楼主自信软件没问题,其实就是软件问题:中断向量入口错误。
- #include<reg51.h>
- #include<intrins.h>
- sbit duan=P3^0;
- sbit wei=P3^1;
- unsigned int ct0=0;
- unsigned char count=0;
- unsigned char code table[] = {
- 0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,
- 0x39,0x5e,0x79,0x71 };
- void delay(unsigned int z) //延迟
- {
- unsigned char i,j;
- for(i=0;i<z;i++)
- for(j=0;j<110;j++);
- }
- void cl(void) //初始化
- {
- TMOD=0x15; //T0外部计数器T1定时器
- TH0=0x00;
- TL0=0x00;
- TH1 = 0x3C; //设置定时器T1初值50ms
- TL1 = 0xB0; //设置定时器T1初值50ms
- TR0=1;
- TR1=1;
- EA=1;
- // ET0=1;
- ET1=1;
- }
- void show6led(unsigned int num)
- {
- static unsigned char count=0; //计数变量
- P2=0x00; //消隐
- duan=1;
- duan=0;
- switch(count)
- {
- case 0:
- P2=table[num/10000%10];
- duan=1;
- duan=0;
- P2=0x7d;
- wei=1;
- wei=0;
- count++;
- break;
- case 1:
- P2=table[num/1000%10]|0x80;
- duan=1;
- duan=0;
-
- P2=0x7b;
- wei=1;
- wei=0;
- count++;
- break;
- case 2:
- P2=table[num/100%10];
- duan=1;
- duan=0;
-
- P2=0x77;
- wei=1;
- wei=0;
- count++;
- break;
- case 3:
- P2=table[num/10%10];
- duan=1;
- duan=0;
-
- P2=0xef;
- wei=1;
- wei=0;
- count++;
- break;
- case 4:
- P2=table[num%10];
- duan=1;
- duan=0;
-
- P2=0xdf;
- wei=1;
- wei=0;
- count=0;
- break;
- }
- }
- void main()
- {
- cl();
- while(1)
- {
- show6led(ct0);
- delay(1);
- }
- }
- void t() interrupt 3 //T1中断服务函数
- {
- TH1 = 0x3C; //设置定时初值50ms
- TL1 = 0xB0; //设置定时初值
- count++;
- if(count>=20) //1秒
- {
- count=0;
- ct0=TH0<<8|TL0;//读取T0计数值
- TH0=0x00;
- TL0=0x00;
- }
- }
复制代码
|