给你改了,对比一下就知道哪里错了。
- #include <stc15.h>
- sbit S0 = P4^1;
- sbit S1 = P4^2;
- sbit S2 = P4^3;
- sbit S3 = P4^4;
- sbit leden = P2^7;
- unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x6f}; //数组
- unsigned char wei[]={0,0,0,0}; //显示的位
- unsigned char flag1s=0;
- unsigned char i=0;
- unsigned int j=0; // 、、??//计时次数
-
- void Timer0Init(void) //100微秒@11.0592MHz
- {
- AUXR |= 0x80; //定时器时钟1T模式
- TMOD &= 0xF0; //设置定时器模式
- TMOD |= 0x01; //设置定时器模式
- //TMOD &= 0x01; //设置定时器模式
- TL0 = 0x67; //设置定时初值
- TH0 = 0xFC; //设置定时初值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- }
- void main()
- {
- unsigned long k=0;
- TMOD = 0X01;
- TH0 = 0XFC;
- TL0 = 0X67;
- TR0 = 1;
- EA = 1;
- ET0 = 1;
- leden = 0;
- while(1)
- {
- if(flag1s==1) //定时器溢出复位
- { flag1s =0;
- k++;
- wei[3] = tab[k%10];
- wei[2] = tab[k/10%10];
- wei[1] = tab[k/100%10];
- wei[0] = tab[k/1000%10];
- }
- }
- }
- void IntrruptTime0() interrupt 1
- {
- TH0=0XFC;
- TL0=0X67;
- j++;
- if(j>=1000)
- {
- j = 0;
- flag1s = 1;
- }
- P0=0xFF;
- switch(i)
- {
- case 0: S3=1;S2=0;S1=0;S0=0;i++;P0=wei[0];
- case 1: S3=0;S2=1;S1=0;S0=0;i++;P0=wei[1];
- case 2: S3=0;S2=0;S1=1;S0=0;i++;P0=wei[2];
- case 3: S3=0;S2=0;S1=0;S0=1;i++;P0=wei[3];
- default: break;
- }
- }
复制代码 |