#includesbit DIO=P1^2;sbit CLK=P1^1;sbit STB=P1^0;#define DIG0 0xc0#define DIG1 0xc2#define DIG2 0xc4 #define DIG3 0xc6#define DIG4 0xc8#define DIG5 0xca#define DIG6 0xcc#define DIG7 0xce#define LEVEL_OFF 0x80#define LEVEL_1 0x88#define LEVEL_2 0x89#define LEVEL_4 0x8a#define LEVEL_10 0x8b#define LEVEL_11 0x8c#define LEVEL_12 0x8d#define LEVEL_13 0x8e#define LEVEL_14 0x8f#define MD_WRITE 0x40#define MD_AUTO MD_WRITE#define MD_NORMAL MD_WRITE#define MD_READKEY 0x42#define MD_FIX 0x44#define MD_TEST 0x48typedef unsigned char uint8;typedef unsigned int uint16;uint16 key;code uint8 shuzu[17] ={ 0x3F,0x06,0x5B,0x4F, 0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00, }; void xianshi(uint8 x,uint8 led,uint8 level);void shizhong();void chushi();void ClearAll();void KeyRead(uint16 *key);void indate(unsigned char input){unsigned int i;STB=0; for(i=0;i<8;i++) {CLK=0; if((input & 0x01)!=0)DIO=1; elseDIO=0; CLK=1; input=input>>1; } }unsigned char outdate(){unsigned char i,out=0; DIO= 1;STB=0; for(i=0;i<8;i++) {CLK=0; out=out>>1;if(DIO == 0)out=out & 0x7f; else out=out | 0x80;CLK=1; }return(out); }void chushi(){CLK = 1;STB = 1;DIO = 1;}void jishi(){ TMOD |= 0x10;TMOD &= 0xdf;TH1=0xb8;TL1=0x00;TR1=1;EA=1;ET1 = 1;}void ql(){xianshi(7,0,LEVEL_11);xianshi(6,0,LEVEL_11);xianshi(4,0,LEVEL_11);xianshi(3,0,LEVEL_11);xianshi(1,0,LEVEL_11);xianshi(0,0,LEVEL_11);}void xianshi(uint8 x,uint8 led,uint8 level){uint8 i;static uint8 cled[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};for(i = 0 ;i < 8;i ++ ){if((shuzu[led]>>i)&0x01)cled[i] |= (0x01<< x);elsecled[i] &= ~(0x01<< x);}DIO=1;CLK=1;STB=1; indate(MD_WRITE);STB = 1;indate(DIG0);for( i = 0 ; i<16; i+= 2){indate(cled[i/2] & 0x0f); indate(cled[i/2] >> 4 & 0x0f);}STB=1; indate(level);STB=1;}void ClearAll(){unsigned int i; DIO=1;CLK=1;STB=1; indate(MD_AUTO); STB=1; indate(DIG0); for(i=0;i<16;i++) indate(0); STB=1; indate(0x80); STB=1; }void KeyRead(uint16 *key){unsigned char key1,key2;STB=1;indate(MD_READKEY); key1 = outdate();key2 = outdate();*key = key1 | (key2 << 8);STB=1;} void delay(){ uint16 n;uint8 k;for(k=0;k<10;k++){for(n=0;n<6000;n++);}}
評論