資源簡介
單片機設(shè)計計算器 實現(xiàn)加減乘除簡單功能
能處理四個字節(jié)的數(shù)據(jù)
代碼片段和文件信息
#include
#define??uint??unsigned?int
#define??uchar?unsigned?char
#define??PinData??P0
#define??ClearScreen() WriteInstruc(0x01)
#define??DispControl(temp) WriteInstruc(temp)
#define??FunctionSet(temp) ????WriteInstruc(temp)
#define??SetDDRAM_Add(Address) WriteInstruc(0x80?|?Address)
#define??CursorReturn() WriteInstruc(0x02)
sbit?PinRS=P2^0;
sbit?PinRW=P2^1;
sbit?PinE=P2^2;
int?r=0;
int?a;
int?reset=0; ??//結(jié)束一次運算后復(fù)位標志位
int?f1=0; ??//結(jié)果是負數(shù)標志位
int?yun; ??//yun==1+???2-???3* 4/
int?o[16];
char?idata?e[16]=“system?error“; ??
char?idata?t[16]?; ??
char?idata?m[16]?; ?? ?
unsigned?long?int?idata?u=0;
unsigned?long?int?idata?v=0;
unsigned?long?int?idata?w=0;
void?delay(int?i)????????????????????????//誤差?0us??延時
{
????unsigned?char?j;
????for(;i>0;i--)
????????for(j=0;j<100;j++);
}
void?ShortDelay(int?i)
{
for(;i>0;i--)?;
}
void?InitP0(bit?i)?
{
if(i==1)?P0?=?0xff;
else?????P0?=?0x00;
}?
char?Read_BF_AC()
{
uchar?temp;
InitP0(1);
PinRS=0;
PinRW=1;
PinE=0;
PinE=1;
ShortDelay(1);
temp?=?PinData;
ShortDelay(10);
PinE=0;
PinRW=0;
PinRS=1;
return(temp);
}
bit?StatusCheck()
{
return((bit)(Read_BF_AC()?&?0x80));
}
void?WriteData(char?data1)
{
InitP0(0);
PinRS=1;
PinRW=0;
PinE=0;
PinData?=?data1;
PinE=1;
ShortDelay(10);
PinE=0;
PinRW=1;
PinRS=0;
}??
void?WriteInstruc(char?Instruc)
{
while(StatusCheck());
InitP0(0);
PinRS=0;
PinRW=0;
PinE=0;
PinData?=Instruc;
PinE=1;
ShortDelay(10);
PinE=0;
PinRW=1;
PinRS=1;
}
void?DispCharacter(int?x?int?y?char?data1)
{
int?temp;???????
while(StatusCheck());????????????????????????//若LCD控制器忙,則等待
temp?=?y?&?0x0f;
x?&=?0x01;
if(x)?temp?|=?0x40;
SetDDRAM_Add(temp); ?????????????????????????//設(shè)置顯示位置
WriteData(data1);
}
void?soft_reset(void) ?//復(fù)位
{
???((void?(code?*)?(void))?0x0000)?();
}
char?xunzuo(char?c) ?????????//0xfe左移
{
?
if(c&0x80)
{
??c=c<<1;
??c=c|0x01;
?}
?else
?{?c<<=1;}
?return(c);
}
unsigned?long?int?pow(int?y)
{
???int?i;
???unsigned?long?int?x=1;
???for(i=0;i ???{
??????x=x*10;
???}
???return?x;
}
void?systemerror()
{
???int?y0q0=3;
???ClearScreen();
???for(y0=0;y0<12;y0++)
{?
???DispCharacter(0q0++e[y0]);
}
delay(2000);
ClearScreen();
soft_reset();
}
void?qian() ????????//計算符號前面的數(shù)值
{
int?i;
unsigned?long?int?idata?tx;
u=0;
if(r-1>10)??{?systemerror();}
if(r-1==10)
{
???if((t[0]-48)>4&&(t[1]-48)>2&&(t[2]-48)>9&&(t[3]-48)>4&&(t[4]-48)>9&&(t[5]-48)>6&&(t[6]-48)>7&&(t[7]-48)>2&&(t[8]-48)>9&&(t[9]-48)>5)?{?systemerror();}
}
????for(i=r-2;i>=0;i--)
{
???tx=u;
???????u=u+((unsigned?long?int)(t[i]-48)*(pow(r-i-2)));??
???if(u }
}?
void?hou(?) ???//計算符號后面的數(shù)值
{
????int?i;
unsigned?long?int?idata?ty;
v=0;
if(r-1-a>10)? {?systemerror();}
if(r-1-a==10)
{
???if((t[a]-48)>4&&(t[a-1]-48)>2&&(t[a-2]-48)>9&&(t[
- 上一篇:訂單號隨機生成器
- 下一篇:變速齒輪2.2.zip
評論
共有 條評論