well i didn't know that my "dump post" would provoke someone.
Jean80 i readed your "chatpad.c" and i understand a small part of it.. but anyways i know what this code do. but, sorry if my post provoke you. i was only trying to submit a dumb approach... to solve the main problem of this discution.
i don't know why but i've wished that keypad would be easy to mod, like th original Xbox controler that we have to skinn the cable, fit it to USB and TA-DA...
Code:
// FIRMWARE REPLACEMENT FOR CHATPAD's pic16f883.....
// see attached documents to learn more
// first release from jean (jean[at]ecando.it www.ecando.it)
// for the Open Keyboard Project
// thanks alot to Gidi (who owns an half of my chatpad)
// and my sweethart piceta; they helped me handling
// cable knots while testing.
const char map[4][49] = { //////// CHARACTER MAPPING MATRIX
// normal char press
{56, 57, 48, 13, 112, 44, 0,
0, 0, 0, 46, 32, 109, 0,
0, 122, 120, 118, 99, 98, 110,
97, 115, 100, 103, 102, 104, 106,
113, 119, 101, 116, 114, 121, 117,
49, 50, 51, 53, 52, 54, 55,
107, 105, 111, 0, 0, 108, 8},
// shifted
{56, 57, 48, 13, 80, 44, 0,
0, 0, 0, 46, 32, 77, 0,
0, 90, 88, 86, 67, 66, 78,
65, 83, 68, 71, 70, 72, 74,
81, 87, 69, 84, 82, 89, 85,
49, 50, 51, 53, 52, 54, 55,
75, 73, 79, 0, 0, 76, 8},
// green alt
{56, 57, 48, 13, 41, 58, 0,
0, 0, 0, 63, 32, 62, 0,
0, 96, 39, 45, 187, 124, 60,
126, 154, 123, 168, 125, 47, 39,
33, 64, 128, 37, 35, 94, 38,
49, 50, 51, 53, 52, 54, 55,
91, 42, 40, 0, 0, 93, 8},
// red alt
{56, 57, 48, 13, 61, 59, 0,
0, 0, 0, 191, 32, 181, 0,
0, 230, 156, 95, 231, 43, 241,
225, 223, 240, 165, 163, 92, 34,
161, 229, 232, 254, 36, 253, 249,
49, 50, 51, 53, 52, 54, 55,
169, 236, 242, 0, 0, 248, 8}
}; ////////// END OF MAPPING MATRIX
unsigned char AMask = 0;
unsigned char BMask = 0;
unsigned char data[] = {0,0,0,0,0,0,0};
unsigned char oldData[] = {0,0,0,0,0,0,0};
unsigned char sc = 0;
unsigned char idx = 0;
// alternates (shift,green,red) mapping to translation map
// 0 1 2 3 4 5 6 7
unsigned char alts [] = {0, 1, 2, 2, 3, 3, 3, 3};
unsigned char alt;
void main() {
OSCCON = 0x67; // 01100111 - 0110 stands for 4Mhz internal clock
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
PORTA = 0; // init port A
TRISA = 0; // 1 = input
PORTB = 0; // initialize PORTB
TRISB = 255; // designate PORTB as all input
OPTION_REG = 0; // pull-ups enabled
PORTC = 0; // initialize PORTC
TRISC = 0; // designate PORTB 0-7 as output
USART_Init(9600); // Initalize USART (9600 baud rate, 1 stop bit, no parity...)
// hope will override 0s set with PORTC=...
//----- TEST ------------------------
USART_Write('O');
USART_Write('K');
USART_Write('.');
USART_Write('.');
Delay_ms(100);
//------------------------------------
do {
idx = 0;
sc = 0;
PORTC = 1;
oldData[0] = data[0];
oldData[1] = data[1];
oldData[2] = data[2];
oldData[3] = data[3];
oldData[4] = data[4];
oldData[5] = data[5];
oldData[6] = data[6];
for (AMask=1; AMask<128; AMask<<=1){
PORTA = ~AMask;
data[sc] = ~PORTB;
for (BMask=1; BMask<128; BMask<<=1){
if (data[sc]&~oldData[sc] & BMask) USART_Write(map[alt][idx]);
idx++;
}
sc++;
}
alt = alts[data[2]&1|((data[1]&1)<<1)|((data[0]&64)>>4)];
} while (1); // endless loop
}