Oilmex board LCD for Comparason
I recently got my PIC-MT-USB up and running, with help from this forum. I got the switches to work and the lights to blink. The LCD was the next headache. I was hoping that your thread may give me some ideas. But I managed to get it to work with the help from an article: http://www.epemag.wimborne.co.uk/lcd1.pdf
I am an old TTL guy, so the wiring diagram made lots of sense to me, and finally got it working. My code is attached with comments. It may offer some ideas. Hope it helps.
Comments about my code are welcome from the community. I am a nophyte.
'************************************************* ***************
'* Name : OILMEX TEST *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 8/24/2009 *
'* Version : 1.0 *
'* Notes : FOR THIS TO WORK ON THE OLMEX BOARD *
'* : the INC file had to be changed to *
'* : change the config to HS from XT *
'* : *
'************************************************* ***************
'************************************************* **************
'* This block of code sets up switches to drive LEDs
LED1 VAR PORTB.2
LED2 VAR PORTB.1
SWITCH1 VAR PORTB.4
SWITCH2 VAR PORTB.5
TRISB = %11111001 'sets bit 1, 2 to output. all else to input
LOW LED1 'inatilized leds
LOW LED2 'LED initalizain probabbly not needed
'********** END PUSH BUTTON / LED CODE*********************
'************* LCD DRIVER TEST CODE **********************
'****** PINS BASED ON SCHEMATIC ***************************
'* LCD Connections
'* _RS PORTD0 -DATA when LOW, Commands when HIGH
'* .R/W PORTD1 - LOW to WRITE Date, HIGH to READ data from LCD
'* E PORTD2 - Data transferred on Transition High to Low
'* Light PORTD3
'* DB4 PORTD4
'* DB5 PORTD5
'* DB6 PORTD6
'* DB7 PORTD7
'**************
define LCD_DREG PORTD 'Display connected to PORTD
DEFINE LCD_DBIT 4 'Data Starting Bit (0, or 4)
'When set to 0, Backlight Display Blinks, no Data
DEFINE LCD_RSREG PORTD 'Reset register is on PortD
DEFINE LCD_RSBIT 0 'Reset Bit is D0
Define LCD_EREG PORTD 'Enable on PORTD
DEFINE LCD_EBIT 2 'enable bit D2
'*********** These LCD DEFINES not needed (presumably) *******
'DEFINE RW_REG PORTD
'DEFINE LCD_RWBIT 1
'DEFINE LCD_BITS 4
DEFINE OSC 20 'The display was jumpp, This took care of it
'DEFINE LCD_COMMANDUS 2000
'DEFINE LCD_DATAUS 50 'data delay in µs'
'Define LOIADER_USED 1
'define NO_CLRWDT 1
'*************** End of UNUSED LCD DEFINES ******************
TRISD = %00001111 'Set D4-8 as output. D0-4 as Input
low PORTD.1 'Set NOT R/W to LOW (Write Data TO LCD)
High PORTD.3 'Turn on Back LIght (Tested - Works)
Pause 500 ' Wait for LCD to startup
mainloop:
Lcdout $fe, 1 ' Clear LCD screen
PAUSE 500
Lcdout "Hello" ' Display Hello
Pause 500 ' Wait .5 second
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World"
Pause 500 ' Wait .5 second
'************* PUSHBUTTON / LET TEST RUTINE *************
IF SWITCH1 = 0 Then 'NOTE Button Goes to 0 When pressed
HIGH LED1
else
low LED1
ENDif
IF SWITCH2 = 0 then
HIGH LED2
else
low LED2
endif
'***************** End Of Pushbutton Routine **********
Goto mainloop ' Do it forever