-
18F4550 and keypad
i working with 18F4550 with 4mhz resonator
usb work 100%
keypad don't work
can i help ?
Code:
INCLUDE "modedefs.bas"
INCLUDE "KeyPad.bas"
DEFINE OSC 48
DEFINE KEYPAD_ROW 6 ' 4 ROW keypad
DEFINE KEYPAD_ROW_PORT PORTB ' ROW port
DEFINE KEYPAD_ROW_BIT 2 ' ROW0
DEFINE KEYPAD_COL 3 ' 4 COL keypad
DEFINE KEYPAD_COL_PORT PORTD ' COL port
DEFINE KEYPAD_COL_BIT 5 ' COL0
DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec
DEFINE KEYPAD_AUTOREPEAT 0 ' use auto-repeat feature
Led Var PORTA.0
RF_Entrada VAR PORTA.1
Contador Var Byte
Dados var Byte[10]
Recebeu var byte[4]
Acao var byte
Botao VAR Byte
Linha VAR BYTE
Coluna VAR BYTE
'-------------------------------------------------------------------------------
Configura:
ADCON0 = 0 ' Turn off A/D
ADCON1 = 7 ' Set PORTA to digital
CMCON = 7 ' Comparators off
high LED
PAUSE 100
USBInit
PAUSE 5000
Low LED
'-------------------------------------------------------------------------------
Inicio:
USBService
contador = 1
USBIn 3, Dados, contador, Inicio
Toggle LED
iF Dados[0]="B" tHEN
Contador = 5
Dados[0] = "B"
Dados[1] = "O"
Dados[2] = "T"
Dados[3] = "Ã"
Dados[4] = "O"
goSUB Usb_Saida
GOTO Ler_Teclado
endif
GOTO Inicio
'-------------------------------------------------------------------------------
Usb_Saida:
USBService
USBOut 3, Dados, contador, Usb_Saida
rETURN
'-------------------------------------------------------------------------------
Ler_Teclado:
@ READKEYPAD _Botao
Contador = 3
Dados[0] = 96+Botao
Dados[1] = 13
Dados[2] = 10
goSUB Usb_Saida
goto Ler_Teclado
END
-
It never makes it to the keypad routine. Unless you send something from the PC.
Then it only checks the keypad once.
Code:
Inicio: <--------------------------------
USBService |
|
contador = 1 |
USBIn 3, Dados, contador, Inicio ---
-
i send 'B" from pc, print "BOTAO" and start keypad
KEYPAD IN 16f628 IS OK...but in 18F4550 portb and portd not work
Inicio:
USBService
contador = 1 'working
USBIn 3, Dados, contador, Inicio 'working
Toggle LED
iF Dados[0]="B" tHEN 'working
Contador = 5
Dados[0] = "B"
Dados[1] = "O"
Dados[2] = "T"
Dados[3] = "Ã"
Dados[4] = "O"
goSUB Usb_Saida
GOTO Ler_Teclado
endif
GOTO Inicio
'-------------------------------------------------------------------------------
Usb_Saida: 'working
USBService
USBOut 3, Dados, contador, Usb_Saida
rETURN
'-------------------------------------------------------------------------------
Ler_Teclado:
Contador = 5 'working
Dados[0] = "B"
Dados[1] = "O"
Dados[2] = "T"
Dados[3] = "Ã"
Dados[4] = "O"
goSUB Usb_Saida
@ READKEYPAD _Botao ' not working
Contador = 3
Dados[0] = 96+Botao
Dados[1] = 13
Dados[2] = 10
goSUB Usb_Saida
goto Ler_Teclado
END
-
It never makes it to the keypad routine. Unless you send something from the PC.
Then it only checks the keypad once.
Code:
Inicio: <--------------------------------
| USBService |
| |
| contador = 1 |
----> USBIn 3, Dados, contador, Inicio ---
...
...
@ READKEYPAD _Botao ' not working