' This Program reads the BX-24 ADC pins and displays the ' values on a connected NetMedia serial 2x16 LCD display. ' Dev board buttons 0 & 1 select the ADC pin#, buttons ' 2 & 3 toggle the LCD backlight. ' Define Com3 buffers Dim Com3In(1 to 15) As Byte Dim Com3Out(1 to 40) As Byte ' Define the variable name for our ADC reading Dim Voltage As Single ' Define the display variable that holds the ASCII (String) Dim ASCII_Voltage As String * 4 ' Define variable to hold ADC pin number Dim ADC_Pin As Byte ' Define variable for buttons Dim Button(0 to 3) As Byte ' Define RAM space for button task to run in Dim Button_Stack(1 to 50) As Byte ' Define the LCD control constants we will use Const BackLite As Byte = 20 Const Clear_LCD As Byte = 12 Const Set_Cursor As Byte = 17 ' Variable to determine when to clear LCD screen and redraw Dim Clean_Display As Byte '************************************************************ Sub Main() Call Sleep(256) ' Wait 1/2 second after power up for LCD to stabilize Call OpenQueue(Com3In, 15) ' Open Com3 Buffers Call OpenQueue(Com3Out, 40) ' Set Com3 to Inverted Logic, 8 Data Bits, No Parity, Pin5 TX, 0 = NO RX pin Call DefineCom3(0, 5, bx1000_1000) Call OpenCom(3, 9600, Com3In, Com3Out) ' Open Com3 Clean_Display = 0 ADC_Pin = 13 ' Set the ADC channel to 13 CallTask "Read_Buttons", Button_Stack Do Call GetADC(ADC_Pin, Voltage) ' Read the selected ADC pin and store value in "Voltage" Voltage = Voltage * 5.0 ' Multiply the 0-1v ADC value by 5 to scale it to 0-5v ASCII_Voltage = CStr(Voltage) ' Convert ADC value to an ASCII string Call Display_Voltage ' Call "Display_Voltage" sub If (Button(0) = 1) And (ADC_Pin = 13) Then Button(0) = 0 ADC_Pin = 19 ElseIf Button(0) = 1 Then Button(0) = 0 ADC_Pin = ADC_Pin - 1 End If If (Button(1) = 1) And (ADC_Pin = 19) Then Button(1) = 0 ADC_Pin = 13 ElseIf Button(1) = 1 Then Button(1) = 0 ADC_Pin = ADC_Pin + 1 End If Call Sleep(100) ' Wait a little before doing it again If (Button(2) = 1) Then Call PutQueueStr(Com3Out, Chr(BackLite) & Chr(255)) Call PutPin(26,0) Button(2) = 0 ElseIf Button(3) = 1 Then Call PutQueueStr(Com3Out, Chr(BackLite) & Chr(0)) Call PutPin(26,1) Button(3) = 0 End If Loop End Sub '************************************************************ Sub Display_Voltage() If Clean_Display > 5 Then Clean_Display = 0 Call PutQueueStr(Com3Out, Chr(Clear_LCD)) End If Clean_Display = Clean_Display + 1 ' Move LCD cursor to Row 0 column 0 Call PutQueueStr(Com3Out, Chr(Set_cursor) & Chr(0) & Chr(0)) ' Print "ADC13 = " and the first 4 characters of our ASCII voltage value Call PutQueueStr(Com3Out, "Pin" & CStr(ADC_Pin) & "= " & Mid(ASCII_Voltage, 1, 4) & "Vdc") End Sub ' Return '******************************************************************** Sub Read_Buttons() Dim Button_Pins As Byte Call PutPin(6, 3) ' Turn on internal pull-up resistors for these pins Call PutPin(7, 3) Call PutPin(8, 3) Call PutPin(9, 3) Do For Button_Pins = 6 to 9 If GetPin(Button_Pins) = 0 Then Do While GetPin(Button_Pins) = 0 Loop Button(Button_Pins - 6) = 1 ' Tell main task this button was pressed End If Next Call Sleep(50) Loop End Sub