koolguy
Active Member
Hi again,
I want to add keyboard with this AT/2 6 pin..what will be the procedure? i am preparing code for PC keyboard .
I want to add keyboard with this AT/2 6 pin..what will be the procedure? i am preparing code for PC keyboard .
#include<pic.h>
#define _XTAL_FREQ 20000000L
__CONFIG(0x3F18);
char displayPointer=0;
extern const char font[];
unsigned char buffer[26]; // buffer for screen
void interrupt ISR() // This just swaps the buffer to the display
{
if(TMR2IF) // make sure its the timer interrupt.
{
PORTB = 0; // clear old data first
if(displayPointer == 0 ) // 1st frame..
RC4 = 1; // Data = 1 on the first clock
RC3 = 1;
__delay_us(20); // Clock the shift registers
RC3 = 0;
RC4 = 0;
PORTB = buffer[displayPointer]; // Move buffer line by line
if(++displayPointer==24) // 24 LED columns
displayPointer = 0; // back to first..
}
TMR2IF = 0;
}
void display(const char* str)
{
int addr;
char x, y;
while(*str != 0) // while there is still characters
{
addr = (int) *str++ - 0x20; // get character
addr *=5;
for(y=0;y<5;y++) // 5x8 font so 5 columns
{
buffer[25] = font[addr++]; // put it in buffer
for(x=0;x<26;x++)
{
buffer[x] = buffer[x+1]; // shift all the columns <--
__delay_ms(5); // so you can see it
}
}
buffer[25] = 0; // This is the scpace between
for(x=0;x<26;x++) // the characters.. Or they will be too close
{
buffer[x] = buffer[x+1]; // shift the space in
__delay_ms(5);
} // NOTE!!! your array is 28 not 24 like mine
}
}
void main(void)
{
ADCON1 = 0x6;
T2CON = 0x1e;
PR2 = 129; // timer preload value
TMR2IE = 1; // enable timer 2 interrupt
PEIE = 1; // enable peripheral interrupt
GIE = 1; // enableglobal interrupt
TRISB = 0; // Port B as output...
TRISC = 0; // Port C as ouput...
while(1)
{
display("HELLO WORLD!!! "); // Here's the message
}
} // End main