秒表计时器.doc_第1页
秒表计时器.doc_第2页
秒表计时器.doc_第3页
秒表计时器.doc_第4页
秒表计时器.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

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

文档简介

/*1.按下启动键,秒表计时;按下停止键,秒表暂停计时;2.再按启动键,秒表接着计时;再按下停止键,秒表暂停计时;3.再按下停止键,秒表清零;4.清零后能够回显两次记录的秒数;5.完成整体设计,交出完整的课设报告。*/#include#include #include #include#define uchar unsigned char#define uint unsigned int#define shuju P0 /LCD1602 P0输出显示数据sbit wela=P27; /数码管位选锁存端sbit dula=P26; /数码管段选锁存端sbit key1 =P32;/启动命令 sbit key2 =P33; /停止命令sbit key3 =P34; /清除键sbit key4 =P35; / 空车/*定义变量*uchar flag; /标志位uchar flag1; /标志位 uchar flag2; /标志位 uchar table2=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,; /码表uchar table1=0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe;/位码uchar tt; / 计时标量每50ms加1uchar a; / 秒个位uchar b; / 秒十位uchar c; / 分个位uchar d; / 分十位uchar num1;uchar num2;uchar num3;uchar num4;uchar num5;uchar num6;uchar num7;uchar num8;/*延时函数*void delayus(uchar t) while(-t);/*延时函数*void delay(uchar t) /大致延时1mS while(t-) delayus(235); delayus(235); /*秒表计时*void miaobiao(void)if(tt=2) / 10ms到tt=0; / 清零 a+; if(a=10) a=0;b+;if(b=10)b=0;c+;if(c=10)c=0;d+; void display(void)if(flag1=1) /flag1=0; wela=1;shuju=table10;wela=0;dula=1;shuju=table2num1;dula=0;delayus(200);wela=1;shuju=table11;wela=0;dula=1;shuju=table2num2;dula=0;delayus(200); wela=1;shuju=table12;wela=0;dula=1;shuju=0x40;dula=0;delayus(200); wela=1;shuju=table13;wela=0;dula=1;shuju=table2num3;dula=0;delayus(200);wela=1;shuju=table14;wela=0;dula=1;shuju=table2num4;dula=0;delayus(200);else if(flag1=2) /flag2=0; wela=1;shuju=table10;wela=0;dula=1;shuju=table2num5;dula=0;delayus(200);wela=1;shuju=table11;wela=0;dula=1;shuju=table2num6;dula=0;delayus(200); wela=1;shuju=table12;wela=0;dula=1;shuju=0x40;dula=0;delayus(200); wela=1;shuju=table13;wela=0;dula=1;shuju=table2num7;dula=0;delayus(200);wela=1;shuju=table14;wela=0;dula=1;shuju=table2num8;dula=0;delayus(200);else wela=1;shuju=table10;wela=0;dula=1;shuju=table2a;dula=0;delayus(200);wela=1;shuju=table11;wela=0;dula=1;shuju=table2b;dula=0;delayus(200); wela=1;shuju=table12;wela=0;dula=1;shuju=0x40;dula=0;delayus(200); wela=1;shuju=table13;wela=0;dula=1;shuju=table2c;dula=0;delayus(200);wela=1;shuju=table14;wela=0;dula=1;shuju=table2d;dula=0;delayus(200);/*定时器初始化*void Init_Timer0(void) TMOD |= 0x01; /使用模式1,16位定时器, TH0=(65535-5000)/256; TL0=(65535-5000)%256; EA=1; /总中断打开 ET0=1; /定时器中断打开 /TR0=1; /定时器开关打开/*独立按键检测*void key(void) if(key1=0) delay(15); if(key1=0)/按键消抖 TR0=1; /打开定时器 /flag=0;/标志位设置 while(key1=0); if(key2=0) delay(15); if(key2=0)/按键消抖 TR0=0; /打开定时器 flag+; /flag=0;/标志位设置 while(key2=0); if(flag=1) num1=a;num2=b;num3=c;num4=d; if(flag=2) num5=a;num6=b;num7=c;num8=d; if(flag=3) flag=0; a=0; b=0; c=0; d=0; if(key3=0) delay(15); if(key3=0)/按键消抖 TR0=0; /打开定时器 flag1=1; /display1(); /flag=0;/标志位设置 while(key3=0); if(key4=0) delay(15); if(key4=0)/按键消抖 TR0=0; /打开定时器 flag1=2; while(key4=0); /*主程序*void main() a=0;/各参数初始化 b=0; c=0; d=0;flag=0;flag1=0;flag2=0;

温馨提示

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

评论

0/150

提交评论