求助程序和电路都在下面,怎么调试蜂鸣器都没反应。
- #include<reg52.h>
- #include<string.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- unsigned long count;
- sbit key1=P3^4;
- sbit key2=P3^5;
- sbit dula=P2^6;
- sbit wela=P2^7;
- sbit beep=P1^4;
- uchar code table[]={
- 0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,
- 0x39,0x5e,0x79,0x71
- };
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--);
- for(y=110;y>0;y--);
- }
- void display()
- {
- int a,b,c,d,e,f;
- a = count/100000%10; //十万
- b = count/10000%10; //万
- c = count/1000%10; //千
- d = count/100%10; //百
- e = count/10%10; //十
- f = count/1%10; //个
- P0=0xfe; //第一个LED
- wela=1;
- wela=0;
- P0=table[a]; //十万位数
- dula=1;
- dula=0;
- P0=0xff; //消隐
- delay(1);
- P0=0xfd; //第二个LED
- wela=1;
- wela=0;
- P0=table[b]; // 万位位数
- dula=1;
- dula=0;
- P0=0xff;
- delay(1);
- P0=0xfb; //第三个LED
- wela=1;
- wela=0;
-
- P0=table[c]; // 千位数
- dula=1;
- dula=0;
- P0=0xff;
- delay(1);
- P0=0xf7; //第四个LED
- wela=1;
- wela=0;
-
- P0=table[d]; // 百位数
- dula=1;
- dula=0;
- P0=0xff;
- delay(1);
- P0=0xef; //第五个LED
- wela=1;
- wela=0;
-
- P0=table[e]; // 十位数
- dula=1;
- dula=0;
- P0=0xff;
- delay(1);
-
- P0=0xdf; //第六个LED
- wela=1;
- wela=0;
- P0=table[f]; // 个位数
- dula=1;
- dula=0;
- delay(1);
-
- }
- void key()
- {
- if(key1==0)
- {
- delay(7);
- if (key1==0)
- {
- count++;
- }
- while(!key1)
- {
- display();
- }
- delay(1);
- while(!key1)
- {
- display();
- }
- }
-
- if(key2==0)
- {
- count=0;
- }
- }
- void main()
- {
- P3=0xff;
- P0=0xff;
- beep=1;
- while(1)
- {
- key();
- display();
- if(count>=999999)
- {
- count=0;
- beep=0;
- delay(50);
- beep=1;
- }
- }
- }
复制代码
|