基于单片机的简单四则运算_第1页
基于单片机的简单四则运算_第2页
基于单片机的简单四则运算_第3页
基于单片机的简单四则运算_第4页
基于单片机的简单四则运算_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 PAGE - 14 - 课程设计任务书课程设计题目:基于单片机的简单四则运算课 程 设 计 任 务 书1设计目的:掌握电子电路的一般设计方法和设计流程;学习使用Altium Designer软件绘制电路原理图及印刷板图;掌握应用Protues对所设计的电路进行仿真,通过仿真结果验证设计的正确性。2设计内容和要求(包括原始数据、技术参数、条件、设计要求等):设计一个基于单片机的简单四则运算,具体要求如下:1. 用键盘输入两个十进制数,并用数码管显示所输入的数。2根据所按键来进行相应的运算(加、减、乘、除),按等号键即显示相应结果。 3. 除数为零时,液晶屏显示“Error!”,以提示输入有误。

2、3设计工作任务及工作量的要求包括课程设计计算说明书(论文)、图纸、实物样品等: 课程设计说明书; 电路原理图和印刷板图; 仿真图形和仿真结果。图1.电路原理图图2.PCB版图图3.Altium Designer 3D电路板正面图图4.Altium Designer 3D电路板背面图图5.材料清单图6.Protues仿真图图7.正确输入时的实物图图8.除数为零时的实物图 程序代码: #include #include #include unsigned char code number=0123456789+-*/.=;unsigned char code xianshi=Made By;uns

3、igned char code tishi=Error!;unsigned char code User68= 0 x04,0 x04,0 x1f,0 x15,0 x15,0 x1f,0 x04,0 x04, /*自定义字“中”*/ 0 x0a,0 x0a,0 x1a,0 x0b,0 x0a,0 x1a,0 x0a,0 x0b, /*自定义字“北” */ 0 x04,0 x00,0 x1f,0 x01,0 x02,0 x04,0 x08,0 x1f, /*自定义字符“之” */ 0 x1b,0 x1b,0 x1b,0 x15,0 x15,0 x15,0 x15,0 x15, /*自定义字符“M

4、” */ 0 x00,0 x00,0 x09,0 x0a,0 x0c,0 x08,0 x08,0 x08, /*自定义字符“r” */ 0 x1f,0 x05,0 x05,0 x07,0 x01,0 x1f,0 x01,0 x03; /*自定义字符“马” */ sbit rs=P20;sbit rw=P21;sbit enable=P22;sbit bf=P07;sbit fmq=P36;unsigned int temp1,temp2,temp;unsigned char flag=0,shu10;void delay(unsigned char i) unsigned char j=114

5、; while(i-) while(j-);void beep(unsigned int i) unsigned int j; for(j=0;ji;j+) fmq=0; delay(1); fmq=1; delay(1); delay(1000);void fanying(unsigned char i) while(i-) _nop_();bit busytest() bit panduan;rs=0;rw=1;enable=1;fanying(4);panduan=bf;enable=0; return panduan;void writecode(char zhiling) while

