多余語句全部注釋掉,只做少量修改,樓主只要逐條語句對比就能明白錯在哪里。
無標題.jpg (184.91 KB, 下載次數: 13)
下載附件
2020-5-23 07:14 上傳
- #include "reg52.h" //此文件中定義了單片機的一些特殊功能寄存器
- typedef unsigned int u16; //對數據類型進行聲明定義
- typedef unsigned char u8;
- char num;
- char temp;
- u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};//顯示0~F的值
- u8 keyvalue;
- void delay(u16 i)
- {
- while(i--);
- }
- void main()
- {
- num=17;
- // P2=0;
- while(1)
- {
- P1=0xfe;
- temp=P1;
- // temp=temp&0xf0;
- if(temp!=0xfe)
- {
- delay(500);
- temp=P1; //
- // temp= temp&0xf0;
- // while(temp!=0xf0)
- // {
- // temp=P1; //此句非常重要
- switch(temp)
- {
- case 0xee : num=1;break;
- case 0xde : num=2;break;
- case 0xbe : num=3;break;
- case 0x7e : num=4;break;
- }
- while(P1!=0xfe); //松手確定
- // {
- // temp=P1;
- // temp=temp&0xf0;
- // }
- // P0=0;
- // P2=smgduan[num];
- // }
- }
- P1=0xfd;
- temp=P1;
- // temp=temp&0xf0;
- if(temp!=0xfd)
- {
- delay(500);
- temp=P1; //
- // temp= temp&0xf0;
- // while(temp!=0xf0)
- // {
- // temp=P1; //此句非常重要
- switch(temp)
- {
- case 0xed : num=5;break;
- case 0xdd : num=6;break;
- case 0xbd : num=7;break;
- case 0x7d : num=8;break;
- }
- while(P1!=0xfd);
- // {
- // temp=P1;
- // temp=temp&0xf0;
- // }
- // P0=0;
- // P2=smgduan[num];
- // }
- }
- P1=0xfb;
- temp=P1;
- // temp=temp&0xf0;
- if(temp!=0xfb)
- {
- delay(500);
- temp=P1; //
- // temp= temp&0xf0;
- // while(temp!=0xf0)
- // {
- // temp=P1; //此句非常重要
- switch(temp)
- {
- case 0xeb : num=9;break;
- case 0xdb : num=10;break;
- case 0xbb : num=11;break;
- case 0x7b : num=12;break;
- }
- while(P1!=0xfb);
- // {
- // temp=P1;
- // temp=temp&0xf0;
- // }
- // P0=0;
- // P2=smgduan[num];
- // }
- }
- P1=0xf7;
- temp=P1;
- // temp=temp&0xf0;
- if(temp!=0xf7)
- {
- delay(500);
- temp=P1; //
- // temp=temp&0xf0;
- // while(temp!=0xf0)
- // {
- // temp=P1; //此句非常重要
- switch(temp)
- {
- case 0xe7 : num=13;break;
- case 0xd7 : num=14;break;
- case 0xb7 : num=15;break;
- case 0x77 : num=16;break;
- }
- while(P1!=0xf7);
- // {
- // temp=P1;
- // temp=temp&0xf0;
- // }
- // P0=0;
- // P2=smgduan[num];
- // }
- }
- P0=0;
- P2=smgduan[num-1];
- }
- }
復制代碼
|