|
下面是我寫(xiě)的流水燈程序,左移和右移,想添加一個(gè)延時(shí)可控按鈕。各位大神怎么添加才好
單片機(jī)源碼:
- #include<reg51.h> //51單片機(jī)頭文件
- #include <intrins.h> //包含有左右循環(huán)移位子函數(shù)的庫(kù)
- #define uint unsigned int //宏定義
- #define uchar unsigned char //宏定義
- void delay(uint time) //延時(shí)子程序
- {
- unsigned int j=0;
- for(;time>0;time--)
- {
- for(j=0;j<125;j++)
- {;}
- }
- }
- void main() //主函數(shù)
- {
- uchar a,i,u,k;
- while(1) //大循環(huán)
- {
- for(u=0;u<3;u++)
- {
- a=0xfe; //賦初值
- for(i=0;i<8;i++) //左移
- {
- P0=a; //點(diǎn)亮小燈
-
- a=_crol_(a,1); //將a變量循環(huán)左移一位
- delay(500);//延時(shí)0.5秒
- }
- }
- for(k=0;k<2;k++)
- {
- a=0x7f;
- for(i=0;i<8;i++) //右移
- {
- P0=a; //點(diǎn)亮小燈
-
- a=_cror_(a,1); //將a變量循環(huán)右移一位
- delay(500);
- }
- }
- }
- }
復(fù)制代碼
|
|