Code:
//*******De An VDK Nhom OV_DHKHTN_TPHCM*******// //Tran Hoang Dat// /*chuong trinh DEMO giao tiep 8051 voi PS/2*/ #include <REGX51.H> #define rs P0_0 #define rw P0_1 #define enable P0_2 #define lcd_data P1 #define zise 20 unsigned char count=0,scancode=0,ip=0,capslock=0; const unsigned char meg_lcd_comman[5]= { 0x38,0x0E,0x01,0x06 }, meg_scancode_abc[47]={ 0x45,0x16,0x1E,0x26,0x25,0x2E,0x36,0x3D,0x3E,0x46, 0x1C,0x32,0x21,0x23,0x24,0x2B,0x34,0x33,0x43,0x3B, 0x42,0x4B,0x3A,0x31,0x44,0x4D,0x15,0x2D,0x1B,0x2C, 0x3C,0x2A,0x1D,0x22,0x35,0x1A,0x29,0x4E,0x55,0x54, 0x5B,0x5D,0x4C,0x52,0x41,0x49,0x4A }, meg_ascii_ABC[47]= { 48,49,50,51,52,53,54,55,56,57, 65,66,67,68,69,70,71,72,73,74, 75,76,77,78,79,80,81,82,83,84, 85,86,87,88,89,90,32,45,61,91, 93,92,59,39,44,46,47 }; unsigned char lcd_ready() { unsigned char busy; lcd_data = 0xFF; rw = 1; rw = 1; enable = 1; enable = 1; busy = lcd_data; enable = 0; return(busy); } void delay_us(unsigned char n) { unsigned char i; for(i=0;i<n;i++); } void delay_ms(unsigned int n) { unsigned int i; for(i=0;i<n;i++) delay_us(255); } void lcd_send_data( unsigned char data_or_comman ) { lcd_data = data_or_comman; lcd_data = data_or_comman; delay_us(10); enable = 1; delay_us(10); enable = 0; delay_us(10); } void lcd_buffer( unsigned char choice, unsigned char data_or_comman ) { rs = 0; while ( lcd_ready()&0x80) ; rs = choice; delay_us(10); rw = 0; delay_us(10); enable = 0; lcd_send_data(data_or_comman); } void lcd_sets() { char i; rs = 0; rw = 0; enable = 0; delay_ms(15); for(i=0;i<4;++i) lcd_buffer(0,meg_lcd_comman[i]); } void lcd_point_x_y( unsigned char x, unsigned char y) { unsigned char point; switch(y) { case 1 : point=0x80;break; case 2 : point=0xC0;break; case 3 : point=0x94;break; case 4 : point=0xD4;break; } point+=x-1; lcd_buffer(0,point); } void lcd_puts_char(char c) { lcd_buffer(1,c); } void lcd_puts_string( const char *msg) { while(*msg) lcd_puts_char(*msg++); ip++; } void inter_external(void) interrupt 0 { if(count<9) { scancode=scancode>>=1; if(P3_3) scancode|=0x80; else scancode|=0x00; } count++; } unsigned char cover_to_ascii(unsigned char temp_scancode) { unsigned char i,test; for(i=0;i<47;i++) { if(temp_scancode==meg_scancode_abc[i]) { test=1; break; } else test=0; } if(temp_scancode==0x58) { capslock=!capslock; ip--; } if(test) { if((capslock)||(i<10)||(scancode==0x29)||(i>=36)) return(meg_ascii_ABC[i]); else return(meg_ascii_ABC[i]+32); } else { ip--; return(0); } } void main(void) { char temp_lcd[1]; P3_3=1;// data P3_2=1;// clock TR1=1; lcd_sets(); while(scancode!=0x76) { while(count<33) { EA=1; EX0=1; IT0=1; } temp_lcd[0]=cover_to_ascii(scancode); if(scancode!=0x66) { lcd_buffer(0,meg_lcd_comman[3]); } else { lcd_buffer(0,0x04); lcd_puts_string(" "); ip=ip-3; } lcd_puts_string(temp_lcd); count=0; if((ip==16)||(scancode==0x5A)) { lcd_buffer(0,0xC0); ip=17; } } /////////////////////////////////////////////// while(1) { delay_ms(800); lcd_buffer(0,0x0A); delay_ms(800); lcd_buffer(0,0x0C); } }
mong anh em góp ý để hoàn thiện đề tài
Comment