#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++); } int main() { while(1) { void shuzhi(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; } return num; } if(key4==0) { delay(); result1=num1*num2; SMG=~smgduan[result1]; } else if(key5==0) { delay(); result1=num1+num2; SMG=~smgduan[result1]; } } return 0; }修改为正确代码
时间: 2024-04-06 07:29:50 浏览: 78
基于单片机是电梯.PWI
#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<1000;i++)
for(j=0;j<1000;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;
}
}
int main()
{
while(1)
{
shuzhi(&num1);
shuzhi(&num2);
if(key4==0)
{
delay();
result1=num1*num2;
SMG=~smgduan[result1];
}
else if(key5==0)
{
delay();
result1=num1+num2;
SMG=~smgduan[result1];
}
}
return 0;
}
阅读全文