ai làm cái này rùi chỉ em với seo nó ko chạy nè
//giao tiep cong ps2
//
//************************************************** ******************
#include <16F877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT
#use delay(clock=4000000)
#include<lcd_lib_4bit.c>
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
#byte portd=0x08
#byte porte=0x09
#bit clk = portb.0
#bit data = portc.0
int8 A=0;
int i;
//int t;
#bit A7 = A.7
int du_lieu;
#int_ext
void ngat()
{
disable_interrupts(global);
//xung ck thu 1, bo qua bit start
LCD_putcmd(0x80);
delay_ms(100);
printf(LCD_putchar,"dien_tu_viet_nam");
delay_ms(100);
while(!clk){} //cho canh len (xung clock)
for (i = 0; i < 8; i++)
{ //chor canh xuong cua xung ck thu 2 thi bat dau nhan
while(clk){}
delay_ms(5);
A7 = data; //nhan bit du lieu bat dau tu bit cao nhat
A = A >> 1;
delay_ms(5);
while(!clk){} //cho xung ck len tro lai
}
du_lieu = A;
while(clk){} //cho xung ck len tro lai
while(!clk){} //bo qua bit parity
while(clk){}
while(!clk){} //bo qua bit stop
delay_ms(100);
enable_interrupts(global);
}
void main(void)
{
set_tris_b(0b00000001);
set_tris_c(0);
set_tris_e(0);
enable_interrupts(global);
enable_interrupts(int_ext);
ext_int_edge(H_to_L);
LCD_init();
LCD_putcmd(0x80);
delay_ms(100);
printf(LCD_putchar,"ps2 keyboard");
delay_ms(100);
LCD_putcmd(0xc0);
delay_ms(100);
//Line_2;
//45H,16H,1EH,26H,25H,2EH,36H,3DH,3EH,46H
//69 ,22 ,30 ,38 ,37 ,46 ,54 ,61 ,62 ,70 ,112,105,114,122,107,115,116,108,117,125
//'0123456789
if(du_lieu==0x45)
{
printf(LCD_putchar,"0");
delay_ms(250);
}
if(du_lieu==0x16)
{
printf(LCD_putchar,"1");
delay_ms(250);
}
if(du_lieu==0x1E)
{
printf(LCD_putchar,"2");
delay_ms(250);
}
if(du_lieu==0x26)
{
printf(LCD_putchar,"3");
delay_ms(250);
}
if(du_lieu==0x25)
{
printf(LCD_putchar,"4");
delay_ms(250);
}
if(du_lieu==0x2E)
{
printf(LCD_putchar,"5");
delay_ms(250);
}
if(du_lieu==0x36)
{
printf(LCD_putchar,"6");
delay_ms(250);
}
if(du_lieu==0x3D)
{
printf(LCD_putchar,"7");
delay_ms(250);
}
if(du_lieu==0x3E)
{
printf(LCD_putchar,"8");
delay_ms(250);
}
if(du_lieu==0x46)
{
printf(LCD_putchar,"9");
delay_ms(250);
}
else printf(LCD_putchar,"no thing press !");
delay_ms(250);
}
//giao tiep cong ps2
//
//************************************************** ******************
#include <16F877a.h>
#fuses NOWDT,PUT,HS,NOPROTECT
#use delay(clock=4000000)
#include<lcd_lib_4bit.c>
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
#byte portd=0x08
#byte porte=0x09
#bit clk = portb.0
#bit data = portc.0
int8 A=0;
int i;
//int t;
#bit A7 = A.7
int du_lieu;
#int_ext
void ngat()
{
disable_interrupts(global);
//xung ck thu 1, bo qua bit start
LCD_putcmd(0x80);
delay_ms(100);
printf(LCD_putchar,"dien_tu_viet_nam");
delay_ms(100);
while(!clk){} //cho canh len (xung clock)
for (i = 0; i < 8; i++)
{ //chor canh xuong cua xung ck thu 2 thi bat dau nhan
while(clk){}
delay_ms(5);
A7 = data; //nhan bit du lieu bat dau tu bit cao nhat
A = A >> 1;
delay_ms(5);
while(!clk){} //cho xung ck len tro lai
}
du_lieu = A;
while(clk){} //cho xung ck len tro lai
while(!clk){} //bo qua bit parity
while(clk){}
while(!clk){} //bo qua bit stop
delay_ms(100);
enable_interrupts(global);
}
void main(void)
{
set_tris_b(0b00000001);
set_tris_c(0);
set_tris_e(0);
enable_interrupts(global);
enable_interrupts(int_ext);
ext_int_edge(H_to_L);
LCD_init();
LCD_putcmd(0x80);
delay_ms(100);
printf(LCD_putchar,"ps2 keyboard");
delay_ms(100);
LCD_putcmd(0xc0);
delay_ms(100);
//Line_2;
//45H,16H,1EH,26H,25H,2EH,36H,3DH,3EH,46H
//69 ,22 ,30 ,38 ,37 ,46 ,54 ,61 ,62 ,70 ,112,105,114,122,107,115,116,108,117,125
//'0123456789
if(du_lieu==0x45)
{
printf(LCD_putchar,"0");
delay_ms(250);
}
if(du_lieu==0x16)
{
printf(LCD_putchar,"1");
delay_ms(250);
}
if(du_lieu==0x1E)
{
printf(LCD_putchar,"2");
delay_ms(250);
}
if(du_lieu==0x26)
{
printf(LCD_putchar,"3");
delay_ms(250);
}
if(du_lieu==0x25)
{
printf(LCD_putchar,"4");
delay_ms(250);
}
if(du_lieu==0x2E)
{
printf(LCD_putchar,"5");
delay_ms(250);
}
if(du_lieu==0x36)
{
printf(LCD_putchar,"6");
delay_ms(250);
}
if(du_lieu==0x3D)
{
printf(LCD_putchar,"7");
delay_ms(250);
}
if(du_lieu==0x3E)
{
printf(LCD_putchar,"8");
delay_ms(250);
}
if(du_lieu==0x46)
{
printf(LCD_putchar,"9");
delay_ms(250);
}
else printf(LCD_putchar,"no thing press !");
delay_ms(250);
}