Hi
The codes now looks like this
i use hserin and now 9600 is perfect
i also added contrast control (thanks to the forum serach for that).
This code now works quite well LcdSmartie and my Miktotik routers.
Regards Jman
' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortB.7
' E PortB.6
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo PMW via20K potentiometer (or ground)
' DB0-3 No connect
'
'
DEFINE OSC 20 'Set the Xtal frequency
include "Modedefs.bas" 'Include general definitions
'ADCON1 = 7 'Make all pins digital
cmcon = 7 ' Make port Digital
' ** Declare LCDOUT Defines **
DEFINE LCD_LINES 2
Define LCD_DREG PORTA
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 7
Define LCD_EREG PORTB
Define LCD_EBIT 6
' HSERIN defines
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 129 ' 9600 Baud @ 20MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
' ** Define LCD Control Constants **
CTL Con 254 ' Control Byte
Clr Con 1 ' Clear the display
HOME Con 2 'Beginning of the 1st line
LINE1 Con 128 ' Point to beginning of line 1
LINE2 Con 192 ' Point to beginning of line 2
LINE3 Con 148 ' Point to beginning of line 3
LINE4 Con 212 ' Point to beginning of line 4
CGram Con 64 ' Point to Cgram within LCD
DDram Con 128 ' Pont to DDRAM
ShiftL Con 24 ' Shift display left
ShiftR Con 28 ' Shift display right
Blank Con 8 ' Blank display (don't clear memory)
ULon Con 14 ' Underline ON
BlinkCur Con 15 ' Blinking Cursor
CurLeft Con 16 ' Move cursor left 1 position
CurRight Con 20 ' Move cursor right 1 position
BlockCur Con 13 ' Block cursor
Space Con 32 'ASCII code for a space
Null CON 0
Restore CON 12
' ** Declare Variables **
InByte1 Var byte ' The byte received
InByte2 var byte ' Second byte recvd
InBytes VAR BYTE[4] 'For multi commands
contrast var byte 'General variables
ch2 var byte
ch3 var byte
tmp var byte 'Temp var
CGChar var byte[8] 'CGRam custom character
CGAddr var byte 'CGRam address
cnt var byte 'General use counter
' Init LCD
Lcdout $fe, 1 ' Init LCD
pause 100 ' Wait for LCD to Initialize
'contrast set default
'HPWM 1,20,1300
'==== MAIN SECTION =======
gosub Init
InByte1 = " "
MainLoop:
HSerin [InByte1] ' Receive the serial byte
if InByte1 <= 31 then goto LCDfonz
if InByte1 >= 128 then goto Custom
Lcdout InByte1 'Dispaly the Char
Goto MainLoop
LCDfonz:
if InByte1 = 0 then MainLoop
select case InByte1
case 1
lcdout CTL, Line1
'LOW VDD 'lcdout ctl, 1
'pause 30
case 2
Lcdout CTL, blank
case 3
Lcdout CTL, Restore
case 4
Lcdout CTL, 12
Case 5
lcdout ctl, ulon
case 6
lcdout ctl, blockcur
case 7
Lcdout CTL, blockcur
case 8
Lcdout CTL, curleft
case 9
hSerin [InBytes(0)] 'command Value
case 10
' Null do nothing
Case 11
' Null do nothing
case 12
lcdout CTL, $80
lcdout " "
lcdout CTL, $C0
lcdout " "
case 13
' Null do nothing
case 14
hSerin [InBytes(0)] 'Brightness
'LOW VDD 'high vdd
case 15
hSerin [InBytes(0)] 'Contrast
contrast = inbytes(0) * 2
HPWM 1,contrast,1300
case 16
' Null do nothing
Case 17
HSerin [InBytes(0), InBytes(1)]
if InBytes(1) = 0 Then
Lcdout CTL, ($80 + InBytes(0))
else
lcdout CTL, ($C0 + Inbytes(0))
endif
case 18
' Null do nothing
case 19
' Null do nothing
Case 20
' Null do nothing
case 21
' Null do nothing
case 22
' Null do nothing
Case 23
' Null do nothing
case 24
' Null do nothing
case 25
hserin [CGAddr, CGChar(0), CGChar(1),_
CGChar(2), CGChar(3), CGChar(4), CGChar(5),_
CGChar(6), CGChar(7)]
Select case CGAddr
Case 0
LCDOUT CTL,64,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
Case 1
LCDOUT CTL,72,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
Case 2
LCDOUT CTL,80,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
Case 3
LCDOUT CTL,88,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
Case 4
LCDOUT CTL,96,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CGC har(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
Case 5
LCDOUT CTL,104,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CG Char(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
Case 6
LCDOUT CTL,112,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CG Char(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
Case 7
LCDOUT CTL,120,CGChar(0),CGChar(1),CGChar(2),CGChar(3),CG Char(4),CGChar(5),CGChar(6),CGChar(7) ' Write Custom Char
End select
Case 26
' Null do nothing
case 27
' Null do nothing
case else
'Lcdout CTL,InByte1
end select
goto Mainloop
Custom:
if InByte1 > 135 Then ' if not a custom Char then return
'Lcdout InByte1
Goto Mainloop
endif
select case InByte1
case 128
lcdout 0 ' Dispaly Custom Char 0
case 129
lcdout 1 ' Dispaly Custom Char 1
case 130
lcdout 2 ' Dispaly Custom Char 2
case 131
lcdout 3 ' Dispaly Custom Char 3
case 132
lcdout 4 ' Dispaly Custom Char 4
Case 133
lcdout 5 ' Dispaly Custom Char 5
case 134
lcdout 6 ' Dispaly Custom Char 6
case 135
Lcdout 7 ' Dispaly Custom Char 7
end Select
goto MainLoop
Init:
'Load Custom CGRam characters
LCDOut CTL,64,$00,$04,$02,$1F,$02,$04,$00,$00,CTL,128
LCDOut CTL,72,$00,$04,$08,$1F,$08,$04,$00,$00,CTL,128
LCDOut CTL,80,$00,$04,$0E,$15,$04,$04,$00,$00,CTL,128
LCDOut CTL,88,$00,$00,$04,$04,$15,$0E,$04,$00,CTL,128
LCDOut CTL,96,$1F,$11,$11,$11,$11,$11,$11,$1F,CTL,128
LCDOut CTL,104,$04,$0E,$1F,$00,$00,$1F,$0E,$04,CTL,128
LCDOut CTL,112,$02,$06,$0E,$1E,$0E,$06,$02,$00,CTL,128
LCDOut CTL,120,$08,$0C,$0E,$0F,$0E,$0C,$08,$00,CTL,128
logo:
Lcdout CTL,LINE1,"Crystal EMU Ver .99"
Lcdout CTL,LINE2,"Jman says 9600 baud"
Lcdout CTL,HOME
Return
Bookmarks