' LCDSimple.bas ' By C.D.Odom on 3.25.06 ' chris_odom@georgeschool.org ' www.basicxandrobotics.com ' A simple application to print text and numbers to ' NetMedia's 2x16 LCD screen. For a more advanced app, ' see LCDAdvanced.bas. Option Explicit ' ////// Main /////////// Public Sub Main() Dim i as Integer ' Pin Constants Const LCDOutputPin as Byte = 20 ' RAMB pin 15 ' LCD Control Constants ' The following are ASCII codes sent to the LCD. These are NOT pin numbers! Const Clear_LCD as Byte = 12 Const Set_Cursor as Byte = 17 Const Contrast as Byte = 19 Const BackLight as Byte = 20 ' Power Backlight with any RAMB power pin ' Open the COM 3 Port Dim Com3In(1 to 15) as Byte ' Create an input data array for the LCD input queue Dim Com3Out(1 to 40) as Byte ' Create an output data array for the LCD output queue Call OpenQueue(Com3In, 15) ' Create an input queue Call OpenQueue(Com3Out, 40) ' Create an output queue Call DefineCom3(0, LCDOutputPin, bx1000_1000) ' Define Com3 parameters Call OpenCom(3, 9600, Com3In, Com3Out) ' Inititalize Com3 port Call Delay(0.7) ' Allow the LCD time to power up ' Set the LCD's Contrast and Backlight Levels Call PutQueueStr(Com3Out, Chr(Contrast) & Chr(0)) ' 0 = High, 255 = Low Call PutQueueStr(Com3Out, Chr(BackLight) & Chr(255)) ' 0 = Dim, 255 = Bright ' Clear the LCD screen, and print "Hello World" to the LCD. Call PutQueueStr(Com3Out, Chr(Clear_LCD)) Call PutQueueStr(Com3Out, "Hello World!") Call Delay(3.0) ' Delay to read message ' Clear the LCD screen and print a second message. Call PutQueueStr(Com3Out, Chr(Clear_LCD)) Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(0) & Chr(3)) ' Move cursor to Row 0, Col 3 Call PutQueueStr(Com3Out, "It is good") Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(1) & Chr(2)) ' Move cursor to Row 1, Col 2 Call PutQueueStr(Com3Out, "to be alive!") Call Delay(3.0) ' Delay to read message ' Clear the LCD screen and print a third message. Call PutQueueStr(Com3Out, Chr(Clear_LCD)) Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(0) & Chr(0)) Call PutQueueStr(Com3Out, "Testing...") For i = 0 to 4 Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(1) & Chr(i*3)) Call PutQueueStr(Com3Out, CStr(i+1) & ",") Call Delay(1.0) Next ' Say Good-bye. Call PutQueueStr(Com3Out, Chr(Clear_LCD)) Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(0) & Chr(5)) Call PutQueueStr(Com3Out, "The") Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(1) & Chr(8)) Call PutQueueStr(Com3Out, "End") End Sub