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
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