PDA

View Full Version : Problem driving lcd from PIckit2 and 16F887



Davidmarks
- 31st January 2010, 14:59
Recently bought Sandhu book on programming the 16F877A and trying to adapt programs to run on the 16F887 which appears pretty similar but am having problems. Nothing but black squares on the lcd. I have entered and run a simple program to switch on each LED on port D in sequence which works OK. The simpler program (below) is supposed to flash the LED on portD bit 0 which it does but also switches on permanently all the other LEDs on portD.
[CLEAR ; clear memory locations
DEFINE OSC 4; Osc speed

LOOP: ; main loop
HIGHPORTD.0 ; turns LED connected to D0 on
PAUSE500 ; delay 0.5 seconds
LOWPORTD.0 ; turns LED connected to D0 off
PAUSE500 ; delay 0.5 seconds
GOTO LOOP; go back to Loop and repeat operation
END; all programs must end with END
]
The program which is supposed to operate the LCD is as follows:
[CLEAR; Define LCD registers and control bits
DEFINE OSC 4; Osc speed]
DEFINE LCD_DREG PORTD; data register]
DEFINE LCD_RSREG PORTE ; select register ]
DEFINE LCD_RSBIT 0 ; select bit] These Defines
DEFINE LCD_EREG PORTE; enable register] are all explained
DEFINE LCD_EBIT 1 ; enable bit] in the PBP
DEFINE LCD_RWREG PORTE ; read/write register] manual.
DEFINE LCD_RWBIT 2 ; read/write bit]
DEFINE LCD_BITS 8 ; width of data path] Can be 4
DEFINE LCD_LINES 2 ; lines in display]
DEFINE LCD_COMMANDUS 2000 ; delay in micro seconds]
DEFINE LCD_DATAUS 50 ; delay in micro seconds]
;
; Set the port directions. We are setting (must set) all of PORTD and all of PORTE as outputs
; even though PORTE has only 3 lines. The other 5 lines will be ignored by the system.
;
TRISD = %00000000; set all PORTD lines to output
TRISE = %00000000; set all PORTE lines to output
; Set the Analog to Digital control register
ADCON1=%00000111; needed for the 16F877A see notes above and below
; this makes all of ports A and E digital.
LOOP:; The main loop of the program
LCDOUT $FE, 1; clear screen, go to position 1
PAUSE 250; pause 0.25 seconds
LCDOUT "HELLO"; print
LCDOUT $FE, $C0; goto second line, first position
LCDOUT "WORLD"; print
PAUSE 250; pause 0.25 seconds to see the display
GOTO LOOP; repeat
END; all programs must end in END
]
This simply produces a row of black squares !
I'm not very good at this and feel sure I am doing something daft... Any comments/help would be appreciated !

mackrackit
- 31st January 2010, 15:34
The two PICs you mention are very different.
The OSCs and ADC are two big ones that come to mind.

Look at the data sheets for both and you will see.

Then work on blinky. To start use a non analog pin just to finf out if the configs are correct.

Davidmarks
- 31st January 2010, 17:06
Thanks ... I will pour a stiff drink and study the data sheets ! I checked that both chips had an 8 bit D port and a 3 bit E port and connected the lcd to them. I first checked that I could flash LED's on the D port and that seems OK so I presume the configuration is more or less OK. I will have a look at the osc as you suggest !
Thanks again

mackrackit
- 31st January 2010, 17:44
Are you using the 44 pin demo board?

Davidmarks
- 31st January 2010, 18:06
Yes I am ! ...and I just chickened out .. Connected the LCD to the default pins on Ports A and B and it now works. I just have now to modify the programs that use those ports unless I can figure out why it doesnt like ports D and E . Many thanks for your input

mackrackit
- 31st January 2010, 18:28
Port D on that board goes to the LEDs unless the jumper is removed.