keil调试过程中,table数组类型为char时,进入定时器1中断时间有问题,并不是设置的50ms,大概只有1-2ms,而数组类型改为int时,时间正确,这里面设置char和int有什么不同吗,求各位大侠帮忙解答一下
单片机源程序:
- #include<reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit alarm=P3^7;
- uint code table[]={50000,10000,5000,2500,1250,625,500};
- uchar i,duan,wei,num;
- void main()
- {
- alarm=1;
- i=0;
- TMOD=0x11;
- TH0=(65535-table[i])/256;
- TL0=(65535-table[i])%256;
- TH1=(65535-50000)/256;
- TL1=(65535-50000)%256;
- EA=1;
- ET0=1;ET1=1;
- TR0=1;TR1=1;
-
- while(1)
- {
- if(wei>0)
- {
- TR0=0;
- alarm=~alarm;
- wei=0;
- TR0=1;
- }
- }
- }
- void it0() interrupt 1
- {
- TH0=(65535-table[i])/256;
- TL0=(65535-table[i])%256;
- wei++;
- }
复制代码
|