PDA

View Full Version : LCD Display



lambert
- 16th January 2010, 21:29
Hi guys,

I'm new to pic-chip programming and am having trouble getting an MCC162b3 lcd display to work. I am using a pic16f873a. Below is the code I am using, which is basically the picBasic sample program, but I changed LCD_DREG to PORTC because I need the ADCs on portA.

I saw in another forum for another pic-chip to set ANSEL=0. I'm not sure what ANSEL is, but it causes a compilation error for me.

Thanks in advance.
L.


DEFINE LCD_DREG PORTC ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTA ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 3 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us

define OSC 20
TRISC = %00000000
TRISA = %000011 'A.0 and A.1 for ADC input
TRISB = %00000000


'
' LCD is connected as follows:
' LCD PIC
' DB4 PortC.0
' DB5 PortC.1
' DB6 PortC.2
' DB7 PortC.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect

Pause 5000 ' Wait for LCD to startup

loopy:
Lcdout $FE, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 2000 ' Wait .5 second

Lcdout $FE, 1 ' Clear LCD screen
Lcdout "World"
Pause 2000 ' Wait .5 second

Goto loopy ' Do it forever

Archangel
- 16th January 2010, 22:18
Hi Lambert,
Welcome to the forum!
In MPASM SUITE, in your MICROCHIP directory, exists files named for each PIC supported, in this case named P16F873A.inc .
Open it in MCS and examine it, there you will find every register available. No ANSEL there, that's why it errors.
look at the list below for suggested changes.

TRISA = %00000011 'Set all bits even if port has access to only some
' Disable comparators !
' Disable analog functions on Ports A, C, capture compare , ADCON. . .