PDA

View Full Version : Unable to use the number 8 in DATA statement



dbachman
- 6th December 2008, 23:34
Whenever I run this in my 18F1320, I can read the data statement just fine but in place of 8's there are 3's. If I put in any other number it seems to work fine. I don't get it.

Thanks, Don



' Define LCD pins
Define LCD_DREG PORTA
Define LCD_DBIT 0
Define LCD_RSREG PORTA
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 3

OSCCON = $60 ' Set up internal oscillator
x var byte
dtmf var byte
data @1,1,3,0,8,8,6,0,7,3,7,5
TRISB = %11010000
TRISA = %01100000
Pause 500 ' Wait 500mS for LCD to startup
LCDOut $fe, 1 ' Clear LCD screen
Pause 1 ' Wait 1 millisecond
LCDOut $fe,$80 ' Move cursor to the beginning of the first line
LCDOut "DTMF Demo using" ' Display
LCDOut $fe,$c0 ' Move cursor to the beginning of the second line
LCDOut "PIC18F1320" 'Display PIC Lecture
pause 1000
LCDOut $fe, 1 ' Clear LCD screen
LCDOut $fe,$80 ' Move cursor to the beginning of the first line
loop:

for x = 1 to 11
read x, dtmf
portb = dtmf
low portb.5
pause 100
high portb.5
pause 100
LCDOut DEC1(dtmf)
next x
pause 200
LCDOut $fe, 1 ' Clear LCD screen
pause 100
goto loop ' Do it forever

End

Darrel Taylor
- 7th December 2008, 00:31
A couple things...

You're writing the dtmf value to all 8 bit's of PORTB. But PORTB.3 is the LCD's Enable Bit.
So when the data is 8, PORTB.3 gets set High, interfering with the enable line.

You should also turn off the Analog functions since the LCD is on PORTA.
ADCON1 = $7F
<br>

dbachman
- 7th December 2008, 01:04
Thanks Darrel,

Kind of makes sense now that you point out the obvious. Every little bit helps in the learning process though.

Don

dbachman
- 7th December 2008, 01:05
Hi Darrel,

How do I just write to the 4 bits I am using?

Archangel
- 7th December 2008, 01:52
Hi Darrel,

How do I just write to the 4 bits I am using?
Hi Don,
PortB.3 is in the lower 4 bits you are using, you might think good thoughts of moving the E bit to b.4 and then you can address the lower bits as individuals or read the entire port and mask out the upper bits after reading them.

dbachman
- 7th December 2008, 03:09
Hi Joe,

I did do something like that. I moved it to Porta bit 7. Just sittin there anyway. How do you read the entire port - better yet, how would you masked out the bits. I am still in a steep learning curve so please bear with me. Is it like this?

DTMF = DTMF & %00001111 ' isolate lower 4 bits

Thanks, Don

Archangel
- 7th December 2008, 06:34
look at this: http://en.wikipedia.org/wiki/Mask_(computing)
and this: http://www.picbasic.co.uk/forum/showthread.php?t=7529&highlight=masking+bits
PORTB & $0F