Created
February 10, 2012 13:36
-
-
Save mingtsay/1789670 to your computer and use it in GitHub Desktop.
LED控制
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <AT89X51.H> | |
#include <stdio.h> | |
void delay(int ms); | |
main() | |
{ | |
int i = 0; | |
int btnL, btnR; | |
//初始化 | |
P0 = 0xFF; | |
P1 = 0xFF; | |
P2 = 0xFF; | |
P3 = 0xFF; | |
while(1) | |
{ | |
P0 = 0xFF; //清除狀態 | |
delay(10); //延遲讓電力可回傳 | |
btnL = 0; | |
btnR = 0; | |
if(!(P0 & 0x01)) btnL = 1; | |
if(!(P0 & 0x02)) btnR = 1; | |
if(i >= 20) i = 0; //圖像迴圈 | |
if(!btnL && !btnR) | |
{ | |
P2 = 0xFF; | |
switch(i % 5) | |
{ | |
case 0: | |
P1 = 0xFE; | |
break; | |
case 1: | |
P1 = 0xFD; | |
break; | |
case 2: | |
P1 = 0xFB; | |
break; | |
case 3: | |
P1 = 0xF7; | |
break; | |
case 4: | |
P1 = 0xEF; | |
break; | |
} | |
} | |
if(btnL && !btnR) | |
{ | |
switch(i % 4) | |
{ | |
case 0: //0 | |
P1 = 0xBF; | |
P2 = 0x9F; | |
break; | |
case 1: //0+1 | |
P1 = 0x9F; | |
P2 = 0x91; | |
break; | |
case 2: //1 | |
P1 = 0xDF; | |
P2 = 0xF1; | |
break; | |
case 3: //Clear | |
P1 = 0xFF; | |
P2 = 0xFF; | |
break; | |
} | |
} | |
if(btnR && !btnL) | |
{ | |
switch(i % 4) | |
{ | |
case 0: //0 | |
P1 = 0xDF; | |
P2 = 0xFC; | |
break; | |
case 1: //0+1 | |
P1 = 0x9F; | |
P2 = 0xC4; | |
break; | |
case 2: //1 | |
P1 = 0xBF; | |
P2 = 0xC7; | |
break; | |
case 3: //Clear | |
P1 = 0xFF; | |
P2 = 0xFF; | |
break; | |
} | |
} | |
if(btnL && btnR) | |
{ | |
switch(i % 2) | |
{ | |
case 0: | |
P1 = 0xFF; | |
P2 = 0xFF; | |
break; | |
case 1: | |
P1 = 0x80; | |
P2 = 0x80; | |
break; | |
} | |
} | |
++i; //圖像推進 | |
delay(4900); //圖像延遲 | |
} | |
} | |
void delay(int ms) | |
{ | |
int i, j; | |
for(i = 0; i < ms; ++i) | |
{ | |
for(j = 0; j < 109; ++j) | |
{ | |
; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:10000300E4F508F5097580FF7590FF75A0FF75B0DD | |
:10001300FF7580FF7F0A7E001201DDE4F50AF50B10 | |
:10002300FBFAE58020E006750A00750B01E58020E8 | |
:10003300E1047A007B01C3E5099414E50864809424 | |
:10004300804005E4F508F509E50B450A703CEB4AE9 | |
:10005300703875A0FFAE08AF09FC7D05120152ECA4 | |
:100063007028ED14601214601414601614601824C0 | |
:100073000470177590FE80127590FD800D7590FBCE | |
:1000830080087590F780037590EFE50B450A603D96 | |
:10009300EB4A7039AE08AF09FC7D04120152EC70D3 | |
:1000A3002CED14601214601714601C2403701E7569 | |
:1000B30090BF75A09F801675909F75A091800E7557 | |
:1000C30090DF75A0F180067590FF75A0FFEB4A6085 | |
:1000D3003FE50B450A7039AE08AF09FC7D041201F8 | |
:1000E30052EC702CED14601214601714601C24037E | |
:1000F300701E7590DF75A0FC801675909F75A0C467 | |
:10010300800E7590BF75A0C780067590FF75A0FF20 | |
:10011300E50B450A6027EB4A6023AE08AF097C0074 | |
:100123007D02120152EC7015ED14600B04700E7514 | |
:1001330090FF75A0FF800675908075A0800509E586 | |
:0F01430009700205087F247E131201DD020014EB | |
:1001DD00E4FDFCC3ED9FEE6480F8EC64809850154F | |
:1001ED00E4FBFA0BBB00010AEB646D4A70F50DBD23 | |
:0501FD0000010C80DE92 | |
:0102020022D9 | |
:03000000020203F6 | |
:0C020300787FE4F6D8FD75810B02000343 | |
:10015200C2D5EC30E709B2D5E4C39DFDE49CFCEEC8 | |
:1001620030E715B2D5E4C39FFFE49EFE120188C3B7 | |
:10017200E49DFDE49CFC800312018830D507C3E4B2 | |
:060182009FFFE49EFE2237 | |
:10018800BC000BBE0029EF8DF084FFADF022E4CC5B | |
:10019800F875F008EF2FFFEE33FEEC33FCEE9DEC24 | |
:1001A800984005FCEE9DFE0FD5F0E9E4CEFD22ED6A | |
:1001B800F8F5F0EE8420D21CFEADF075F008EF2FB4 | |
:1001C800FFED33FD4007985006D5F0F222C398FDA5 | |
:0501D8000FD5F0EA2242 | |
:00000001FF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment