標(biāo)題: 單片機(jī)內(nèi)部輸出彩燈 [打印本頁(yè)]

作者: XCYYLX    時(shí)間: 2022-3-20 15:41
標(biāo)題: 單片機(jī)內(nèi)部輸出彩燈
#include<reg51.h>
#define uchar unsigned char
uchar code play_rom[6]={0x55,0xaa,0x0f,0xf0,0x99,0x66};

void delay(void)
{
        uchar i,j,k;
        for(i=10; i>0; i--) //外循環(huán)5次每次約0.1s,共延時(shí)1s
        {
                for(j=200; j>0; j--) //循環(huán)200次,每次約0.5ms共延時(shí)0.1
                {
                        for(k=250; k>0; k--) //內(nèi)部循環(huán)250次,延時(shí)約250*2us=0.5ms
                        {
                                {;}
                        }
                }
        }
}

void main(void)
{
        uchar i=0;
        while(1)
        {
                for(i=0; i<6; i++)
                {
                        P1=play_rom[i]; //P1輸出數(shù)組第i號(hào)元素
                           delay();
                }
        }
}






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