D
DarkKobold
I am writting a keyboard emulator for the pic microcontroller.
Unfortunately, after watching it on the oscilliscope, it is not
transmitting the right data. The clock signal on B1 is working correctly,
however, the actual data part is not. I've included this short snipet,
and the entire program, so anyone can peruse my work. Thanks for any and
all help.
for (i = 0; i<= 7; i++)
{
if ((buffer[curr] & y) == y)
// ^^ this line is the main problem I think.
{
parity = not(parity);
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y << 1;
}
Kyle
#include <16F874.H>
#use delay(clock=20000000)
#define ALLIN 0xFF
#define LiftC 0xF0
#define DirKey 0xE0
#define KeyTm 0x03
//ENTER UP LEFT DOWN RIGHT Q W 1
const char TBLP1[] = {0x5A, 0x75, 0x6B, 0x72, 0x74, 0x15, 0x1D, 0x16};
//5 A S D F G H 2
const char TBLP2[] = {0x36, 0x1C, 0x1B, 0x23, 0x2B, 0x34, 0x33, 0x1E};
int x;
int8 y;
int8 i;
int8 buffer[25];
int1 parity;
int8 buffsize;
int8 curr;
int8 next;
int8 load;
int8 P1;
int8 P2;
int8 P1Stat;
int8 P2Stat;
int1 Shift1;
int1 Shift2;
#byte PORTC = 6
#byte PORTD = 8
void buff_load()
{
buffsize++;
buffer[next] = load;
next++;
if (next == 25) next = 0;
}
//CLOCK on PIN B1
//DATA on PIN B0
void main()
{
curr = 0;
next = 0;
P1 = 0;
P2 = 0;
Shift1 = 0;
Shift2 = 0;
x = 0;
while(1)
{
set_tris_b(ALLIN);
set)tris_c(ALLIN); //Start Keyboard
//Test Key Values
P1Stat = PORTC;
/* if (!Input(PIN_C0) != bit_test(P1, 1))
{
}*/
x = 2;
for(i = 1; i <=7; i++)
{
if((not(P1Stat) & x) != (P1 & x))
{
if (i < 5)
{
load = DirKey;
buff_load();
}
if (bit_test(P1,x))
{
bit_set(P1,x);
}
else
{
bit_clear(P1,x);
load = LiftC;
buff_load();
}
load = TBLP1;
buff_load();
}
x << 1;
}
/* if (x == 1000 && P1 != 1)
{
P1 = 1;
load = TBLP1[7];
buff_load();
}
x++;*/
output_low(PIN_A0);
if (buffsize > 0)
{
//Test if keyboard is ready to transmit
while( !INPUT(PIN_B0) || !INPUT(PIN_B1))
{
}
delay_us(40);
//BEGIN TRANSMISSION
output_high(PIN_A0);
delay_ms(500);
parity = TRUE;
set_tris_b(KeyTm);
output_low(pin_B0);
delay_us(15);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y = 1;
for (i = 0; i<= 7; i++)
{
if ((buffer[curr] & y) == y)
{
parity = not(parity);
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y << 1;
}
if (parity)
{
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
output_high(PIN_B0);
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
buffsize = buffsize - 1;
if (curr != 25)
{
curr++;
}
else
{
curr = 0;
}
} //if (buffsize > 0)
} //while(1)
} //void main()
Unfortunately, after watching it on the oscilliscope, it is not
transmitting the right data. The clock signal on B1 is working correctly,
however, the actual data part is not. I've included this short snipet,
and the entire program, so anyone can peruse my work. Thanks for any and
all help.
for (i = 0; i<= 7; i++)
{
if ((buffer[curr] & y) == y)
// ^^ this line is the main problem I think.
{
parity = not(parity);
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y << 1;
}
Kyle
#include <16F874.H>
#use delay(clock=20000000)
#define ALLIN 0xFF
#define LiftC 0xF0
#define DirKey 0xE0
#define KeyTm 0x03
//ENTER UP LEFT DOWN RIGHT Q W 1
const char TBLP1[] = {0x5A, 0x75, 0x6B, 0x72, 0x74, 0x15, 0x1D, 0x16};
//5 A S D F G H 2
const char TBLP2[] = {0x36, 0x1C, 0x1B, 0x23, 0x2B, 0x34, 0x33, 0x1E};
int x;
int8 y;
int8 i;
int8 buffer[25];
int1 parity;
int8 buffsize;
int8 curr;
int8 next;
int8 load;
int8 P1;
int8 P2;
int8 P1Stat;
int8 P2Stat;
int1 Shift1;
int1 Shift2;
#byte PORTC = 6
#byte PORTD = 8
void buff_load()
{
buffsize++;
buffer[next] = load;
next++;
if (next == 25) next = 0;
}
//CLOCK on PIN B1
//DATA on PIN B0
void main()
{
curr = 0;
next = 0;
P1 = 0;
P2 = 0;
Shift1 = 0;
Shift2 = 0;
x = 0;
while(1)
{
set_tris_b(ALLIN);
set)tris_c(ALLIN); //Start Keyboard
//Test Key Values
P1Stat = PORTC;
/* if (!Input(PIN_C0) != bit_test(P1, 1))
{
}*/
x = 2;
for(i = 1; i <=7; i++)
{
if((not(P1Stat) & x) != (P1 & x))
{
if (i < 5)
{
load = DirKey;
buff_load();
}
if (bit_test(P1,x))
{
bit_set(P1,x);
}
else
{
bit_clear(P1,x);
load = LiftC;
buff_load();
}
load = TBLP1;
buff_load();
}
x << 1;
}
/* if (x == 1000 && P1 != 1)
{
P1 = 1;
load = TBLP1[7];
buff_load();
}
x++;*/
output_low(PIN_A0);
if (buffsize > 0)
{
//Test if keyboard is ready to transmit
while( !INPUT(PIN_B0) || !INPUT(PIN_B1))
{
}
delay_us(40);
//BEGIN TRANSMISSION
output_high(PIN_A0);
delay_ms(500);
parity = TRUE;
set_tris_b(KeyTm);
output_low(pin_B0);
delay_us(15);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y = 1;
for (i = 0; i<= 7; i++)
{
if ((buffer[curr] & y) == y)
{
parity = not(parity);
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y << 1;
}
if (parity)
{
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
output_high(PIN_B0);
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
buffsize = buffsize - 1;
if (curr != 25)
{
curr++;
}
else
{
curr = 0;
}
} //if (buffsize > 0)
} //while(1)
} //void main()