




已阅读5页,还剩23页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
单片机课程设计 院系: 电子工程信息学院 姓名: 学号: 班号:12级 电子通信313班 指导教师: 日期:2013.05.28目录第一部分 元器件的购买和电路板的焊接1.元器件清单:USB电源借口,四位一体共阴数码管,电阻:铝电解电容器,电阻,晶振,瓷片电容器两个,电阻若干2.电路板原理图,单片机,单片机芯片,电源指示灯3.焊接第二部分 1.编程软件的学习 2.简单的LED和液晶显示第三部分 时钟的设计1.总体设计 2.硬件设计 3.软件设计第四部分 实习心得体会通过学习单片机我懂得了不只要在书本上花时间,还要动手去做,去实践,手脑结合,学习效果会更好,锻炼自己动手的能力更能突出自己的聪明才智,单片机在现实社会当中已经普片存在了,越来越多的电子产品牵涉到单片机的应用了,单片机在电子产品当中已经占主要市场了,所以我要学好这门技术,为自己的梦想从现在开始奋斗吧第一部分 元器件的购买和电路板的焊接1.元器件清单(见附录)2.电路板原理图1104 12041204 1104通过和班长去广埠屯购买元件,对购买元器件有了一定的了解。另外通过对开发板硬件的学习,熟知了很多元器件的功能。3.焊接 以下是完成后的开发板: 通过对开发板的焊接,首先对焊接技巧有了一定的掌握,另外对一些电路图有了一定的认识,并初步了解了一些基本的原理,如A/D转换,复位电路等。第二部分1.编程软件的学习首先,在上课期间了解了wave,在暑假集中学习了keil.以下是keil编程的主要步骤:1、点击Keil uVision4FileNew可新建一个工程文件。点击Keil uVision4FileSave可保存并重命名新建的工程文件。工程文件的名称后缀为.c 2、点击Keil uVision4ProjectNew Project.可新建并重命名一个工程; 点击“保存”按钮后,选择对应的单片机型号3、在Source Group 1上右键单击Add Files to Group Source Group 1为工程添加相应的工程文件 4、在工程文件中写入单片机程序,点击保存按钮保存文件5、如果程序出现错误,在Output Window窗口会有错误和告警提示,修改并重新编译程序内容,直到Output Window窗口出现“0 Error(s),0 Warning(s)”。 2.简单的LED和液晶的显示 通过课程和编程软件的学习,可以编写一些基本的程序,比如数码管可以实现计时,闪烁,键盘扫描,移位,清屏;液晶可以实现按键显示。以下是C语言源程序:#includereg51.h#include1602.hunsigned char t;unsigned char Led8=1,2,3,4,5,6,7,8;unsigned char Led18=0x00,0x21,0x42,0x63,0x84,0xa5,0xc6,0xe7;unsigned char KeyV=0;unsigned char code Key16= 0xeb,0x77,0x7b,0x7d, /0 1 2 3 0xb7,0xbb,0xbd,0xd7, /4 5 6 7 0xdb,0xdd,0x7e,0xbe, /8 9 a b 0xde,0xee,0xe7,0xed, /c d * # ;unsigned char code A= 0X00,0X01,0X02,0X03,0X04,0X05,0X06,0X07,0X08,0X09 ; unsigned char SecondL; unsigned char SecondH; unsigned char MinuteL; unsigned char MinuteH; unsigned char HourL; unsigned char HourH; unsigned char cnt;void delay() unsigned char t; t=200; while(t-);void dly() unsigned int q; q=2000; while(q-);void display() unsigned char i,P1Buf; for(i=0;i=7;i+) P1Buf=i*2; P1Buf=P1Buf4; P1Buf=P1Buf+Ledi; P1=P1Buf; delay(); /*0为放开,1为未放开*/unsigned char up() unsigned char P0Buf; P0=0xf0; delay(); P0Buf=P0; return(P0Buf-0xf0);void scan() unsigned char P0Buf,P0Buf2,i; P0=0xf0; P0Buf=P0; if(P0Buf!=0xf0) dly(); P0=0xf0; P0Buf=P0; if(P0Buf!=0xf0) P0=0x0f; P0Buf2=P0; P0Buf=P0Buf+P0Buf2; KeyV=P0Buf; while(up();/*判断按键放开*/ for(i=0;i0;i-) Ledi=Ledi-1; Led0=KeyV; void timer0() interrupt 1 unsigned char cnt;TH0 = (65536-50000)/256;TL0 = (65536-50000)%256;cnt+;if(cnt = 20) cnt = 0; +SecondL; if(SecondL = 10) SecondL = 0; +SecondH; if(SecondH = 6) SecondH = 0; +MinuteL; if(MinuteL = 10) MinuteL = 0;+MinuteH; if(MinuteH=6) MinuteH=0; +HourL; if(HourL=10) HourL=0; +HourH; if(HourH=2&HourL=4) HourH=0; HourL=0; void shizhong() TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1; KeyV=0; while(1) scan(); if(KeyV=11) P1=0x0a; KeyV=0; while(up(); do scan(); while(!KeyV); HourH=KeyV; KeyV=0; while(up(); do scan(); while(!KeyV); HourL=KeyV; KeyV=0; while(up(); do scan(); while(!KeyV); MinuteH=KeyV; KeyV=0; while(up(); do scan(); while(!KeyV); MinuteL=KeyV; KeyV=0; while(up(); do scan(); while(!KeyV); SecondH=KeyV; KeyV=0; while(up(); do scan(); while(!KeyV); SecondL=KeyV; if(HourH=2&HourL=4) HourH=0; HourL=0; if(KeyV=10) P1=0x0a; break; P1=ASecondL+0x00;delay(); P1=ASecondH+0x20;delay(); P1=AMinuteL+0x40;delay(); P1=AMinuteH+0x60;delay(); P1=AHourL+0x80;delay(); P1=AHourH+0xA0;delay(); void jianpan() while(1) if(KeyV=10) P1=0x0a;break; scan(); display(); void timer1() interrupt 3 t+; TL1=(65536-50000)%256; TH1=(65536-50000)/256;void sanshuo() TL1=(65536-50000)%256; TH1=(65536-50000)/256; EA=1; ET1=1; TR1=1; while(1) scan(); if(KeyV=10) P1=0x0a; break; if(t=20) P1=0x0a; t=0; while(t=20);t=0; P1=0x01;delay();P1=0x22;delay();P1=0x43;delay();P1=0x64;delay(); P1=0x85;delay();P1=0xa6;delay();P1=0xc7;delay();P1=0xe8;delay(); void yejing() unsigned char x,y; /显示坐标 unsigned char tmp;/用于暂存 dly(); LcdInit(); /LCD初始化 WrtLcdCmd(); /清显示 SetCursor(0,0); /光标复位 进入工作状态 Display(0,0, danpianjiyanshi ); /欢迎画面 SetCursor(0,1); Display(0,1, zhanglin ); dly();void main() while(1) doscan();while(!KeyV); switch(KeyV) case 12: yejing();break; case 13: sanshuo();break; case 14: jianpan();break; case 15: shizhong();break; case 16: break; 第三部分 时钟的设计1.总体设计本系统选用MCS-51系列单片机为主控机,通过扩展必要的外围接口电路,实现对时钟的设计。具体设计如下:(1)由于要设计的是简单的时钟,为了得到较好的显示效果,采用LCD 显示时间。(2)键盘采用PS2键盘,除了数字键输入时间外,“+”设置时间,“”设置闹钟,“.”跳出闹钟。(3)执行过程:开机LCD显示时间,当键入按键,执行相应的功能。2、硬件设计本设计选用AT89C51单片机为主控单元。 显示部分:采用LCD静态显示。按键部分:PS2键盘。 3、软件设计时钟程序:#include #include1602.h#includeabsacc.h#include intrins.h#includePS2.hsbit cs=P20; /片选信号sbit Read_enable=P37;/ 读使能信号sbit Led_clock=P31;/LED模拟闹钟unsigned char num1,num2,num3,num4,num5,num6; /存储显示时间信息unsigned char miao=0,fen=0,shi=0,ri=0,yue=0,nian=0;/存储设置时间信息unsigned char temp1=0,temp2=0,temp3=0,temp4=0,temp5=0,temp6=0;/存储闹钟时间信息unsigned char shuju15=0,shuju215=0,shuju315=0,shuju415=0;char flag=1,flag1=1,flag3=1;/标志位/*命令常量定义 */#define CMD_START_DS12C887 0x20 / 开启时钟芯片 #define CMD_START_OSCILLATOR 0x70 / 开启振荡器,处于抑制状态 /*所有的置位使用或操作,清除使用与操作 */#define MASK_SETB_DM 0x04 / 使用二进制格式 #define MASK_CLR_DM 0xfb / 使 用BCD码格式 #define MASK_SETB_2412 0x02 / 使用24小时模式 #define MASK_CLR_2412 0xfd / 使用12小时模式 /*寄存器地址通道定义*/xdata char chSecondsChannel _at_ 0xfe00; xdata char chMinutesChannel _at_ 0xfe02; xdata char chHoursChannel _at_ 0xfe04; xdata char chDofWChannel _at_ 0xfe06; xdata char chDateChannel _at_ 0xfe07; xdata char chMonthChannel _at_ 0xfe08; xdata char chYearChannel _at_ 0xfe09; xdata char chCenturyChannel _at_ 0xfe32; xdata char chRegA _at_ 0xfe0a; xdata char chRegB _at_ 0xfe0b; xdata char chRegC _at_ 0xfe0c; xdata char chRegD _at_ 0xfe0d; /* 函数声明部分 */void display(void); void StartDs12c887(void); void CloseDs12c887(void); void InitDs12c887(void); unsigned char GetSeconds(void); unsigned char GetMinutes(void); unsigned char GetHours(void); unsigned char GetDate(void); unsigned char GetMonth(void); unsigned char GetYear(void); unsigned char GetCentury(void); void SetTime(unsigned char chSeconds,unsigned char chMinutes,unsigned char chHours); void SetDate(unsigned char chDate,unsigned char chMonth,unsigned char chYear); /*延时函数*/void Dly_mS(unsigned int ms) unsigned int i; while(ms-) for(i=0;i0; no-) for(i=0; i7244; i+);/* 启动时钟芯片工作*/ void StartDs12c887(void) chRegA = CMD_START_DS12C887; /*关闭时钟芯片*/ /*void CloseDs12c887(void) chRegA = CMD_CLOSE_DS12C887; */* 从时钟芯片读取秒字节 */ unsigned char GetSeconds(void) return(chSecondsChannel); /*从时钟芯片读取分字节 */ unsigned char GetMinutes(void) return(chMinutesChannel); /*从时钟芯片读取小时字节 */ unsigned char GetHours(void) return(chHoursChannel); /*从时钟芯片读取日字节*/ unsigned char GetDate(void) return(chDateChannel); /* 从时钟芯片读取月字节 */ unsigned char GetMonth(void) return(chMonthChannel); /*从时钟芯片读取年字节*/ unsigned char GetYear(void) return(chYearChannel); /*设置时钟芯片的时间 */ void SetTime(unsigned char chSeconds,unsigned char chMinutes,unsigned char chHours) chRegB = 0x86; / 禁止刷新 chSecondsChannel = chSeconds; chMinutesChannel = chMinutes; chHoursChannel = chHours; chRegB =0x06;/使能刷新 /*设置时钟芯片的日期 */ void SetDate(unsigned char chDate,unsigned char chMonth,unsigned char chYear) chRegB = 0x86; / 禁止刷新 chDateChannel = chDate; chMonthChannel = chMonth; chYearChannel = chYear; chRegB = 0x06;/ 使能刷新 /* 显示时间日期 */ void display(void) unsigned char y,l,m,w,n,o,p,q; unsigned char z,x,c,b; z=num1/10; /秒 x=num1%10; c=num2/10; /分 b=num2%10; n=num3/10;/时 o=num3%10; p=num4/10;/日 q=num4%10; w=num5/10; /月 l=num5%10; m=num6/10; /年 y=num6%10; WrtLcdCmd(0x81); WrtLcdData(0x30+n); WrtLcdCmd(0x82); WrtLcdData(0x30+o); Display(3,0,:);WrtLcdCmd(0x84); WrtLcdData(0x30+c); WrtLcdCmd(0x85); WrtLcdData(0x30+b); Display(6,0,:); WrtLcdCmd(0x87); WrtLcdData(0x30+z); WrtLcdCmd(0x88); WrtLcdData(0x30+x); WrtLcdCmd(0xc1); WrtLcdData(0x30+m); WrtLcdCmd(0xc2); WrtLcdData(0x30+y); Display(3,1,:); WrtLcdCmd(0xc4); WrtLcdData(0x30+w); WrtLcdCmd(0xc5); WrtLcdData(0x30+l); Display(6,1,:);WrtLcdCmd(0xc7); WrtLcdData(0x30+p); WrtLcdCmd(0xc8); WrtLcdData(0x30+q);/*设置时间日期 */ void Settime() unsigned char x,y,i,t=0,m=12; WrtLcdCmd(Clear); /清显示 SetCursor(0,0); /光标复位 进入工作状态 Display(0,0,Please inter); /画面设置 Dly_S(1);/延时2s Dly_S(1); WrtLcdCmd(Clear); /清显示(); SetCursor(0,0); WrtLcdCmd(AllOn); x=y=0; i=0; while(flag) while(KeyPress=0); /等待有键按下 KeyPress=0; /按键标识清零 DispOneChar(x,y,KeyChar); /显示坐标 x+; shujui+=KeyChar; /存储键值字符 if(x=6)&(y=0) y=1;x=0; /换行 if(x=6)&(y=1) x=0;y=0; flag=0; /y=0;x=0;/显示坐标归零 WrtLcdCmd(Clear);/清显示 Dly_S(1);i=0; t=0;m=12; /再次赋值while(m-) /数据转换函数 switch(shujui+) case0:shuju2t+=0;break; case1:shuju2t+=1;break; case2:shuju2t+=2;break; case3:shuju2t+=3;break; case4:shuju2t+=4;break; case5:shuju2t+=5;break; case6:shuju2t+=6;break; case7:shuju2t+=7;break; case8:shuju2t+=8;break; case9:shuju2t+=9;break; default:break; miao=shuju210*10+shuju211;fen=shuju28*10+shuju29;shi=shuju26*10+shuju27;ri=shuju24*10+shuju25;yue=shuju22*10+shuju23;nian=shuju20*10+shuju21; SetDate(nian,yue,ri); /设置日期SetTime(shi,fen,miao); /设置时间flag=1; i=0; t=0; /所有标志清零/*显示完成设置*/ void Wangcheng() WrtLcdCmd(Clear); /清显示 Display(0,0,zhupengjian); /完成画面Display(0,1,O(_)O O(_)O ); Dly_S(1); WrtLcdCmd(Clear); /清显示 Dly_S(1);Read_enable=1; num1=GetSeconds(); num2=GetMinutes(); num3=GetHours(); num4=GetDate(); num5=GetMonth(); num6=GetYear(); display(); Read_enable=0;/*设置闹钟*/ void Setclock() unsigned char x,y,j,s=0,n=12; WrtLcdCmd(Clear); /清显示 SetCursor(0,0); /光标复位 进入工作状态 Display(0,0,Set clock); /画面设置 Dly_S(1); Dly_S(1); WrtLcdCmd(Clear); /清显示(); SetCursor(0,0); WrtLcdCmd(AllOn); x=y=0; j=0; while(flag1) while(KeyPress=0); /等待有键按下 KeyPress=0; /按键标识清零 DispOneChar(x,y,KeyChar); /显示坐标 x+; shuju3j+=KeyChar; if(x=6)&(y=0) y=1;x=0;/换行 if(x=6)&(y=1) x=0;y=0; flag1=0; /y=0;x=0;/显示坐标归零 WrtLcdCmd(Clear);/清显示 Dly_S(1);j=0; s=0;n=12;while(n-) switch(shuju3j+) case0:shuju4s+=0;break; case1:shuju4s+=1;break; case2:shuju4s+=2;break; case3:shuju4s+=3;break; case4:shuju4s+=4;break; case5:shuju4s+=5;break; case6:shuju4s+=6;break; case7:shuju4s+=7;break; case8:shuju4s+=8;break; case9:shuju4s+=9;break; default:break; temp1=shuju410*10+shuju411;temp2=shuju48*10+shuju49;temp3=shuju46*10+shuju47;temp4=shuju44*10+shuju45;temp5=shuju42*10+shuju43;temp6=shuju40*10+shuju41; flag1=1; j=0;s=0; /*停止闹钟*/ void Stopclock() WrtLcdCmd(Clear); /清显示 SetCursor(0,0); /光标复位 进入工作状态 Display(0,0,Stop clock); /画面设置 Dly_S(1); Dly_S(1); WrtLcdCmd(Clear); /清显示 Led_clock=1; flag3=0; /* 摁键功能 */ void checkkey() switch(KeyChar) case+:Settime();break; case-:Setclock();break; case*:Wangcheng();break; case.:Stopclock();break; default:break; /* 主函数*/ void main() cs=0; Led_clock=1; LcdInit(); /lcd初始化 InitDs12c887();/时钟初始化 /StartDs12c887();/启动时钟 /* /XBYTE0x
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 护理就业考试题及答案解析
- 红繁星春水考试题及答案
- 考点攻克人教版八年级物理《运动和力》定向训练试卷(附答案详解)
- 4s店钣喷主管考试题及答案
- 公司融资保密协议书7篇
- 畜禽废弃物资源利用考试题及答案
- 全国新闻摄影自考试题及答案
- 【全国】2025年4月自学考试00882学前教育心理学模拟题及参考答案
- 环境敏感区选址分析-洞察与解读
- 2025年卫生类药学专业知识事业单位招聘考试真题模拟训练及答案
- 6.我们神圣的国土《辽阔的国土》(教案)-部编版道德与法治五年级上册
- 胖东来服务管理办法
- 三轮车驾培考试题库及答案
- HuaTeng店铺跨境电商社交媒体营销策略研究
- 港口码头安全培训知识课件
- 迷走神经反应性晕厥课件
- 2025年中国行政史试题及答案
- (2025年标准)化妆学员协议书
- 人大代表候选人初步人选资格审查表
- 中学生厌学现象调查及应对建议
- 2025年公共文明引导员考试题库
评论
0/150
提交评论