旋轉(zhuǎn)LED燈原理和應用
這是用此思路編的流水燈C51程序
#include
code unsigned char led[]={0x01,
0x02,0x04,0x08,0x10,0x20,0x40,0x80};

0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void main(void)
{
unsigned int i,j;
while(1)
{
for(j=0;j<8;j++){
P0=~led[j];
for(i=3000;i>0;i--);
}
}
}
運行看一下,結(jié)果與我們的第一個程序效果是一樣的,但這個程序的優(yōu)勢在于我們可以按我們的要求,改變數(shù)組中的數(shù)據(jù)來驅(qū)動端口上的LED,達到我們預期的顯示效果。這可以說是流水燈的萬能程序。這樣我們邁出了第一步。
再來看如何產(chǎn)生需要的圖案。
現(xiàn)在我們讓LED顯示數(shù)字12為例,我們先作一個表。
0 1 0 0 1 1 1 1 低四位
1 1 0 0 1 0 0 1
0 1 0 0 0 0 0 1
0 1 0 0 0 0 1 0
0 1 0 0 0 1 0 0 高四位
0 1 0 0 1 0 0 0
0 1 0 0 1 0 0 0
1 1 1 0 1 1 1 1
0 1 0 0 1 1 1 1 低四位
1 1 0 0 1 0 0 1
0 1 0 0 0 0 0 1
0 1 0 0 0 0 1 0
0 1 0 0 0 1 0 0 高四位
0 1 0 0 1 0 0 0
0 1 0 0 1 0 0 0
1 1 1 0 1 1 1 1
從下到上將每列看成是一個16進制數(shù),我得到8個16進制數(shù)
10000010=0x82
11111111=0xff
10000000=0x80
00000000=0x00
11100011=0xe3
10010001=0x91
10001001=0x89
10000111=0x87
這樣我們得到了我們想要的一組掃描碼{0x82,0xff,0x80,0x00,0xe3,0x91,0x89,0x87}
將前一程序的數(shù)組數(shù)據(jù)改成我們得到的掃描碼,我們得到新的C51程序
#include
code unsigned char led[]={0x82,0xff,0x80,0x00,0xe3,0x91,0x89,0x87};
void main(void)
{
unsigned int i,j;
while(1)
{
for(j=0;j<8;j++){
P0=~led[j];
for(i=600;i>0;i--);
}
for(i=8000;i>0;i--);
for(i=8000;i>0;i--);
}
}
編譯下載后,將運行進的電路板來回晃晃看……,哈,“12”已隱約出現(xiàn)在眼前。

是不是成功離我們已經(jīng)不遠了。

是不是成功離我們已經(jīng)不遠了。
最后是發(fā)揮部分。接著要做的事就是解決如何讓這些LED運動,如何檢測運行時的開始和結(jié)束,如何給運動著的系統(tǒng)供電,如何控制運動著的系統(tǒng)….等等。不同的解決方案造就各具特色的LED旋轉(zhuǎn)屏。
用上面的辦法對一些簡單圖案還能行,當遇到LED個數(shù)多或圖文復雜時,用這樣直接取碼的工作量就會很大,這就需要專門軟件,根據(jù)顯示的字符和圖案自動生成掃描碼。好在網(wǎng)上有不少這類軟件可免費下載,免去了手工取碼之苦。
看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
評論