I'm trying to get an Adafruit 12 key capacitive touchpad (https://www.adafruit.com/product/1982) going. I don't think I'm too far off, but the multiple registers, Arduino-centric tutorial, and my own lack of experience leave me struggling. On a 16F88, I get inconsistent readings and cannot tell if it's the Adafruit part, some problem with my understanding of I2C statements, or general lunkheadedness. The link contains all in unique information I can find...
I'm hoping someone has a minute to comment...
I'm hoping someone has a minute to comment...
Code:
#CONFIG
__config _CONFIG1, _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF
__config _CONFIG2, _FCMEN_OFF & _IESO_OFF
#ENDCONFIG
DEFINE OSC 8
'-----DEBUG (SERIAL) SETUP----------------------------------------
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 3
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 0
OPTION_REG = %00001111 ' PULL-UPS ON, FALLING EDGE
TRISA = %00000000 ' Set PORTA output
TRISB = %00000000
OSCCON = %01110000
ANSEL = %00000000
T_ADDR VAR BYTE
T_ADDW VAR BYTE
T_REG VAR BYTE
KEYS VAR BYTE[2]
'-----PORT SET-UP-------------------------------------------------
SDA VAR PORTB.1
SCL VAR PORTB.0
T_ADDW = %10110100
T_ADDR = %10110101
T_REG = $0
i2cwrite SDA, SCL, T_ADDW, $5E, [%00111100] , I2CERR
i2cwrite SDA, SCL, T_ADDW, $0, [%11111111] , I2CERR
MAIN:
PORTA = 0
PAUSE 2000
PORTA = 255
PAUSE 50
GOSUB READKEYS
GOTO MAIN
READKEYS:
I2CRead SDA, SCL, T_ADDR, T_REG, [KEYS[0], KEYS[1]], I2CERR
DEBUG " ?--P110000000000", 13
DEBUG " ?--P109876543210", 13
DEBUG "k: ", BIN8 KEYS[1], BIN8 KEYS[0], 13
RETURN
I2CERR:
DEBUG "PROBLEM "
RETURN