PDA

View Full Version : Can PortA of PIC16F877 be used for LCD, by using DT's ALLDIGITAL.pbp ?



Larryd
- 24th July 2013, 16:26
PIC16F877
PBP Ver 2.6C

I can't get port A to work with LCD.
Port C and D work fine.

I'm sure I missed somthing just can't seem to find it.

Thanks

Ld

Code Trying:

INCLUDE "ALLDIGITAL.pbp" 'Darrel Taylor's Include
' DEFINE SHOWDIGITAL 1
'-------------------------------------------------------
DEFINE OSC 10 ' We're using a 10MHz oscillator
DEFINE HSER_RCSTA 90h ' enable serial port,
define HSER_TXSTA 24h ' enable transmit,
define HSER_BAUD 9600 ' set baudrate to 9600
DEFINE HSER_CLOERR 1 ' automatic clear overrun error
'Define LCD
DEFINE LCD_DREG PORTA 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTA 'LCD register select port
DEFINE LCD_RSBIT 5 'LCD register select bit
DEFINE LCD_EREG PORTA 'LCD enable port
DEFINE LCD_EBIT 4 'LCD enable bit
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
DEFINE LCD_COMMANDUS 2000 '2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us

TempB VAR BYTE
BUSdata VAR BYTE


'================================================= =================


PAUSE 3500

Main:
GOSUB LCD_INIT ' Do manual LCD Initialization
Lloop:
Pause 1000 ' Wait .5 second
Lcdout $FE, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 1000 ' Wait .5 second
Lcdout $FE, $C0
Lcdout "World"
Pause 1000 ' Wait .5 second
Goto Lloop ' Do it forever

;---- Manual LCD Initialization -------------------------------------
LCD_INIT:
@ MOVE?CT 0, LCD_RSREG,LCD_RSBIT ; Start with RS LOW
@ MOVE?CT 0, LCD_RSREG+80h,LCD_RSBIT ; RS is OUTPUT
@ MOVE?CT 0, LCD_EREG,LCD_EBIT ; Start with Enable LOW
@ MOVE?CT 0, LCD_EREG+80h,LCD_EBIT ; Enable is OUTPUT
@ MOVE?CT 0, LCD_DREG+80h,LCD_DBIT ; Data Bus is OUTPUT
@ MOVE?CT 0, LCD_DREG+80h,LCD_DBIT +1
@ MOVE?CT 0, LCD_DREG+80h,LCD_DBIT +2
@ MOVE?CT 0, LCD_DREG+80h,LCD_DBIT +3
PAUSE 1000
BUSdata = 3
GOSUB Send4Bit : pause 8 ; FunctionSet 4 times
GOSUB Send4Bit : pauseUS 200
GOSUB Send4Bit : pauseUS 200
GOSUB Send4Bit : pauseUS 200
BUSdata = 2 : GOSUB Send4Bit ; 4-bit mode
BUSdata = 2 : GOSUB Send4Bit ; 2-line, 5x7
BUSdata = 8 : GOSUB Send4Bit
BUSdata = 0 : GOSUB Send4Bit ; Display OFF
BUSdata = 8 : GOSUB Send4Bit
BUSdata = 0 : GOSUB Send4Bit ; Display Clear
BUSdata = 1 : GOSUB Send4Bit
PAUSE 3
BUSdata = 0 : GOSUB Send4Bit ; Entry Mode Set
BUSdata = 6 : GOSUB Send4Bit
PAUSE 3
BUSdata = 0 : GOSUB Send4Bit ; Display ON
BUSdata = $C : GOSUB Send4Bit
@ MOVE?CT 1, LCDINITFLAG ; Tell PBP LCD is already Initialized
return

Send4Bit:
@ MOVE?CT 1, LCD_EREG,LCD_EBIT ; Enable LCD
@ MOVE?BB LCD_DREG, _TempB ; Put Data on the Bus R-M-W
@ if LCD_DBIT == 0 ; Bus starts at 0
TEMPB = (TEMPB & $F0) | BUSdata
@ else ; Bus starts at 4
TEMPB = (TEMPB & $0F) | (BUSdata << 4)
@ endif
@ MOVE?BB _TempB, LCD_DREG
PAUSEUS 25 ; Keep enabled extra long
@ MOVE?CT 0, LCD_EREG,LCD_EBIT ; Disable LCD
Pauseus 50
return
;---------- END LCD_INIT --------------------------------------------

Darrel Taylor
- 24th July 2013, 17:59
RA4 is an open drain output.
You'll need a pull-up resistor on that pin.

Larryd
- 24th July 2013, 18:34
Thank You Darrel !!,

I put a 10K pullup,
Works Great now.

Thanks
Ld