#include "reg52.h" #define SMG P0 sbit key1 = P3^1; sbit key2 = P3^0; sbit key3 = P3^2; sbit key4 = P3^4; sbit key5 = P3^5; typedef unsigned int u16; typedef unsigned char u8; u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; u16 num1,num2,result1,result2; void delay() { u16 i,j; for(i=0;i<255;i++) for(j=0;j<255;j++); } void shuzhi(u16 *num) { if(key1 == 0) { delay(); SMG=~smgduan[1]; *num=1; } else if(key2 == 0) { delay(); SMG=~smgduan[2]; *num=2; } else if(key3 == 0) { delay(); SMG=~smgduan[3]; *num=3; } } void fuhao() { if(key4==0) { delay(); result1=num1*num2; SMG=~smgduan[result1]; } else if(key5==0) { delay(); result2=num1+num2; SMG=~smgduan[result2]; } } int main() { while(1) { shuzi(&num1); shuzi(&num2); fuhao(); } return 0; }修正代码
时间: 2024-04-06 12:28:45 浏览: 48
# include "reg52.h"
# define SMG P0
sbit key1 = P3^1;
sbit key2 = P3^0;
sbit key3 = P3^2;
sbit key4 = P3^4;
sbit key5 = P3^5;
typedef unsigned int u16;
typedef unsigned char u8;
u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
u16 num1,num2,result1,result2;
void delay()
{
u16 i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
void shuzi(u16 *num)
{
if(key1 == 0) {
delay();
SMG = ~smgduan[1];
*num = 1;
}
else if(key2 == 0) {
delay();
SMG = ~smgduan[2];
*num = 2;
}
else if(key3 == 0) {
delay();
SMG = ~smgduan[3];
*num = 3;
}
}
void fuhao()
{
if(key4 == 0) {
delay();
result1 = num1 * num2;
SMG = ~smgduan[result1];
}
else if(key5 == 0) {
delay();
result2 = num1 + num2;
SMG = ~smgduan[result2];
}
}
int main()
{
while(1) {
shuzi(&num1);
shuzi(&num2);
fuhao();
}
return 0;
}
阅读全文