![]() |
發(fā)布時(shí)間: 2019-1-17 22:00
正文摘要:前幾天在論壇得到許多大佬的指導(dǎo)成功驅(qū)動(dòng)了36個(gè)LED燈。目前還是很懵逼,12列全部高電平也就是LED1-12為全為1,y=0xfff; 第一行L1置低,第二第三行L2-L3置高x=0x6;第一行的綠燈全亮。如何實(shí)現(xiàn),第一行的綠 ... |
wulin 發(fā)表于 2019-1-18 11:28 非常感謝!無(wú)以言表我試試,雖然現(xiàn)在還不是很理解 |
![]() |
真心感謝你們![]() |
weidoit 發(fā)表于 2019-1-18 12:05 謝謝大神!我試試 |
yzwzfyz 發(fā)表于 2019-1-18 08:20 動(dòng)態(tài)顯示確實(shí)讓我很懵逼,6ms切換一行一直循環(huán)人眼看到的就是全亮了啊。1號(hào)燈滅的同時(shí)25號(hào)燈亮,逐個(gè)移位過(guò)去,靜態(tài)和動(dòng)態(tài)都不能實(shí)現(xiàn) |
給你寫一個(gè)示例程序,因?yàn)橛肔ED仿真視覺不好,用LED點(diǎn)陣屏代替演示。
![]() #include <reg51.h> #define uint unsigned int #define uchar unsigned char sbit code0 =P2^0;//列 sbit code1 =P2^1; sbit code2 =P2^2; sbit code3 =P2^3; sbit code4 =P2^4; sbit code5 =P2^5; sbit code6 =P2^6; sbit code7 =P2^7; sbit code8 =P0^0; sbit code9 =P0^1; sbit code10=P0^2; sbit code11=P0^3; sbit Column0=P1^0;//行 sbit Column1=P1^1; sbit Column2=P1^2; uint code table[]={0x001,0x002,0x004,0x008,0x010,0x020,0x040,0x080,0x100,0x200,0x400,0x800,0x0fff}; uint num=0x0000; uchar i,j,k; bit a; void PX(uint i) //寫入12位數(shù)據(jù) { code0 =i&0x01;i>>=1; code1 =i&0x01;i>>=1; code2 =i&0x01;i>>=1; code3 =i&0x01;i>>=1; code4 =i&0x01;i>>=1; code5 =i&0x01;i>>=1; code6 =i&0x01;i>>=1; code7 =i&0x01;i>>=1; code8 =i&0x01;i>>=1; code9 =i&0x01;i>>=1; code10=i&0x01;i>>=1; code11=i&0x01; } void Timer0Init(void) //1毫秒@12.000MHz { TMOD |= 0x01; //設(shè)置定時(shí)器模式 TL0 = 0x18; //設(shè)置定時(shí)初值 TH0 = 0xFC; //設(shè)置定時(shí)初值 TF0 = 0; //清除TF0標(biāo)志 TR0 = 1; //定時(shí)器0開始計(jì)時(shí) EA=1; //開總中斷 ET0=1; //開T0中斷 } void main() { Timer0Init(); PX(0x0000); while(1) { if(a==1) { a=0; switch(j)//動(dòng)態(tài)逐行顯示 { case 0: P1&=0xf8;//P1低3位清0 P1|=0x01;//P1低3位賦值 num&=0xf000;//num低12位清0 num|=table;//num低12位賦值 PX(num);j++;//num值寫入列端口 break; case 1: P1&=0xf8; P1|=0x02; num&=0xf000; num|=table; PX(num);j++; break; case 2: P1&=0xf8; P1|=0x04; num&=0xf000; num|=table; PX(num);j=0; break; } if(++k==3)//流水燈 { k=0; i++; if(i==12) i=0; } } } } void timer0() interrupt 1 { TL0 = 0x18; //設(shè)置定時(shí)初值 TH0 = 0xFC; //設(shè)置定時(shí)初值 a=1; } |
你的空間想力不夠啊。 建議: 每6ms切換一行顯示,一直永遠(yuǎn)循環(huán)。試試吧。 |
貌似?當(dāng)時(shí)誰(shuí)提出來(lái)點(diǎn)亮幾十個(gè)LED時(shí)我說(shuō)用點(diǎn)陣做,但是,你卻沒有按點(diǎn)陣的思路來(lái)操作!如果是按點(diǎn)陣方式來(lái)做應(yīng)該是8個(gè)I/O取縱,其于取橫!這樣你要點(diǎn)一個(gè)燈時(shí)用取模軟件直接取模就得到數(shù)組值就OK的,也不用復(fù)雜的計(jì)算。這就同點(diǎn)陣點(diǎn)一個(gè)燈是一樣的。 |
參與人數(shù) 1 | 黑幣 +15 | 收起 理由 |
---|---|---|
![]() | + 15 | 回帖助人的獎(jiǎng)勵(lì)! |
Powered by 單片機(jī)教程網(wǎng)