السلام عليكم
كود:
// using pic18f45k22 and crystal 8MHZ
sbit LCD_RS at PORTB.b4;
sbit LCD_EN at PORTB.b5;
sbit LCD_D4 at PORTB.b0;
sbit LCD_D5 at PORTB.b1;
sbit LCD_D6 at PORTB.b2;
sbit LCD_D7 at PORTB.b3;
sbit LCD_RS_Direction at TRISB.b4;
sbit LCD_EN_Direction at TRISB.b5;
sbit LCD_D4_Direction at TRISB.b0;
sbit LCD_d5_Direction at TRISB.b1;
sbit LCD_d6_Direction at TRISB.b2;
sbit LCD_d7_Direction at TRISB.b3;
char keydata = 0, special = 0, down = 0;
sbit PS2_Data at portc.b6;
sbit PS2_Clock at portc.b7;
sbit PS2_Data_Direction at TRISc.b6;
sbit PS2_Clock_Direction at TRISc.b7;
void main() {
char tolcd[4];
ansela=0;
anselb=0;
anselc=0;
anseld=0;
Lcd_Init();
Ps2_Config();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
while(1)
{
if(down==0)Ps2_Key_Read(&keydata, &special, &down);
ByteToStr(keydata,tolcd); // show Ascii code
lcd_out(1,1,tolcd);
if(special==0 && down==1)lcd_chr(2,1,keydata); // show character
down=0;
special=0;
}
}
طبعا الكود لغرض فحص مكتبه ps2
1- الارقام تعمل بشكل طبيعي
2- الاحرف الصغيره اي من a to z تعمل بشكل طبيعي
3- لكي تعمل الاحرف الكبيره A to Z يجب الضغط على Caps Lock
4- يوجد في بعض ازرار الكيبورد اكثر من وظيفه على سبيل مثال
رقم 3 معه # ولكي احصل على # لابد من الضغط على SHift
5- الاحرف Special Function Keys تعمل بشكل صحيح وانتبه هذه مفاتيح تؤدي مهام خاصه لها مثل Caps Lock تحول من حروف صغيره الى كبيره بدون تدخل منا
وكذلك shift يغير بين وظائف مفتاح الواحد
تحياتي