- #include "reg52.h"
- #include "intrins.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define STOP 398
- //特殊寄存器申明
- sbit section=P2^7;
- sbit part=P2^6;
- //-----------------------
- uchar temp,timer_0,timer_1,hundred,ten,one;
- uint digital_num;
- /*---------(0,1,2,3,4,5,6,7,8,9)--------*/
- uchar code digital_list[]={
- 0x3f,0x06,0x5b,0x4f,0x66,
- 0x6d,0x7d,0x07,0x7f,0x67};
- /*------------------------------------*/
- void init();
- void display(uchar section_1,uchar section_2,uchar section_3,uchar section_4,uchar section_5,uchar section_6);
- void delay(uint x)
- {
- uchar a,b;
- for(a=x;a>=0;a--)
- for(b=110;b>=0;b--)
- ;
- }
- void main()
- {
- init();
- while(1)
- {
- // display(7,6,5,hundred,ten,one);
- }
- }
- void init()
- {
- digital_num=432;
- temp=0xfe;
- P1=temp;
- TMOD=0x11;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- TH1=(65536-50000)/256;
- TL1=(65536-50000)%256;
- EA=1;
- ET0=1;
- ET1=1;
- TR0=1;
- TR1=1;
- }
- void time0() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- timer_0++;
- if(timer_0==10)
- {
- timer_0=0;
- temp=_crol_(temp,1);
- P1=temp;
- }
- }
- void time1() interrupt 3
- {
- TH1=(65536-50000)/256;
- TL1=(65536-50000)%256;
- timer_1++;
- //display(7,6,5,hundred,ten,one);
- if(timer_1==2)
- {
- timer_1=0;
- /*----------进行位分解------------------*/
- hundred=digital_num/100;
- ten=digital_num/10%10;
- one=digital_num%10;
- /*---------------------------------------*/
- digital_num--;
- if(digital_num==STOP)
- {
- TR0=0;
- TR1=0;
- }
- }
- }
- /*------------------------------------------数码管动态扫描---------------------------------------------------*/
- void display(uchar section_1,uchar section_2,uchar section_3,uchar section_4,uchar section_5,uchar section_6)
- {
- part=1;
- P0=digital_list[section_1];
- part=0;
- P0=0xff;
- section=1;
- P0=0xfe;
- section=0;
- delay(1);
- part=1;
- P0=digital_list[section_2];
- part=0;
- P0=0xff;
- section=1;
- P0=0xfd;
- section=0;
- delay(1);
- part=1;
- P0=digital_list[section_3];
- part=0;
- P0=0xff;
- section=1;
- P0=0xfb;
- section=0;
- delay(1);
- part=1;
- P0=digital_list[section_4];
- part=0;
- P0=0xff;
- section=1;
- P0=0xf7;
- section=0;
- delay(1);
- part=1;
- P0=digital_list[section_5];
- part=0;
- P0=0xff;
- section=1;
- P0=0xef;
- section=0;
- delay(1);
- part=1;
- P0=digital_list[section_6];
- part=0;
- P0=0xff;
- section=1;
- P0=0xdf;
- section=0;
- delay(1);
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>