' Serial LCD Display Gateway for HD44780 LCD Display Controller V1.0
' , used for pollin 2x16 display with neg. contrast voltage in black folding box
' 11.03.2018, version with WaitHSerRx 9600 baud, in use
' compiled with v95.02
'
' ------------
' V+ -| 1 20 |- GND
' PORTA.5 -| 2 19 |- PORTA.0
' PORTA.4 ____ -| 3 18 |- PORTA.1
' PORTA.3(MCLR) -| 4 17 |- PORTA.2
' PORTC.5 -| 5 16 |- PORTC.0 LCD_DB4
' PORTC.4 -| 6 15 |- PORTC.1 LCD_DB5
' PORTC.3 LCD_Enable -| 7 14 |- PORTC.2 LCD_DB6
' PORTC.6 LCD_RS -| 8 13 |- PORTB.4 LCD_DB7
' PORTC.7 LCD_RW -| 9 12 |- PORTB.5 SerInPort
' PORTB.7 -| 10 11 |- PORTB.6
' ------------
#chip 16F690,8
#config OSC=INTRC_OSC_NOCLKOUT, PWRTE = ON
'LCD setting 4 bit mode HD44780
#define LCD_IO 4
#define LCD_RS PORTC.6
#define LCD_RW PORTC.7
#define LCD_Enable PORTC.3
#define LCD_DB4 PORTC.0
#define LCD_DB5 PORTC.1
#define LCD_DB6 PORTC.2
#define LCD_DB7 PORTB.4
' Serial settings and defines
'Baud Rate 9600 @ 8Mhz eq. 207
#define BAUD_RATE_LREG 207
#define BAUD_RATE_HREG 0
#define SerInPort PORTB.5
dir SerInPort In
dim Temp as byte
Temp = 0
'Init
display_ctrl = 0
InitUart
CLS
'------------------- Main loop ------------------------------------------------
Do
'Get a byte from RS232 Rx
Temp = WaitHSerRx
'Received Display CTRL command, ASCII DEZ 254
if (Temp = 254) then
display_ctrl = 1
end if
' Clear Display, received ASCII DEZ 254, 1
if (Temp = 1) and (display_ctrl = 1) then
CLS
display_ctrl = 0
end if
' Diplay Line 1, pos 1, received ASCII DEZ 254, 128
If (Temp = 128) and (display_ctrl = 1) then
Locate 0, 0
display_ctrl = 0
end if
' Diplay Line 2, pos 1, received ASCII DEZ 254, 192
If (Temp = 192) and (display_ctrl = 1) then
Locate 1, 0
display_ctrl = 0
end if
'Received ASCII DEZ between 32 and 127
if (Temp >= 32) and (Temp <= 127) then
LCDWriteChar(Temp)
end if
Loop
'------------------------------- end Main loop --------------------------------
'--------------------------------- subs ---------------------------------------
sub InitUart
;Baud-Rate setup see 12F1572 data sheet, page 176
movlw BAUD_RATE_LREG
movwf SPBRG
movlw BAUD_RATE_HREG
movwf SPBRGH
;16-bit Baud Rate Generator bit
bsf BAUDCTL,BRG16
;High speed asynchronous operation
bsf TXSTA,BRGH
;EUSART asynchronous operation
bcf TXSTA,SYNC
;Set SPEN On
bsf RCSTA,SPEN
;Enables receiver
bsf RCSTA,CREN
end sub 'InitUart
'------------------------------------------------------------------------------
function WaitHSerRx as byte 'Waits until UART has data
clrf WaitHSerRx
;Wait until UART has data
btfss PIR1,RCIF
goto $-1
;If USART has data then
btfss PIR1,RCIF
goto ENDIF_1
;WaitHSerRx = RCREG, return value
movf RCREG,W
movwf WaitHSerRx
;End if
ENDIF_1:
;If overrun error OERR Then
btfss RCSTA,OERR
goto ENDIF_2
;Set CREN Off Disables receiver
;clear if overrun error
bcf RCSTA,CREN
;Set CREN On Enables receiver
bsf RCSTA,CREN
;End if
ENDIF_2:
end function 'WaitHSerRx