Creating a serial LCD can be very useful for quick debugging; as well as projects requiring LCD support with minimal interface. The circuit presented here may not satisfy all needs, but it should serve as a good starting point for further work.
How does serial LCD interface work?
It is quite simple really. Using a microcontroller with a built-in HW UART, the information form the HW UART is received and passed on to the LCD using 4-bit control. The LCD is a standard 2x16 character based display compatible with a HD44780 controller. The microcontroller is a 16F688 with built-in UART. A baud-select function is included to allow for the selection of two different input baud rates. The following figure shows how the circuit used.
Code Description:
The code for the simple serial LCD was created using Oshonsoft Basic. This language is not as complete or provides as much functionality as others (e.g. CCS C), but it can be readily obtained and used.
The code can be summarized as follows:
On power-up read the baud-select input (select between 9600bps and 1200bps),
Continuously monitor the HW UART and parse any received characters,
a null character is ignored,
a carriage return starts the second line of the LCD,
an escape character clears the LCD,
everything else is passed on to the LCD.
CODE
* PIC16F688 Serial LCD Test Bed *'
'Title: Simple Serial LCD Test Program
'Description: This program uses PIC16F688 to drive a 2x16 LCD from an RS-232 input (9600bps)
'Author: languer (2010)
'Pin Allocation:
'PIN# Main_Fn
'RA0 -> PGD - Programming data
'RA1 -> PGC - Programming clock
'RA2 -> not used
'RA3 -> not used
'RA4 -> LCD EBIT
'RA5 -> LCD RSBIT
'RC0 -> LCD DB4
'RC1 -> LCD DB5
'RC2 -> LCD DB6
'RC3 -> LCD DB7
'RC4 -> BAUD SELECT
'RC5 -> RS232 RX
'Usage Information:
'BAUD Select
'low -> 1200
'high -> 9600
'RS232 Input
'0x00 -> ignore
'0x0D -> LCD line 2, clear line 2
'0x1B -> LCD line 1, clear LCD
'General Device Configuration
Define CONF_WORD = 0x33c4
OSCCON = 0x70 'define internal 8MHz clock
Define CLOCK_FREQUENCY = 8
'HW UART Setup
Define ALLOW_MULTIPLE_HSEROPEN = 1
'LCD Configuration
Define LCD_BITS = 4 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTC
Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 5
Define LCD_EREG = PORTA
Define LCD_EBIT = 4
Define LCD_RWREG = 0 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0 'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 10 'delay used by LCDINIT, default value is 100
'Variable Declarations
Const trisa1 = %11001111
Const trisc1 = %11010000
Symbol lcd_db4 = PORTC.0
Symbol lcd_db5 = PORTC.1
Symbol lcd_db6 = PORTC.2
Symbol lcd_db7 = PORTC.3
Symbol lcd_rs = PORTA.4
Symbol lcd_e = PORTA.5
Symbol baud_select = PORTC.4
Symbol rs232_rx = PORTC.5
Dim _true As Bit
Dim _false As Bit
Dim char As Byte
_true = True
_false = False
'Main Program
main:
Call init()
WaitMs 1000
While _true
Call get_rs232_char()
Call send_lcd_char()
Wend
End
Proc init()
AllDigital 'set all ports to digital
TRISA = trisa1
TRISC = trisc1
WaitMs 1
Lcdinit 1 'initialize LCD module; cursor is blinking
Lcdcmdout LcdClear 'clear LCD display
Lcdout "LCD Display" 'line 1
Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
Lcdout "LR@2010" 'line 2
WaitMs 1
If baud_select = 1 Then
Hseropen 9600
Else
Hseropen 1200
Endif
End Proc
Proc get_rs232_char()
Hserin char
End Proc
Proc send_lcd_char()
Select Case char
Case 0
'do nothing
Case 13
Lcdcmdout LcdLine2Home
Lcdcmdout LcdLine2Clear
Case 27
Lcdcmdout LcdHome
Lcdcmdout LcdClear
Case Else
Lcdout char
EndSelect
End Proc
How does serial LCD interface work?
It is quite simple really. Using a microcontroller with a built-in HW UART, the information form the HW UART is received and passed on to the LCD using 4-bit control. The LCD is a standard 2x16 character based display compatible with a HD44780 controller. The microcontroller is a 16F688 with built-in UART. A baud-select function is included to allow for the selection of two different input baud rates. The following figure shows how the circuit used.
Code Description:
The code for the simple serial LCD was created using Oshonsoft Basic. This language is not as complete or provides as much functionality as others (e.g. CCS C), but it can be readily obtained and used.
The code can be summarized as follows:
On power-up read the baud-select input (select between 9600bps and 1200bps),
Continuously monitor the HW UART and parse any received characters,
a null character is ignored,
a carriage return starts the second line of the LCD,
an escape character clears the LCD,
everything else is passed on to the LCD.
CODE
* PIC16F688 Serial LCD Test Bed *'
'Title: Simple Serial LCD Test Program
'Description: This program uses PIC16F688 to drive a 2x16 LCD from an RS-232 input (9600bps)
'Author: languer (2010)
'Pin Allocation:
'PIN# Main_Fn
'RA0 -> PGD - Programming data
'RA1 -> PGC - Programming clock
'RA2 -> not used
'RA3 -> not used
'RA4 -> LCD EBIT
'RA5 -> LCD RSBIT
'RC0 -> LCD DB4
'RC1 -> LCD DB5
'RC2 -> LCD DB6
'RC3 -> LCD DB7
'RC4 -> BAUD SELECT
'RC5 -> RS232 RX
'Usage Information:
'BAUD Select
'low -> 1200
'high -> 9600
'RS232 Input
'0x00 -> ignore
'0x0D -> LCD line 2, clear line 2
'0x1B -> LCD line 1, clear LCD
'General Device Configuration
Define CONF_WORD = 0x33c4
OSCCON = 0x70 'define internal 8MHz clock
Define CLOCK_FREQUENCY = 8
'HW UART Setup
Define ALLOW_MULTIPLE_HSEROPEN = 1
'LCD Configuration
Define LCD_BITS = 4 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTC
Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 5
Define LCD_EREG = PORTA
Define LCD_EBIT = 4
Define LCD_RWREG = 0 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0 'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 2000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 10 'delay used by LCDINIT, default value is 100
'Variable Declarations
Const trisa1 = %11001111
Const trisc1 = %11010000
Symbol lcd_db4 = PORTC.0
Symbol lcd_db5 = PORTC.1
Symbol lcd_db6 = PORTC.2
Symbol lcd_db7 = PORTC.3
Symbol lcd_rs = PORTA.4
Symbol lcd_e = PORTA.5
Symbol baud_select = PORTC.4
Symbol rs232_rx = PORTC.5
Dim _true As Bit
Dim _false As Bit
Dim char As Byte
_true = True
_false = False
'Main Program
main:
Call init()
WaitMs 1000
While _true
Call get_rs232_char()
Call send_lcd_char()
Wend
End
Proc init()
AllDigital 'set all ports to digital
TRISA = trisa1
TRISC = trisc1
WaitMs 1
Lcdinit 1 'initialize LCD module; cursor is blinking
Lcdcmdout LcdClear 'clear LCD display
Lcdout "LCD Display" 'line 1
Lcdcmdout LcdLine2Home 'set cursor at the beginning of line 2
Lcdout "LR@2010" 'line 2
WaitMs 1
If baud_select = 1 Then
Hseropen 9600
Else
Hseropen 1200
Endif
End Proc
Proc get_rs232_char()
Hserin char
End Proc
Proc send_lcd_char()
Select Case char
Case 0
'do nothing
Case 13
Lcdcmdout LcdLine2Home
Lcdcmdout LcdLine2Clear
Case 27
Lcdcmdout LcdHome
Lcdcmdout LcdClear
Case Else
Lcdout char
EndSelect
End Proc
No comments:
Post a Comment