|
按鍵控制彩燈的仿真電路圖:
0.png (30.84 KB, 下載次數(shù): 74)
下載附件
2017-4-2 01:25 上傳
0.png (54.88 KB, 下載次數(shù): 91)
下載附件
2017-4-2 01:24 上傳
單片機(jī)源程序:
- /**********************劉金森 1440302103 電子信息工程*********************/
- #include<reg51.h> //51單片機(jī)頭文件
- #include<intrins.h> //包含crol(循環(huán)左移)函數(shù)所在的頭文件
- #define uint unsigned int
- void delay(int z); //聲明子函數(shù)
- unsigned char temp; //定義一個(gè)變量,用來給P1口賦值
- int i,j;
- sbit Key0=P0^0;
- sbit Key1=P0^1;
- sbit Key2=P0^2; //定義三個(gè)按鍵
- /**************按鍵控制函數(shù)************/
- uint key()
- {
- uint temp;
- Key0=0;
- Key1=0;
- Key2=0;
- if(Key0==1)
- {
- delay(500); //延時(shí)500毫秒,去按鍵時(shí)的抖動(dòng)
- if(Key0==1)
- {
- temp=0xfc; //1111 1100B 只有兩盞燈亮
- P1=temp;
- while(Key0)
- {
- delay(500);
- temp=_crol_(temp,1); //將temp循環(huán)左移一位后再賦給temp
- P1=temp; //將移位后的值賦給P1口,從低位到高位逐個(gè)點(diǎn)亮發(fā)光二極管
- }
- }
-
- }
- else if(Key1==1)
- {
- delay(500); //延時(shí)500毫秒,去按鍵時(shí)的抖動(dòng)
- if(Key1==1)
- {
- temp=0x10; //0001 0000B 只有一盞燈不亮
- P1=temp;
- while(Key1)
- {
- delay(500);
- temp=_cror_(temp,1); //將temp循環(huán)左移一位后再賦給temp
- P1=temp; //將移位后的值賦給P1口,從低位到高位逐個(gè)點(diǎn)亮發(fā)光二極管
- }
- }
-
- }
- else if(Key2==1)
- {
- delay(500); //延時(shí)500毫秒,去按鍵時(shí)的抖動(dòng)
- if(Key2==1)
- {
- temp=0xfd; //1111 1101B 只有一盞燈亮
- P1=temp;
- while(Key2)
- {
- delay(500);
- temp=_cror_(temp,1); //將temp循環(huán)左移一位后再賦給temp
- P1=temp; //將移位后的值賦給P1口,從低位到高位逐個(gè)點(diǎn)亮發(fā)光二極管
- }
- }
-
- }
-
-
- return temp;
- }
- void delay(int z) //延時(shí)z毫秒
- {
- unsigned int x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- /*****************主函數(shù)*************/
- void main()
- {
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
下載:
test1.zip
(73.8 KB, 下載次數(shù): 63)
2017-3-27 01:20 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|