標(biāo)題: 各位大佬幫我看下單片機(jī)控制LED燈閃爍程序可否,萬分感謝 [打印本頁]

作者: luogu34    時(shí)間: 2022-11-22 22:39
標(biāo)題: 各位大佬幫我看下單片機(jī)控制LED燈閃爍程序可否,萬分感謝
開始時(shí),第一個(gè)燈閃爍,時(shí)間間隔為1s。當(dāng)按下按鍵后,八個(gè)燈閃爍,時(shí)間間隔為 2s;
這段程序?yàn)槭裁礇]法實(shí)現(xiàn)上面的要求。。仿真圖在下面。


單片機(jī)源程序如下:
#include <REGX51.H>

int count0=0,count1=0,num0=0,num1=0;
int temp=1;

void delay()
{
        unsigned char i,j;
        for(i=0;i<20;i++){
                for(j=0;j<120;j++);
        }
}
void inittimer0()
{
        TMOD=0x01;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        TR0=1;
        EA=1;
        ET0=1;
}
void button_scan(){
        delay();
        if(P1!=0) temp=0;
        while(P1==0);
}
void main(){
        inittimer0();
        while(1){
                button_scan();
                if(temp==1){
                        P2_0=num0;
                }
                else{
                        P2=num1;
                }
        }
}
void timer0_isr() interrupt 1
{
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        count0++;
        count1++;
        if(count0==20&&temp){
                num0=num0?0:1;
                count0=0;
        }
        else if(count1==40&&!temp){
                num1=~num1;
                count1=0;
        }
}



作者: lkc8210    時(shí)間: 2022-11-23 09:04

比較一下分別

作者: luogu34    時(shí)間: 2022-11-23 13:32
lkc8210 發(fā)表于 2022-11-23 09:04
比較一下分別

太感謝你了大佬腦子太笨了

-24c1f5902144c618.gif (10.54 KB, 下載次數(shù): 68)

-24c1f5902144c618.gif





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1