标题: 51单片机中断和查询工作模式的区别 [打印本页]

作者: liuqq    时间: 2015-5-20 18:17
标题: 51单片机中断和查询工作模式的区别
中断是硬件自动的清零,查询如果是查询的TFX就必须软件清零,如果查询的是THX和TLX就也是硬件自动的清零。验证的程序如:


#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar count ;
sbit LED=P3^0;
void main()
{
        TMOD = 0X01;
        TH0 = (65536 - 50000)/256;
        TL0 = (65536 - 50000)%256;
        ET0 =1;
        TR0 = 1;
        while(1)
        {
            while(TF0 == 1)
                {
                        if(count++ == 50)
                        {
                            LED =!LED;
                        }
                        TH0 = (65536 - 50000)/256;
                    TL0 = (65536 - 50000)%256;
                    TF0 = 0;
                }                                                                   //查询工作的模式        软件清零
        }
}       

#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
uint count=0;
void main()
{       
       TMOD = 0X01;       
        TH0 = (65536-50000)/256;       
        TL0 =(65536-50000)%256;       
        ET0 = 1;       
        TR0 = 1;       
        while(1)
        {
                if((TH0 == 65535/256)&&(TL0 == 65535%256))                {
                        count++;
                        if(count == 50)
                        {
                                P3 = ~P3;
                                count = 0;
                        }
                    TH0 =(65536-50000)/256;
                TL0 =(65536-50000)%256;
                }
        }
}

       







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1