标题: 51单片机使用定时器控制流水灯-分享文件 [打印本页]

作者: !=5    时间: 2020-2-19 10:32
标题: 51单片机使用定时器控制流水灯-分享文件
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar oxfe;
uchar b,j,c,n=0,i=0,k=0,d=0;
void dsqcsh(void)
{
        TMOD |=0x01;
        TH0=0x20;
        TL0=0xD1;
        EA=1;
        ET0=1;
        TR0=1;
}
void dsqzd() interrupt 1 using 1
{
        n++;
        TH0=0x20;
        TL0=0xD1;
        if(n==2)//10ms
        {
                if(i!=7)
                {
                P2=b;
                b=_crol_(b,1);//左移
                n=0;
                i++;}
                else
                {       
          P2=b;
                b=_cror_(b,1);                //右移
                d++;
                n=0;
                        if(d==7)
                        {i=0;
                                d=0;
                        }
                }
        }

}

void delay(uchar t)
{
        while(t--);

}
void main()
{
        dsqcsh();
        b=0xfe;
        while(1);
}



1.PNG (55.52 KB, 下载次数: 31)

proteus中的电路图

proteus中的电路图





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