標(biāo)題: 51單片機輸出彩燈,隨機變化 [打印本頁]

作者: XCYYLX    時間: 2022-8-31 15:21
標(biāo)題: 51單片機輸出彩燈,隨機變化
#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,共延時1s
        {
                for(j=200; j>0; j--) //循環(huán)200次,每次約0.5ms共延時0.1
                {
                        for(k=250; k>0; k--) //內(nèi)部循環(huán)250次,延時約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號元素
                           delay();
                }
        }
}


51hei圖片20220831152037.png (70.77 KB, 下載次數(shù): 116)

51hei圖片20220831152037.png

作者: sonique0371    時間: 2022-9-1 08:07
理論上可以無限擴充彩燈樣式。
作者: pcbboy    時間: 2022-9-6 16:10
產(chǎn)生隨機數(shù)就可以無限隨機了。
作者: STC莊偉    時間: 2022-9-7 17:06
各種燈,STC-ISP提供范例程序,可以直接復(fù)制
STC-ISP軟件V6.90J版http://www.stcmcudata.com/STCISP/stc-isp-15xx-v6.90J.zip





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