PDA

View Full Version : Keypad_Lcd problem



joseph Degorio
- 23rd November 2007, 06:34
Hi everyone,
Kindly check the codes below, I'm trying to display numeric value to the LCD 1 to 12.
My problem is that initially it displays the digit 4 and I noticed that switches 1-3(row 1) dont change any value (displays digit 4).
But switches 4 to 12 is working fine. I'm using PIc16F876A, my keypad is 3x4 and connected to B0-B6 with external resistors 270 ohms at B0-B3.
My second question is how do you convert this code 'LCDOUT $FE, $C0, "ROW=", DEC ROW, " COL=", DEC COLUMN, " SW=", DEC SWITCH, " " and
LCDOUT $FE, $80, "ROW=",BIN4 (BUFFER & $0F)," COL=", BIN4 BUFFER >>4' to Serout command.

The Code:
;define the variables
BUFFER VAR BYTE
ALPHA VAR BYTE ;counter for rows
COLUMN VAR BYTE
ROW VAR BYTE
SWITCH VAR BYTE

;SET UP PORT B PULL UPS
OPTION_REG.7 = 0 ;Enable PORTB pullups to make B4-B7 high
TRISB = %11110000 ;Make B4-B7 inputs, B0-B3 outputs,
TRISC =%00000000
PAUSE 200 ;Wait for LCD to start
;Set up the initial LCD readings
Serout 7,6, [$FE, 1] ;Clear the LCD
PORTB =%00001110 ;Set line B0 low so we can read row 1 only
LOOP:
PORTB =%00001110 ;Set line B0 low so we can read row 1 only
FOR ALPHA = 1 TO 4 ;Need to look at 4 rows
IF (PORTB & $70)<>$70 THEN
;As soon as one of the bits in B4 to B7 changes we
;immediately
;have to store the value of PORTB in a safe place.
BUFFER =PORTB
GOSUB SHOWKEYPRESS
Serout 7,6, [$FE, 1] ;Clear the LCD

ELSE
ENDIF
PORTB= PORTB <<1 ;move bits left one place for next line low
PORTB= PORTB + 1 ;put 1 back in LSBit, the right bit
NEXT ALPHA
GOTO LOOP

SHOWKEYPRESS:
BUFFER = BUFFER ^ %11111111 ;flips all the bits in the buffer
;print the first line
''LCDOUT $FE, $80, "ROW=",BIN4 (BUFFER & $0F)," COL=", BIN4 BUFFER >>4

COLUMN=(NCD BUFFER) -4
ROW=NCD (BUFFER & $0F)
SWITCH=((ROW-1) * 3) +COLUMN
;print the second line
''LCDOUT $FE, $C0, "ROW=", DEC ROW, " COL=", DEC COLUMN, " SW=", DEC SWITCH, " "
Serout PortC.1,6,[$FE,1]
serout PortC.1, 6, [#SWITCH]
pause 500
RETURN
END


Thanks in advance,
joe

mister_e
- 23rd November 2007, 16:06
this could be easier to debug and implement
http://www.picbasic.co.uk/forum/showthread.php?t=3250

Download the latest version
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1742&d=1181850086

joseph Degorio
- 24th November 2007, 11:49
Hi Steve,
Thanks for the reply, I know it may sound silly but where can I get MPASM to compile the keypad.bas? Sorry, I'm really new to this found hobby.


Thanks again,
joe

mister_e
- 24th November 2007, 18:01
No problem my friend, you're in the learning process.

To have MPASM (and some extra tools) just Download MPLAB IDE from Microchip Website.
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002

If you're using MicroCodeStudio, you need to specify you want to use MPASM as assembler in View>Compile and Program Option>>Assembler.

If you don't want to download MPLAB, you can use Darrel's version made for PM, same thread, post #29
http://www.picbasic.co.uk/forum/showpost.php?p=32663&postcount=29

joseph Degorio
- 25th November 2007, 06:08
Hi Steve,
Thanks for the guide, everything now is running fine...


Regards,
joe

mister_e
- 25th November 2007, 09:39
http://www.mister-e.org/Pics/woohoo