📄 ps2barcode.c
字号:
//#include <AT89X52.h>
#include "me.h"
#include "disp.h"
#include "LCD1602.h"
sbit Ps2Dat = P1^0;
sbit Ps2Clk = P3^3;//INT1 low
unsigned char code ASCII[] ="0123456789ABCDEF";
unsigned int KeyGet( void );
unsigned char KeyPut( int KeyVal);
unsigned char KeyBack( int KeyVal);
void KeyClear( void );
void KeyInitial(void);
void KeyScan( void );
#define KEYBUFSIZE 32
unsigned char KeyBuf[KEYBUFSIZE];
unsigned char KeyRp=0;
unsigned char KeyWp=0;
void main( void )
{
unsigned int KeyVal;
KeyInitial();
LCD_init();
CLEARSCREEN;
// delay_nms(2);
LCD_write_string(LINE1,0,"ESCAdd");
while(1)
{
KeyVal = KeyGet();
if( KeyVal != 0xff )
{
LCD_write_string(LINE1,0,"Add");
P30=~P30;
P31=~P31;
// LCD_write_char(LINE1,0,'A');
}
// KeyScan();
}
}
unsigned int KeyGet( void )
{
unsigned int RetVal=0xff,flag=0;
if( KeyRp != KeyWp )
{
RetVal = KeyBuf[ KeyRp ];
switch (RetVal)
{
case 0x0e: RetVal=0x30; break;
case 0x96: RetVal=0x31; break;
case 0x4e: RetVal=0x32; break;
case 0x5e: RetVal=0x33; break;
case 0xd6: RetVal=0x34; break;
case 0xce: RetVal=0x35; break;
case 0x2e: RetVal=0x36; break;
case 0x36: RetVal=0x37; break;
case 0xae: RetVal=0x38; break;
case 0xbe: RetVal=0x39; break;
case 0x9e: RetVal=0x2b; break;
case 0xde: RetVal=0x2d; break;
case 0x3e: RetVal=0x2a; break;
case 0x8e: RetVal=0x2e; break;
case 0x0f: RetVal=0xff00; break;
case 0x52: RetVal=0x2f; break;
default: RetVal=0x0a; flag=1;
}
if( ++KeyRp >= KEYBUFSIZE ) KeyRp=0;
}
return( RetVal );
}
void KeyInitial( void )
{
TMOD = 0x20; //9600, crystal = 22.1184MHz
TH1 = -3;
SCON = 0x42;
PCON = 0x80;
TI = 1;
TR1 = 1;
Ps2Clk = 1;
Ps2Dat = 1;
INT1 = 1;
IT1 = 1;
EX1 = 1;
EA = 1;
}
void KeyScan( void ) interrupt 2 //int1
{
static unsigned char ch;
static unsigned char cnt=0;
static unsigned int abc=0;
if( (cnt==0) && (Ps2Dat==1) ) return;
ch <<= 1; if( Ps2Dat == 1 ) ch |=0x01;
if( ++cnt == 9 )
{
KeyBuf[ KeyWp ]= ch;
LCD_write_char(LINE2,abc++,ASCII[ch>>4]);
LCD_write_char(LINE2,abc++,ASCII[ch&0x0f]);
if(abc==16)
{
abc=0;
CLEARSCREEN;
}
if( ++KeyWp >= KEYBUFSIZE ) KeyWp=0;
}
if( cnt == 11) cnt=0;
}
/*
void KeyScan( void ) //interrupt 0
{
// static unsigned char Clk_Sta;
static unsigned char ch;
static unsigned char cnt=0;
static unsigned int abc=0;
// if (Ps2Clk!=Clk_Sta)
// {
// if (Ps2Clk==0)
// {
if( (cnt==0) && (Ps2Dat==1) ) return;
if( (cnt==0) && (Ps2Dat==1) )
{
return;
}
ch <<= 1;
if( Ps2Dat == 1 )
{
ch |=0x01;
}
if( ++cnt == 9 )
{
KeyBuf[ KeyWp ]= ch;
LCD_write_char(LINE2,abc++,ASCII[ch>>4]);
LCD_write_char(LINE2,abc++,ASCII[ch&0x0f]);
if(abc==16)
{
abc=0;
CLEARSCREEN;
}
if( ++KeyWp >= KEYBUFSIZE )
{
KeyWp=0;
}
}
if( cnt == 11)
{
cnt=0;
}
}
// Clk_Sta=Ps2Clk;
// }
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -