可单键实现三种功能的切换: 1、 电子时钟: 初始显示时间为23-59-55,正常走时,2个按键调整时、分 功能, 按键1选择的调整内容以闪烁表示,按键2具备长按连续加1功能。 操作过程中显示稳定,单次按键调整不出现数字跳变情形(防抖)。 后台走时:切换至其他功能,仍能后台正确走时。 2、 跑表 显示格式为000.0,计时单位为0.1秒,范围为0.1秒~999.9秒 后台计时:计时中的跑表,切换至其他功能,后台计时继续。 单键实现启动、停止、清零功能 3、 简易直流电压表: 直流电压由信号源或直流源给出,范围0.2v~2.5v; 按键校准:测量仪器给出标准1v电压,可用按键校准自身显示; 自动稳定显示直流电压;1.1v~2.5v范围内任测1个电压值,误差<2%; 0.2~1v范围内,任测1电压值,误差<1%,且显示基本稳定。 芯片:TLC2543、lcd1602、51 内含:protues仿真电路图
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #include "lcd.h"
- #include "TLC2543.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define d0 0x80
- #define d1 0xc0
- sbit s1=P1^0; //按键1:进入时钟设置,再按进入秒表界面,再按进入电压表界面
- sbit s5=P1^4; //时钟下:时分秒的选择(第四次确认设置);秒表下:启动、停止、清零
- sbit s6=P1^5; //时钟下:加1,长按停顿后连续加1
- uchar count=0,count1=0,s=23,f=59,m=55;
- uchar ss1=0,t0,t1,n=0;
- uchar code tab2[]=" 000.0";
- uchar code tab3[]=" 0.000";
- float p=0;
- void delay(uint c);
- void button0();
- void button1();
- void button2();
- void main()
- {
- LcdInit();
- while(1)
- {
- if(s1==0)
- {
- delay(5);
- if(s1==0) {while(!s1);ss1++;button0();}
- }
- LcdWriteSg(d1,2,s);
- LcdWriteSg(d1,5,f);
- LcdWriteSg(d1,8,m);
- }
- }
- //子函数
- void delay(uint x)
- {
- uint i;
- while(x--)
- for(i=0;i<110;i++);
- }
- void button0()
- {
- LcdWriteCom(d1+6);
- LcdWriteCom(0x0f); //开光标
- while(1)
- {
- if(ss1==0) return;
- if(s5==0)
- {
- delay(5);
- if(s5==0)
- {
- while(!s5);
- ss1++;
- if(ss1==2)
- {
- LcdWriteCom(d1+3); //在时钟时个位光标闪烁
- }
- if(ss1==3)
- {
- ss1=0; //取消设置
- LcdWriteCom(0x0c); //整体显示开、光标关、光标不闪烁
- return;
- }
- }}
- if(ss1!=0)
- {
- if(s6==0)
- {
- delay(5);
- if(s6==0)
- {
- delay(850);
- if(s6)
- {
- if(ss1==1)
- {
- f++;
- if(f==60) f=0;
- LcdWriteSg(d1,5,f);
- LcdWriteCom(d1+6);
- }
- if(ss1==2)
- {
- s++;
- if(s==24) s=0;
- LcdWriteSg(d1,2,s);
- LcdWriteCom(d1+3);
- }
- }
- while(!s6){
- if(ss1==1)
- {
- f++;
- if(f==60) f=0;
- LcdWriteSg(d1,5,f);
- LcdWriteCom(d1+6);
- }
- if(ss1==2)
- {
- s++;
- if(s==24) s=0;
- LcdWriteSg(d1,2,s);
- LcdWriteCom(d1+3);
- }
- delay(100);
- }
- }
- }
- }
- if(s1==0)
- {
- delay(5);
- if(s1==0){while(!s1);ss1=0;button1();}
- }
- }
- }
- void button1()
- {
- uchar i;
- LcdWriteCom(0x0c);
- LcdWriteCom(0x01);
- LcdWriteCom(0x80);
- for(i=0;i<7;i++)
- {
- LcdWriteData(tab2[i]);
- delay(5);
- }
- while(1){
- if(s5==0 && n==0)
- {
- delay(5);
- if(s5==0)
- {
- n++;
- while(!s5);
- TMOD=TMOD|0x10;//定时器1 每50000*1us=0.05s溢出一次
- TH1=0x3c;
- TL1=0xd0;
- EA=1; //开总中断
- ET1=1; //开定时器1中断
- TR1=1; //开定时器
- }
- }
- if(s5==0 && n==1)
- {
- delay(5);
- if(s5==0)
- {
- while(!s5);
- n++;
- TR1=0;
- }
- }
- if(s5==0 && n==2)
- {
- if(s5==0)
- {
- while(!s5);
- n=0;
- t0=0;
- t1=0;
- }
- }
- LcdWriteSg(d0,2,t1);
- LcdWriteSg1(d0,4,t0);
- if(s1==0)
- {
- delay(5);
- if(s1==0) {while(!s1);button2();return;}
- }
- }
- }
- void button2()
- {
- uchar i,a[5];
- uint dat;
- float s;
- LcdWriteCom(0x01);
- LcdWriteCom(0x80);
-
-
- for(i=0;i<7;i++)
- {
- LcdWriteData(tab3[i]);
- delay(5);
- }
- while(1){
- dat=Read_AD_Data(0);
- s=(float)5*dat/4096;
- if(s5==0)
- {
- delay(5);
- if(s5==0)
- {
- p=s-1;
- }
- }
- s=s-p;
- a[3]=(int)s*1;
- a[2]=((int)(s*10))%10;
- a[1]=((int)(s*100))%10;
- a[0]=((int)(s*1000))%10;
- a[4]=((int)(s*10000))%10;
- if(a[4]>5)
- {
- if(a[0]==9)
- {
- a[0]=0;
- if(a[1]==9)
- {
- a[1]=0;
- if(a[2]==9)
- {
- a[2]=0;
- a[3]++;
- }
- else a[2]++;
- }
- else a[1]++;
- }
- else a[0]++;
- }
- LcdWriteCom(0x80+0x02);
- LcdWriteData(0x30+a[3]);
- LcdWriteCom(0x80+0x04);
- LcdWriteData(0x30+a[2]);
- LcdWriteCom(0x80+0x05);
- LcdWriteData(0x30+a[1]);
- LcdWriteCom(0x80+0x06);
- LcdWriteData(0x30+a[0]);
- if(s1==0)
- {
- delay(5);
- if(s1==0){while(!s1);LcdInit();return;}
- }
- }
- }
- void tim0() interrupt 1
- {
- TH0=0x3c;
- TL0=0xd0;
- count++;
- if(count==20)
- {
- count=0;
- m++;
- if(m==60)
- {
- m=0;
- f++;
- if(f==60)
- {
- f=0;
- s++;
- if(s==24) s=0;
- }
- }
- }
- }
- void tim1() interrupt 3
- {
- TH1=0x3c;
- TL1=0xd0;
- count1++;
- if(count1==2)
- {
- count1=0;
- t0++;
- if(t0==100)
- {
- t0=0;
- t1++;
- }
- if(t1==99 && t0==99)
- {
- TR1=0; //关中断
- }
- }
- }
复制代码
所有资料51hei提供下载:
简易时钟 跑表 直流电压表.rar
(100.52 KB, 下载次数: 91)
|