資源簡介
基于proteus的計算器,c語言編程,設(shè)計的一個在proteus上仿真的計算器

代碼片段和文件信息
#include?
#define?uchar?unsigned?char
#define?uint?unsigned?int ?
uchar?code?wei[]?=?{0x01?0x02?0x04?0x08};
uchar?code?table[]?=?{0xc0?0xf9?0xa4?0xb0?0x99
0x92?0x82?0xf8?0x80?0x90?0xff
0x83?0xc6?0xa1?0x86};??//+??-??*??/???
uchar?dbuf[4]?=?{10?10?10?10};
uchar?operand1[3]?operand2[3];??
uint?value1?value2?value;
uchar?cut1?=?0?cut2?=?0?bool?=?0;
??
void?delay(uint?z)
{
uint?xy;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar?keyscan()
{
uchar?temp?temp1?temp2?key;
P1?=?0x0f;
if(P1?!=?0x0f)
delay(100);
if(P1?!=?0x0f)
{
temp1?=?P1;
P1?=?temp1?|?0xf0;
temp2?=?P1?&?0xf0;
P1?=?0x0f;
}?while(?P1?!=?0x0f);
temp?=?temp1?+?temp2;
switch(temp)
{
case?0xbe?:?key?=?1;
break;
case?0xbd?:?key?=?2;
break;
case?0xbb?:?key?=?3;
break;
case?0xde?:?key?=?4;
break;
case?0xdd?:?key?=?5;
break;
case?0xdb?:?key?=?6;
break;
case?0xee?:?key?=?7;
break;
case?0xed?:?key?=?8;
break;
case?0xeb?:?key?=?9;
break;
case?0x7d?:?key?=?0;
break;
case?0x77?:?key?=?‘+‘;
break;
case?0xb7?:?key?=?‘-‘;
break;
case?0xd7?:?key?=?‘*‘;
break;
case?0xe7?:?key?=?‘/‘;
break;
case?0x7b?:?key?=?‘=‘;
break;
case?0x7e?:?key?=?‘$‘;
break;
default???:?key?=?‘#‘;
break;
}
return?key;
}
uint?compute(uint?va1uint?va2uchar?optor)
{
uint?value;
switch(optor)
{
case?‘+‘?:?value?=?va1+va2; break;
case?‘-‘?:?value?=?va1-va2; break;
case?‘*‘?:?value?=?va1*va2; break;
case?‘/‘?:?value?=?va1/va2; break;
default?:?value?=?va1;??break;
}
return?value;
}
void?buf(uint?val)
{
uchar?i;
if(val?==?0)
{
dbuf[3]?=?0;
i?=?2;
}
else
for(i?=?3;?val?>?0?&&?i?>=?0;?i--)
{
dbuf[i]?=?val?%?10;
val?/=?10;
}
for(?;?i?>?0;?i--)
dbuf[i]?=?10;
}
void?disp(void)
{
uchar?n;
????for(n=0;n<4;n++)
????{?
P2=wei[n];
P0=table[dbuf[n]];
delay(10);
????}
}
//void?error()
//{
// uchar?n;
//????for(n=0;n<4;n++)
//????{?
// P2=wei[n];
// P0?=?0x00;
// delay(20);
// }
//}
void?init()
{
uchar?i;
buf(0);???????????????????????????
disp();
value?=?0;
cut1?=?cut2?=?0;
bool?=?0;
for(i?=?0;i?3;i++)
{
operand1[i]?=?0;
operand2[i]?=?0;
}???????
}
void?main()
{ ??
uchar?ckey?operator;???? ?????????????? ??????????????????????????????
init();
while(1)
{
ckey?=?keyscan();?
if(ckey?==?‘$‘)
init();???????????
if(ckey?!=?‘#‘)
{?
if(ckey>=0&&ckey<=9)?????????
{
switch(bool)
{
case?0:
if(cut1?3)
{
operand1[cut1]?=?ckey;
switch(cut1)
{
case?0:?value1?=?operand1[0];
break;
case?1: value1?=?operand1[0]*10+operand1[1];
break;
case?2: value1?=?operand1[0]*100+operand1[1]*10+operand1[2];
break;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-03-14?14:47??基于proteus的計算器\
?????文件????????4648??2017-03-05?14:10??基于proteus的計算器\play.c
?????文件????????3477??2017-03-05?14:10??基于proteus的計算器\計算器.hex
?????文件???????18694??2017-03-05?18:11??基于proteus的計算器\計算器.pdsprj
- 上一篇:IP TCP UDP校驗和計算
- 下一篇:山大C++實驗
評論
共有 條評論