微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > Tm1639汇编驱动程序

Tm1639汇编驱动程序

时间:11-29 来源:互联网 点击:
#include
sbit 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++);}}void zhongduan()interrupt 3{shizhong();}void shizhong(){static uint16 count=0;static uint16 scount=0;static uint8  a=0;static uint8  b=0;static uint8  c=0;static uint8  d=0; static uint8  x=0;static uint8  y=0;TH1=0xb8;TL1=0x00;count++;if(count==5){count=0;scount++;x=scount/10%10;y=scount/100%10; xianshi(7,x,LEVEL_11);if(scount%600==0){xianshi(6,0,LEVEL_11);scount=0;a++;}else xianshi(6,y,LEVEL_11);if(a>=10){a=0;b++;}xianshi(4,a,LEVEL_11);if(b>=6){b=0;c++;}xianshi(3,b,LEVEL_11);if(d<2){if(c==10){c=0;d++;}xianshi(1,c,LEVEL_11);xianshi(0,d,LEVEL_11);}else if(d>=2){if(d>2)d=0;if(c==4){c=0;d=0;}xianshi(1,c,LEVEL_11);xianshi(0,d,LEVEL_11);}KeyRead(&key);if(key==0x0008)a++;KeyRead(&key);if(key==0x0080)b++;KeyRead(&key);if(key==0x0800)c++;KeyRead(&key);if(key==0x8000)d++;if(key==0x0004){scount=0;x=0;y=0;}}}main(){ql();jishi();while(1){};  

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top