EDA课设

更新时间:2024-01-12 03:27:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

# include #define uchar unsigned char #define uint unsigned int

bit NumSem;//前后操作数的互斥信号量 bit equ;//等号判断 bit clr;//清零标志 bit add;//加标志 bit dec;//减标志 bit mul;//乘标志 bit div;//除标志

bit op;//算术符号标志 uchar KeyNum;//键值 uint result;//计算结果

uint PreNum,LatNum;//计算的两个操作数前操作数,后操作数 uchar KeyPos;

uchar DisLed[]={0xC0,0xF9,0xA4,0xB0,0x99,//LED数码七段表 0x92,0x82,0xF8,0x80,0x90}; uchar NumBufe[]={0,0,0,0}; //sbit P10=P1^0; //sbit P11=P1^1; //sbit P12=P1^2; //sbit P13=P1^3;

void T0Intal(void);//定时器0初始化程序 void DisPlay(void);//显示程序

void ResultNum(void);//计算器运算结果 void Clear(void);//清零程序

void Delay_510(void);//延时510us程序用汇编编写

void ChangeNum(uchar *p,uchar nCount);//NumBufe[]移位程序 void main(void) {

T0Intal(); while(1) {

if(NumSem) {

PreNum=NumBufe[3]*1000+NumBufe[2]*100+NumBufe[1]*10+NumBufe[0]; NumBufe[4]=0; NumSem=0; } if(op) {

if(PreNum!=0) {

if(NumBufe[4]==0)

{

NumSem=1; }

if(equ) {

if(NumBufe[4]!=0) {

LatNum=NumBufe[3]*1000+NumBufe[2]*100+NumBufe[1]*10+NumBufe[0]; //DisLed[]=0; KeyPos=0; }

ResultNum();//计算器结果计算 //DisPlay();//显示计算结果 } }

else Clear(); }

if(clr) {

Clear(); }

DisPlay();//显示计算结果 } }

void T0Intal(void) {

TMOD=0x01;

TH0=(65536-20000)/256; TL0=(65536-20000)%6; EA=1; ET0=1; TR0=1; }

void DisPlay(void) {

//uchar one,two,three,four; //one=result/1000;

P2=DisLed[NumBufe[3]]; P0=0xFE; Delay_510();

//two=(result-one*1000)/100;

P2=DisLed[NumBufe[2]]; P0=0xFD; Delay_510();

//three=(result-one*1000-two*100)/10; P2=DisLed[NumBufe[1]]; P0=0xFB; Delay_510();

//four=(result-one*1000-two*100); P2=DisLed[NumBufe[0]]; P0=0xF7; Delay_510(); }

void ResultNum(void) {

if(op) {

if(add) {

result=PreNum+LatNum; }

if(dec) {

result=PreNum-LatNum; }

if(mul) {

result=PreNum*LatNum; }

if(div) {

result=PreNum/LatNum; } }

//return result; //unsigned char

//uchar one,two,three; //one=result/1000;

NumBufe[3]=result/1000;

NumBufe[2]=(result-NumBufe[3]*1000)/100; //NumBufe[2]=two;

NumBufe[1]=(result-NumBufe[3]*1000-NumBufe[2]*100)/10; //NumBufe[1]=three;

NumBufe[0]=(result-NumBufe[3]*1000-NumBufe[2]*100);

}

void Clear(void) {

// if(Clear) //{

NumBufe[0]=0; NumBufe[1]=0; NumBufe[2]=0; NumBufe[3]=0; PreNum=0; LatNum=0; result=0; NumSem=0; KeyPos=0; clr=0; equ=0; add=0; dec=0; mul=0; div=0; op=0; // } }

void ChangeNum(uchar *p,uchar nCount) {

if(nCount<4) {

uchar ncount; ncount=nCount; while(ncount>0) {

*(p+nCount)=*(p+nCount-1); ncount--; } } }

void Delay_510(void)//延时510微秒 {

#pragma asm MOV R0,#7DH MOV R1,#02H TSR1:

DJNZ R0,TSR1 MOV R0,#7DH

DJNZ R1,TSR1 #pragma endasm }

void Time0_Isr_Int(void) interrupt 1 //定时器0中断服务子程序 {

TH0=(65536-20000)/256; TL0=(65536-20000)%6; P1=0xF0;

if((P1&0xF0)!=0xF0) {

Delay_510(); if((P1&0xF0)!=0xF0) {

P1=0xFE;

if((P1&0xF0)==0xE0)//数字键0 {

KeyNum=0;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

if((P1&0xF0)==0xD0) {

KeyNum=1;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

if((P1&0xF0)==0xB0) {

KeyNum=2;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

if((P1&0xF0)==0x70) {

KeyNum=3;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

P1=0xFD;

if((P1&0xF0)==0xE0) {

KeyNum=4;

ChangeNum(NumBufe,KeyPos);

KeyPos++; }

if((P1&0xF0)==0xD0) {

KeyNum=5;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

if((P1&0xF0)==0xB0) {

KeyNum=6;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

if((P1&0xF0)==0x70) {

KeyNum=7;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

P1=0xFB;

if((P1&0xF0)==0xE0) {

KeyNum=8;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

if((P1&0xF0)==0xD0) {

KeyNum=9;

ChangeNum(NumBufe,KeyPos); KeyPos++; }

if((P1&0xF0)==0xB0)//加法 {

op=1; add=1; }

if((P1&0xF0)==0x70) {

op=1; dec=1; }

P1=0xF7;

if((P1&0xF0)==0xE0) {

op=1; mul=1; }

if((P1&0xF0)==0xD0) {s

op=1; div=1; }

if((P1&0xF0)==0xB0)//等号 {

equ=1; }

if((P1&0xF0)==0x70)//清零 {

clr=1; } } } }

本文来源:https://www.bwwdw.com/article/x6no.html

Top