6、(busytest(); rs=0; rw=0; enable=0; fanying(4); enable=1; P0=zhiling; fanying(8); enable=0; void address(char add) writecode(add + 0 x80);void writestring(char str) while(busytest(); rs=1; rw=0; enable=0; fanying(4); enable=1; P0=str; fanying(8); enable=0; void chushihua() delay(15); writecode(0 x38)

7、; delay(5); writecode(0 x38); delay(5); writecode(0 x38); delay(5); writecode(0 x06); delay(5); writecode(0 x0c); delay(5);void gettemp1(unsigned char i) unsigned char x; temp1=0; for(x=0;x=100) temp1+;void gettemp2(unsigned char i) unsigned char x; temp2=0; for(x=0;x=100) temp2+;void qiu(unsigned i

8、nt temp1,unsigned int temp2) unsigned char ge=0,shi=0,bai=0,qian=0,wan=0; temp=0; switch(flag) case 1:temp=temp1+temp2;break; case 2:temp=temp1-temp2;break; case 3:temp=temp1*temp2;break; case 4: if(temp2=0) address(0 x40); for(;tishige!=0;ge+) writestring(tishige); goto loop; temp=temp1/temp2; brea

9、k; if(0=temp & temp10) ge=temp; writestring(numberge);loop: writestring(0 x20); writestring(0 x20); writestring(0 x20); writestring(0 x20); writestring(0 x20); writestring(0 x20); writestring(0 x20); writestring(0 x20); address(0 x40); if(10=temp & temp100) shi=temp/10; ge=temp%10; writestring(numbe

10、rshi); writestring(numberge); writestring(0 x20); writestring(0 x20); writestring(0 x20); writestring(0 x20); writestring(0 x20); address(0 x40); if(100=temp & temp1000) bai=temp/100; shi=(temp/10)%10; ge=temp%10; writestring(numberbai); writestring(numbershi); writestring(numberge); writestring(0 x

11、20); writestring(0 x20); writestring(0 x20); address(0 x40); if(1000=temp & temp10000) qian=temp/1000; bai=(temp/100)%10; shi=(temp/10)%10; ge=temp%10; writestring(numberqian); writestring(numberbai); writestring(numbershi); writestring(numberge); writestring(0 x20); writestring(0 x20); writestring(

12、0 x20); address(0 x40); if(10000=temp & temp100000) wan=temp/10000; qian=(temp/1000)%10; bai=(temp/100)%10; shi=(temp/10)%10; ge=temp%10; writestring(numberwan); writestring(numberqian); writestring(numberbai); writestring(numbershi); writestring(numberge); writestring(0 x20); writestring(0 x20); wr

13、itestring(0 x20); address(0 x40); void main() unsigned char i=0,j,k,add=0 x40,a=0 x08; chushihua(); address(0 x01); for(;xianshii!=0;i+) writestring(xianshii); i=0 x01; for(j=0;j6;j+) writecode(add=add+0 x08); delay(5); for(k=0;k8;k+) writestring(Userjk); address(a=a+0 x01); delay(5); writestring(i+

14、); address(0 x40); P1=0 xf0; i=0; while(1) if(P1!=0 xf0) delay(60); P1=0 x7f; switch(P1) case 0 x77:writestring(number13);flag=4;gettemp1(i); i=0;beep(50);break;/除法 4 case 0 x7b:writestring(number12);flag=3;gettemp1(i); i=0;beep(50);break; /乘法 3 case 0 x7d:writestring(number11);flag=2;gettemp1(i); i

15、=0;beep(50);break;/减法 2 case 0 x7e:writestring(number10);flag=1;gettemp1(i); i=0;beep(50);break; /加法 1 P1=0 xbf; switch(P1) case 0 xb7:writestring(number14);beep(50);break; case 0 xbb:writestring(number9);shui+=9;beep(50);break; case 0 xbd:writestring(number6);shui+=6;beep(50);break; case 0 xbe:writ

16、estring(number3);shui+=3;beep(50);break; P1=0 xdf; switch(P1) case 0 xd7:writestring(number0);shui+=0;beep(50);break; case 0 xdb:writestring(number8);shui+=8;beep(50);break; case 0 xdd:writestring(number5);shui+=5;beep(50);break; case 0 xde:writestring(number2);shui+=2;beep(50);break; P1=0 xef; swit

17、ch(P1) case 0 xe7:writestring(number15);gettemp2(i);qiu(temp1,temp2);i=0;beep(50);break; /= case 0 xeb:writestring(number7);shui+=7;beep(50);break; case 0 xed:writestring(number4);shui+=4;beep(50);break; case 0 xee:writestring(number1);shui+=1;beep(50);break; delay(60); 课 程 设 计 任 务 书4主要参考文献: 童诗白模拟电子技术基础北京:高等教育出版社,2002 张建华数字电子技术北京:机械工业出版社,2004 陈汝全电子技术常用器件应用手册北京:机械工业出版社,2005 毕满清电子技术实验与课程设计北京:机械工业出版社,2005 潘永雄电子线路CAD实用教程西安:西安电子科技大学出版社,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论