PDA

View Full Version : LCD R/S works on Port A but not Port B



TDonBass
- 10th February 2009, 04:49
Have been trying on both a 16F627A and now a 16F84A'
The first code below works, but when I switch the R/S pin from PortA.2 to Port B.2, I get a blank LCD screen. I can't see what I'm doing wrong. Can anyone help?

LCD Display
' ================
'
'
' The connection between the LCD display and the microcontroller is as follows:
'
' Display Microcontroller pin
' DB4 RB4
' DB5 RB5
' DB6 RB6
' DB7 RB7
' E RB3
' RS RA2
'
' Compiler: PicBasic Pro
'
' Modifications
' ==========
'
'************************************************* *******************************************

' DEFINITIONS
define LCD_DREG PORTB
define LCD_DBIT 4
define RSREG PORTA
define LCD_RSBIT 2
define LCD_EREG PORTB
define LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

TRISA = 0 ' Register A pins are outputs
TRISB = 0 ' Register B pins are outputs


PAUSE 500 ' Wait 0.5sec for LCD to initialize

OPTION_REG = $80

LCDOUT $FE, 1 ' Clear LCD
LCDOUT $FE, $C0
LCDOUt "ClockWorks"
'

END




The following does not work:
' LCD Display
' ================
'
'
' The connection between the LCD display and the microcontroller is as follows:
'
' Display Microcontroller pin
' DB4 RB4
' DB5 RB5
' DB6 RB6
' DB7 RB7
' E RB3
' RS RB2
'
' Compiler: PicBasic Pro
'
' Modifications
' ==========
'
'************************************************* *******************************************

' DEFINITIONS
define LCD_DREG PORTB
define LCD_DBIT 4
define RSREG PORTB
define LCD_RSBIT 2
define LCD_EREG PORTB
define LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

TRISA = 0 ' Register A pins are outputs
TRISB = 0 ' Register B pins are outputs


PAUSE 500 ' Wait 0.5sec for LCD to initialize

OPTION_REG = $80

LCDOUT $FE, 1 ' Clear LCD
LCDOUT $FE, $C0
LCDOUt "ClockNot"


END

Archangel
- 10th February 2009, 05:32
Try adding this to your code. FLAGS=0 and for the 627A add cmcon=7 to disable the comparators on portA. It is just me but I would initialize the Ports before the Tris with PortB = 0 and PortA = 0 and lose this: OPTION_REG = $80. OPTION_REG = $80 sets WPU when portB is set as input, since you are using it as outputs, it is not needed.

Melanie
- 10th February 2009, 08:38
You've screwed up your defines...

Instead of...

Define LCD_RSREG PORTB

you've written...

define RSREG PORTB

PICBasic doesn't error on define typo's, and you must have chosen the default setting in the option that works.

Archangel
- 10th February 2009, 09:24
You've screwed up your defines...

Instead of...

Define LCD_RSREG PORTB

you've written...

define RSREG PORTB

PICBasic doesn't error on define typo's, and you must have chosen the default setting in the option that works.

SHARP EYES ! Good catch.

TDonBass
- 10th February 2009, 12:41
Thanks Melanie and Joe,

And I had even read Melanies post about not screwing up the DEFINE statements!
What happened was that I had copied some defines from the pbppic14.lib file and then modified them for PBP, but I missed changing them to upper case.

This is a good example of why you should post your code when you ask a question. No telling how long it would have taken me to find that.

thanks again