one last update:
added an PGM Sw on RA3
to edit the baud rate:
turn off the LCD display, press & hold the PGM sw, turn on the LCD
line 1 will show "Press to Select" , line 2 : "Baud Rate:"
release the sw and press it again to select next value (at this point the new value is save to EEPROM memory)
when the desire value is reach, turn off the LCD and turn it on again at this point the LCD will display the baud rate on line 2
and the display is ready to receive a clear LCD command, and data from the sender.
As for different LCD module eg: 1601,1602,2004 1 line, 2 lines 4 lines etc.. the LCD commands is use to control position of the data on the screen.
as of today the 1601, 1602, 2004 have been tested successfuly.
Code:#CONFIG __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF #ENDCONFIG DEFINE OSC 20 ' Running @ 20MHz PBP 33,217 ANSEL = 0 : ANSELH = 0 ' Set all pins digital TRISA = 001000 : TRISB = 100000 : TRISC = 0 ' 0 = OUT, 1 = IN PORTA = 000001 : PORTB = 0 : PORTC = 0 ' 0 = Low 1 = High OSCCON = $78 ' $78=External Xtal $70 = Internal BaudR var word ' Baud Rate word var En var Portb.4 ' LCD Enable RS var Portb.6 ' LCD Register Set B1 var byte ' Serial IN Byte Flag var bit ' Display Baud Rate on Power-up I VAR BYTE : II VAR BYTE : III VAR BYTE ' use in Set1 read 0, word baudr,ii : pause 2 ' Read Baud Rate from EEPROM if ii < 0 or ii > 7 then baudr = 84 : ii = 3 WRITE 0, Word baudr,ii : pause 2 ' Write to EEPROM endif ArrayA var Byte [65] ' Array index (III) 0 5 10 15 20 25 30 35 40~55 56~65 ARRAYWRITE ArrayA,[" 1200 2400 4800 960014400192002880038400Press to Select:Baud Rate:"] gosub LCDinit ' Initialise LCD IF PORTA.3 = 1 THEN ' PGM Switch GOTO Set1 else flag = 1 gosub set2 pause 500 ENDIF main: serin2 Portb.5,baudr,3,main,[b1] ' Serial IN if b1 < 253 then ' if Characters PORTC = b1 HIGH EN : PAUSEus 1 : LOW EN goto main elseif b1 = 254 then ' if LCD Command low RS serin2 Portb.5,baudr,3,main,[b1] PORTC = b1 ' output the data HIGH EN : PAUSEus 1 : LOW EN high RS ' character mode goto main elseif b1 = 255 then ' if Port Command serin2 Portb.5,baudr,3,main,[b1] if b1 = 0 then TOGGLE PORTA.0 ' Toggle Back Light OFF / ON if b1 = 1 then TOGGLE PORTB.7 ' Toggle PORTB.7 ON / OFF if b1 = 2 then TOGGLE PORTA.2 ' Toggle PORTA.2 ON / OFF goto main ' loop back to top ENDIF LCDINIT: ' Standard LCD Module Initialisation PORTC = 000001 : HIGH EN : PAUSEus 1 : LOW EN : pause 4 ' Clear Display PORTC = 000010 : HIGH EN : PAUSEus 1 : LOW EN : pause 2 ' Return Home PORTC = 111000 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' 8 bit, 2 line, 5x8 Characters PORTC = 000110 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' Entry mode PORTC = 001110 : HIGH EN : PAUSEus 1 : LOW EN : Pause 2 ' 001DCB Display on/off, Cursor on/off, Blink y/n RETURN Set1: ' Baud Rate Selection and EEPROM Save at Power ON with Switch press PAUSE 10 ' "Press to Select:" Low RS : PORTC = 128 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 1 For I = 40 To 55 PORTC = ArrayA[I] High En : PauseUS 1 : Low En PAUSE 2 Next I Set2: PAUSE 10 ' "Baud Rate:" Low RS : PORTC = 192 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 2 For I = 56 To 65 PORTC = ArrayA[I] High En : PauseUS 1 : Low En PAUSE 2 Next I Set3: Low RS : PORTC = 203 : High En : PauseUS 1 : Low En : High RS : Pause 3 ' Line 2 PAUSE 2 ' Index IF II = 0 THEN III = 0 : baudr = 813 ' 1200 IF II = 1 THEN III = 5 : baudr = 396 ' 2400 IF II = 2 THEN III = 10 : baudr = 188 ' 4800 IF II = 3 THEN III = 15 : baudr = 84 ' 9600 IF II = 4 THEN III = 20 : baudr = 49 ' 14400 IF II = 5 THEN III = 25 : baudr = 32 ' 19200 IF II = 6 THEN III = 30 : baudr = 15 ' 28800 IF II = 7 THEN III = 35 : baudr = 6 ' 38400 For I = III To (IIi + 4) PORTC = ArrayA[I] High En : PauseUS 1 : Low En PAUSE 2 Next I if flag = 1 then flag = 0 : return endif WRITE 0, Word baudr,ii : pause 2 ' Write to EEPROM II = II + 1 IF II > 7 THEN II = 0 while PORTA.3 = 1 ' Switch Press wend PAUSE 250 while PORTA.3 = 0 ' Switch Release wend pause 250 GOTO set3


Reply With Quote

Bookmarks