- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- //uchar code table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90};//数码管段选
- uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共阴数码管段码"0~9"
- uchar code wela[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//数码管位选
- //sbit d1=P1^0;
- //sbit beep=P2^3;
- sbit switch1=P2^6;//段选LE
- sbit switch2=P2^7;//位选LE
- uchar x;//tt;
- /*
- void delay(uint z)//unit是宏定义
- {
- uint x;
- for(x=z;x>0;x--);
- }*/
- void display()
- {
- P0=0x00;
- switch1=1;
- switch1=0;
- P0=wela[x];
- switch2=1;
- switch2=0;
- P0=table[x];
- switch1=1;
- switch1=0;
- if(++x>=6)
- x=0;
- }
- void main()
- {
- // tt=0;
- TMOD=0x01;//设置定时器0工作方式
- TH0=(65536-2000)/256;//2ms
- TL0=(65536-2000)%256;
- // EA=1;//总中断
- // ET0=1;//
- TF0=0;
- TR0=1;//启动定时器
- // beep=0;
- while(1)
- {
- if(TF0)//查询方式
- {
- TF0=0;
- TH0=(65536-2000)/256;
- TL0=(65536-2000)%256;
- display();
- }
- }
- }
复制代码
|