用數(shù)組書(shū)寫花式流水燈
單片機(jī)源程序如下:- #include <reg51.h> //MCS-51系列單片機(jī)頭文件
- unsigned char tab[]=
- {
- 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,
- 0xff,0x7e,0xbd,0xdb,0xe7,0xdb,0xbd,0x7e,0xff
- }; //聲明數(shù)組tab并賦值(共25個(gè)元素)
- delay() //延時(shí)子函數(shù)
- {
- unsigned int i;
- for (i=0;i<30000;i++); //用for 語(yǔ)句實(shí)現(xiàn)30000次循環(huán)
- }
- int main(void) //主程序main函數(shù)
- {
- unsigned char j;
- while(1) //在主程序中設(shè)置死循環(huán)程序
- {
- for (j=0;j<25;j++) //25次循環(huán)語(yǔ)句
- {
- P2=tab[j]; //數(shù)組tab中下標(biāo)為j的元素賦給P2口
- delay(); //調(diào)用延時(shí)子函數(shù)
- }
- }
- }
復(fù)制代碼
Proteus7.8版本的仿真下載:
花式流水燈.zip
(9.3 KB, 下載次數(shù): 23)
2024-4-2 10:35 上傳
點(diǎn)擊文件名下載附件
|