单片机驱动8位数码管怎么让其中2位闪烁,求助大佬,现在情况是只能整体闪烁不知道怎么控制其中2位闪烁
代码如下
- #include “reg52.h”
- sbit a=P2^2;
- sbit b=P2^3;
- sbit c=P2^4;
- sbit k1=P3^0;
- sbit k2=P3^1;
- sbit k4=P3^3;
- sbit k8=P3^7;
- unsigned char i=0;
- unsigned int l=0;
- unsigned int flag=0;
- unsigned int cishu=1;
- unsigned ssec=0,sec=5,min=0;
- unsigned DisplayData[8];
- unsigned code dongtai[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- void delay(unsigned int i)
- {
- while(i–);
- }
- void Timer0Init()
- {
- TMOD|=0X01;//选择为定时器0模式,工作方式1,仅用TR0打开启动。
- TH0=0Xd8; //给定时器赋初值,定时10ms
- TL0=0Xf0;
- ET0=1;//打开定时器0中断允许
- EA=1;//打开总中断
- TR0=1;//打开定时器
- }
- void Timer1Init()
- {
- TMOD|=0X10;//选择为定时器1模式,工作方式1,仅用TR1打开启动。
- TH1=0XFC; //给定时器赋初值,定时1ms
- TL1=0X18;
- ET1=1;//打开定时器1中断允许
- EA=1;//打开总中断
- TR1=1;//打开定时器
- }
- void aaa()
- {
- DisplayData[4]=dongtai[min/10];
- DisplayData[5]=dongtai[min%10]+0x80;
- DisplayData[6]=dongtai[sec/10];
- DisplayData[7]=dongtai[sec%10];
- DisplayData[0]=dongtai[cishu];
- DisplayData[1]=0x80;
- DisplayData[2]=0x80;
- DisplayData[3]=0x80;
- if(min==0&&sec==0)
- {
- DisplayData[4]= 0x3f;
- DisplayData[5]= 0x3f+0x80;
- DisplayData[6]= 0x3f;
- DisplayData[7]= 0x3f;
- }
- }
- void abc()
- {
- for(i=0;i<8;i++)
- { switch(i)
- { case(0): a=0;b=0;c=0; break;
- case(1): a=1;b=0;c=0; break;
- case(2): a=0;b=1;c=0; break;
- case(3): a=1;b=1;c=0; break;
- case(4): a=0;b=0;c=1; break;
- case(5): a=1;b=0;c=1; break;
- case(6): a=0;b=1;c=1; break;
- case(7): a=1;b=1;c=1; break;
- }
- if(l==1&&(i==0||i==1))
- {
- Timer1Init();
- }
- P0=DisplayData[i];
- delay(100);
- P0=0x00;
- }
- }
- void main()
- {
- P0=0x00;
- while(1)
- {
- if(k1!=0xFF)
- delay(1000);
- if(k1!=0xFF)
- {
- flag++;
- if(flag==1)
- {
- }
- else if(flag>1)
- {
- flag=1;
- cishu++;
- if(cishu>=9)
- {
- cishu=1;
- }
- }
- Timer0Init();
- sec=5;
- min=0;
- }
- while(!k1);
- if(k2!=0xFF)
- delay(30000);
- if(k2!=0xFF)
- {
- l++;
- while(!k2);
- if(l>=5)
- {
- l=0;
- }
- }
- abc();
- aaa();
- }
- }
- void Timer0() interrupt 1
- {
- TH0=0Xd8; //给定时器赋初值,定时10ms
- TL0=0Xf0;
- ssec++;
- if(ssec>=100) //1s
- {
- ssec=0;
- sec–;
- if(sec<=0)
- {
- if(min>0)
- {
- sec=60;
- min–;
- }
- if(min<=0)
- {
- if(sec==0)
- {
- TR0=0;
- }
- }
- }
- }
- }
- void Timer1() interrupt 3
- {
- static unsigned int j=0;
- TH1=0XFC; //给定时器赋初值,定时1ms
- TL1=0X18;
- j++;
- if(j>=500)
- {
- j=0;
- P0=0x00;
- delay(20000);
- }
- }
复制代码