本帖最后由 lkc8210 于 2021-10-24 23:01 编辑
改用联合体又正常了
- #include <reg52.h>
- sbit LED1=P3^5;
- typedef union{
- unsigned char Dat_c[2];
- unsigned int Dat_i;
- }EData;
- EData TMR_XX;
- sfr AUXR = 0x8E;
- void Timer0Init(void) //1毫秒@12.000MHz
- {
- AUXR &= 0x7F; //定时器时钟12T模式
- TMOD &= 0xF0; //设置定时器模式
- TMOD |= 0x00; //设置定时器模式
- TL0 = 0x18; //设置定时初始值
- TH0 = 0xFC; //设置定时初始值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- }
- void timer0_int (void) interrupt 1
- {
- if(TMR_XX.Dat_i)TMR_XX.Dat_i--;
- }
- void main()
- {
- Timer0Init();
- ET0 = 1;
- EA = 1;
- while(1)
- {
- if(!TMR_XX.Dat_c[0] && !TMR_XX.Dat_c[1])
- {TMR_XX.Dat_i=270;
- LED1 = !LED1;
- }
- }
- }
复制代码
编译出来发现if(!TMR_XX_OT)是用ORL
- 30: if(!TMR_01_OT)
- C:0x0013 E509 MOV A,0x09
- C:0x0015 4508 ORL A,TMR_01_OT(0x08)
- C:0x0017 70FA JNZ C:0013
- 31: {TMR_01_OT=270;
- C:0x0019 750801 MOV TMR_01_OT(0x08),#0x01
- C:0x001C 75090E MOV 0x09,#0x0E
复制代码
if(!TMR_XX.Dat_c[0] && !TMR_XX.Dat_c[1]) 是用两个JNZ
- 34: if(!TMR_XX.Dat_c[0] && !TMR_XX.Dat_c[1])
- C:0x0013 E508 MOV A,TMR_XX(0x08)
- C:0x0015 70FC JNZ C:0013
- C:0x0017 E509 MOV A,0x09
- C:0x0019 70F8 JNZ C:0013
- 35: {TMR_XX.Dat_i=270;
- C:0x001B 750801 MOV TMR_XX(0x08),#0x01
- C:0x001E 75090E MOV 0x09,#0x0E
复制代码
是ORL有问题吗?
|