|
循環(huán)點(diǎn)亮led燈
單片機(jī)源程序如下:
- #include <reg52.h>
- #include <intrins.h>//這個就是循環(huán)移位的頭文件
- #define uchar unsigned char//這個應(yīng)該知道的吧
- #define uint unsigned int
- void DelayMS(uint x)//延時(shí)函數(shù)
- {
- uchar t;
- while(x--)
- {
- for(t=120;t>0;t--);
- }
- }
- void main()
- {
- uchar i;
- P2=0x01;//給P2管腳賦值,P2連的是發(fā)光二極管
- while(1)
- {
- for(i=7;i>3;i--)//移7次
- {
- P2=_crol_(P2,1);//循環(huán)左移,每次移一位
- DelayMS(150);//延時(shí)一下,這樣人眼就能看出來,不延時(shí)的話人眼不能識別,機(jī)器處理的太快
- }
- for(i=7;i>0;i--)
- {
- P2=_cror_(P2,2);//循環(huán)右移,每次2位
- DelayMS(150);
- }
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
新建 Microsoft Word 文檔 (3).docx
(12.46 KB, 下載次數(shù): 10)
2018-4-26 10:45 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|