|
本帖最后由 ION_i 于 2022-3-28 18:07 編輯
這個是后來改的,改過之后還是之前的效果。- #include <reg51.h>
- #define uchar unsigned char
- //Delay
- void delay(){
- uchar i,j;
- for(i=0;i<255;i++)
- for(j=0;j<255;j++);
- }
- char GetKey(){
- char key;
- key = ~P2;
- return key;
- }
- //P2=1,P0 All On.
- void P0_All_On(){
- P0 = 0x00;
- }
- //P1 unidirectional led
- void P1_Unidirectional_Led(){
-
- }
- //P2=0xfd,P1 All On.
- void P1_All_On(){
- while(1){
-
- P1 = 0x00;
- }
- }
- void LedDispose(char key){
- P1 = 0xff;
- P0 = 0xff;
- if(key == 0x01)
- P0_All_On();
- if(key == 0x02)
- P1_All_On();
- }
- void main(){
- char key;
- P2 = 0xff;
- key = ~P2;
- while(1)
- {
- key = GetKey();
- // state = ~P2;
- if(key != 0x00)
- {
- LedDispose(key);
- }else{
- P1 = 0xff;
- P0 = 0xff;
- }
- }
- }
復制代碼
|
|