熱門: 51單片機(jī) | 24小時(shí)必答區(qū) | 單片機(jī)教程 | 單片機(jī)DIY制作 | STM32 | Cortex M3 | 模數(shù)電子 | 電子DIY制作 | 音響/功放 | 拆機(jī)樂園 | Arduino | 嵌入式OS | 程序設(shè)計(jì)
|
發(fā)布時(shí)間: 2019-2-17 11:29
正文摘要:很喜歡51黑論壇,論壇里面有很多熱心的大佬,這是我見過的最有愛的論壇,沒有之一。每一位回貼的網(wǎng)友都是優(yōu)秀的老師,像我這樣的小白在這里能學(xué)到很多東西。 最近想用數(shù)組跑一個(gè)流水燈,LED的引腳是隨便接的,考慮 ... |
wulin 發(fā)表于 2019-2-17 20:36 看了你的例程,我在我的程序LED()驅(qū)動(dòng)函數(shù)里面加了一個(gè)參數(shù)y,在main函數(shù)的for循環(huán)里面調(diào)用了這個(gè)帶參數(shù)的驅(qū)動(dòng)函數(shù)LED(y),就美妙的跑起來了,跪謝大佬用心給我仿真,祝新年快樂!萬事大吉! ![]() |
| 頂頂頂!還有沒有其它好方法實(shí)現(xiàn)啊,這種引腳分散的怎么用數(shù)組來操作哦? |
| 你的大循環(huán)沒寫 |
你這樣寫LED驅(qū)動(dòng)函數(shù)不行,改成這樣就可以了。
#include<reg51.h> #define uint unsigned int #define uchar unsigned char sbit LED1 = P3^5; sbit LED2 = P1^7; sbit LED3 = P1^6; sbit LED4 = P1^5; sbit LED5 = P1^4; sbit LED6 = P1^3; sbit LED7 = P3^7; sbit LED8 = P0^0; sbit LED9 = P1^2; sbit LED10 = P1^0; sbit LED11 = P3^2; sbit LED12 = P1^1; //全局變量// uint y; //定義LED數(shù)組// uint leddata[]={0xfffe,0xfffd,0xfffb,0xfff7,0xffef,0xffdf,0xffbf,0xff7f,0xfeff,0xfdff,0xfbff,0xf7ff}; //延時(shí)函數(shù)// delay(uint t) { uint i,j; for(i=t;i>0;i--) for(j=112;j>0;j--); } //LED驅(qū)動(dòng)函數(shù)// void LED(uint i)//寫入12位數(shù)據(jù) { LED1=i&0x01;i>>=1; LED2=i&0x01;i>>=1; LED3=i&0x01;i>>=1; LED4=i&0x01;i>>=1; LED5=i&0x01;i>>=1; LED6=i&0x01;i>>=1; LED7=i&0x01;i>>=1; LED8=i&0x01;i>>=1; LED9=i&0x01;i>>=1; LED10=i&0x01;i>>=1; LED11=i&0x01;i>>=1; LED12=i&0x01; } void main() { uchar j=0; while(1) { y=leddata[j]; LED(y); j++; j%=12; delay(500); } } |
| 參與人數(shù) 2 | 黑幣 +18 | 收起 理由 |
|---|---|---|
|
| + 8 | 回帖助人的獎(jiǎng)勵(lì)! |
|
| + 10 | 跪謝大佬!按照你的例程我找到了我程序問題. |
Powered by 單片機(jī)教程網(wǎng)