找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3670|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

TLC2543+51單片機(jī)的直流電壓表+時(shí)鐘+跑表仿真及程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
可單鍵實(shí)現(xiàn)三種功能的切換:
1、       電子時(shí)鐘:
          初始顯示時(shí)間為23-59-55,正常走時(shí),2個(gè)按鍵調(diào)整時(shí)、分 功能,
          按鍵1選擇的調(diào)整內(nèi)容以閃爍表示,按鍵2具備長(zhǎng)按連續(xù)加1功能。
          操作過程中顯示穩(wěn)定,單次按鍵調(diào)整不出現(xiàn)數(shù)字跳變情形(防抖)。
          后臺(tái)走時(shí):切換至其他功能,仍能后臺(tái)正確走時(shí)。
2、       跑表
                           顯示格式為000.0,計(jì)時(shí)單位為0.1秒,范圍為0.1秒~999.9秒
                          后臺(tái)計(jì)時(shí):計(jì)時(shí)中的跑表,切換至其他功能,后臺(tái)計(jì)時(shí)繼續(xù)。
                          單鍵實(shí)現(xiàn)啟動(dòng)、停止、清零功能
3、       簡(jiǎn)易直流電壓表:
          直流電壓由信號(hào)源或直流源給出,范圍0.2v~2.5v;
                           按鍵校準(zhǔn):測(cè)量?jī)x器給出標(biāo)準(zhǔn)1v電壓,可用按鍵校準(zhǔn)自身顯示;
                           自動(dòng)穩(wěn)定顯示直流電壓;1.1v~2.5v范圍內(nèi)任測(cè)1個(gè)電壓值,誤差<2%;
                            0.2~1v范圍內(nèi),任測(cè)1電壓值,誤差<1%,且顯示基本穩(wěn)定。
芯片:TLC2543、lcd1602、51
內(nèi)含:protues仿真電路

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)



單片機(jī)源程序如下:
  1. #include<reg51.h>
  2. #include "lcd.h"
  3. #include "TLC2543.h"
  4. #define uchar unsigned char
  5. #define uint unsigned int
  6. #define d0 0x80
  7. #define d1 0xc0
  8. sbit s1=P1^0;                 //按鍵1:進(jìn)入時(shí)鐘設(shè)置,再按進(jìn)入秒表界面,再按進(jìn)入電壓表界面
  9. sbit s5=P1^4;                 //時(shí)鐘下:時(shí)分秒的選擇(第四次確認(rèn)設(shè)置);秒表下:?jiǎn)?dòng)、停止、清零
  10. sbit s6=P1^5;                 //時(shí)鐘下:加1,長(zhǎng)按停頓后連續(xù)加1
  11. uchar count=0,count1=0,s=23,f=59,m=55;
  12. uchar ss1=0,t0,t1,n=0;
  13. uchar code tab2[]="  000.0";
  14. uchar code tab3[]="  0.000";
  15. float p=0;
  16. void delay(uint c);
  17. void button0();
  18. void button1();
  19. void button2();
  20. void main()
  21. {
  22.         LcdInit();
  23.         while(1)
  24.         {
  25.         if(s1==0)
  26.         {
  27.                 delay(5);
  28.                 if(s1==0) {while(!s1);ss1++;button0();}
  29.         }
  30.         LcdWriteSg(d1,2,s);
  31.         LcdWriteSg(d1,5,f);
  32.         LcdWriteSg(d1,8,m);
  33.         }

  34. }






  35. //子函數(shù)        
  36. void delay(uint x)
  37. {
  38.         uint i;  
  39.         while(x--)
  40.            for(i=0;i<110;i++);
  41. }
  42. void button0()
  43. {       
  44.         LcdWriteCom(d1+6);
  45.         LcdWriteCom(0x0f); //開光標(biāo)
  46.         while(1)
  47.         {
  48.                 if(ss1==0) return;
  49.                 if(s5==0)
  50.                 {
  51.                         delay(5);
  52.                         if(s5==0)
  53.                         {
  54.                                 while(!s5);
  55.                                 ss1++;
  56.                                 if(ss1==2)
  57.                                  {
  58.                                         LcdWriteCom(d1+3);          //在時(shí)鐘時(shí)個(gè)位光標(biāo)閃爍
  59.                                  }
  60.                                 if(ss1==3)                                         
  61.                                  {
  62.                                         ss1=0;                           //取消設(shè)置
  63.                                         LcdWriteCom(0x0c);                //整體顯示開、光標(biāo)關(guān)、光標(biāo)不閃爍
  64.                                         return;
  65.                                  }
  66.                         }}
  67.                 if(ss1!=0)
  68.                         {
  69.                                 if(s6==0)
  70.                                 {
  71.                                         delay(5);
  72.                                         if(s6==0)
  73.                                         {       
  74.                                                 delay(850);
  75.                                                 if(s6)
  76.                                                 {
  77.                                                 if(ss1==1)
  78.                                                 {
  79.                                                         f++;
  80.                                                         if(f==60) f=0;
  81.                                                         LcdWriteSg(d1,5,f);
  82.                                                         LcdWriteCom(d1+6);
  83.                                                 }
  84.                                                 if(ss1==2)
  85.                                                 {
  86.                                                         s++;
  87.                                                         if(s==24) s=0;
  88.                                                         LcdWriteSg(d1,2,s);
  89.                                                         LcdWriteCom(d1+3);
  90.                                                 }
  91.                                                 }
  92.                                                 while(!s6){
  93.                                                 if(ss1==1)
  94.                                                 {
  95.                                                         f++;
  96.                                                         if(f==60) f=0;
  97.                                                         LcdWriteSg(d1,5,f);
  98.                                                         LcdWriteCom(d1+6);
  99.                                                 }
  100.                                                 if(ss1==2)
  101.                                                 {
  102.                                                         s++;
  103.                                                         if(s==24) s=0;
  104.                                                         LcdWriteSg(d1,2,s);
  105.                                                         LcdWriteCom(d1+3);
  106.                                                 }
  107.                                                 delay(100);
  108.                                                 }
  109.                                      }
  110.                                 }
  111.                         }
  112.                 if(s1==0)
  113.                 {
  114.                         delay(5);
  115.                         if(s1==0){while(!s1);ss1=0;button1();}
  116.                 }
  117.         }
  118. }
  119. void button1()
  120. {
  121.         uchar i;
  122.         LcdWriteCom(0x0c);
  123.         LcdWriteCom(0x01);
  124.         LcdWriteCom(0x80);
  125.         for(i=0;i<7;i++)
  126.     {
  127.                  LcdWriteData(tab2[i]);
  128.                    delay(5);
  129.         }       
  130.         while(1){
  131.         if(s5==0 && n==0)
  132.         {
  133.                 delay(5);
  134.                 if(s5==0)
  135.                 {
  136.                         n++;
  137.                         while(!s5);
  138.                         TMOD=TMOD|0x10;//定時(shí)器1        每50000*1us=0.05s溢出一次            
  139.                         TH1=0x3c;
  140.                         TL1=0xd0;
  141.                         EA=1;                                //開總中斷
  142.                         ET1=1;                                //開定時(shí)器1中斷
  143.                         TR1=1;                                //開定時(shí)器
  144.                 }
  145.         }
  146.         if(s5==0 && n==1)
  147.         {
  148.                 delay(5);
  149.                 if(s5==0)
  150.                 {
  151.                         while(!s5);
  152.                         n++;
  153.                         TR1=0;
  154.                 }
  155.         }
  156.         if(s5==0 && n==2)
  157.         {
  158.                 if(s5==0)
  159.                 {
  160.                         while(!s5);
  161.                         n=0;
  162.                         t0=0;
  163.                         t1=0;
  164.                 }
  165.         }
  166.         LcdWriteSg(d0,2,t1);
  167.         LcdWriteSg1(d0,4,t0);
  168.         if(s1==0)
  169.         {
  170.                 delay(5);
  171.                 if(s1==0) {while(!s1);button2();return;}
  172.         }
  173.   }
  174. }

  175. void button2()
  176. {
  177.         uchar i,a[5];
  178.         uint dat;
  179.         float s;
  180.            LcdWriteCom(0x01);
  181.            LcdWriteCom(0x80);          
  182.        
  183.        
  184.         for(i=0;i<7;i++)
  185.     {
  186.                  LcdWriteData(tab3[i]);
  187.                    delay(5);
  188.         }

  189.         while(1){
  190.         dat=Read_AD_Data(0);
  191.         s=(float)5*dat/4096;

  192.         if(s5==0)
  193.         {
  194.                 delay(5);
  195.                 if(s5==0)
  196.                 {
  197.                         p=s-1;
  198.                 }       
  199.         }
  200.         s=s-p;
  201.         a[3]=(int)s*1;
  202.         a[2]=((int)(s*10))%10;
  203.         a[1]=((int)(s*100))%10;
  204.         a[0]=((int)(s*1000))%10;
  205.         a[4]=((int)(s*10000))%10;

  206.         if(a[4]>5)
  207.         {
  208.                 if(a[0]==9)
  209.                 {       
  210.                         a[0]=0;       
  211.                         if(a[1]==9)
  212.                         {
  213.                                 a[1]=0;
  214.                                 if(a[2]==9)
  215.                                 {
  216.                                         a[2]=0;
  217.                                         a[3]++;
  218.                                 }
  219.                                 else a[2]++;
  220.                         }
  221.                         else a[1]++;
  222.                 }
  223.                 else a[0]++;
  224.         }

  225.         LcdWriteCom(0x80+0x02);       
  226.         LcdWriteData(0x30+a[3]);
  227.         LcdWriteCom(0x80+0x04);       
  228.         LcdWriteData(0x30+a[2]);
  229.         LcdWriteCom(0x80+0x05);       
  230.         LcdWriteData(0x30+a[1]);
  231.         LcdWriteCom(0x80+0x06);       
  232.         LcdWriteData(0x30+a[0]);
  233.         if(s1==0)
  234.         {
  235.                 delay(5);
  236.                 if(s1==0){while(!s1);LcdInit();return;}
  237.         }
  238.         }       
  239. }


  240. void tim0() interrupt 1
  241. {
  242.     TH0=0x3c;
  243.         TL0=0xd0;
  244.         count++;
  245.         if(count==20)
  246.           {
  247.                    count=0;
  248.                  m++;
  249.                 if(m==60)
  250.                   {
  251.                           m=0;
  252.                         f++;
  253.                         if(f==60)
  254.                          {
  255.                            f=0;
  256.                            s++;
  257.                            if(s==24) s=0;
  258.                          }
  259.                   }
  260.           }
  261. }
  262. void tim1() interrupt 3
  263. {
  264.         TH1=0x3c;
  265.         TL1=0xd0;
  266.         count1++;
  267.         if(count1==2)
  268.         {               
  269.                 count1=0;
  270.                 t0++;
  271.                 if(t0==100)
  272.                 {
  273.                         t0=0;
  274.                         t1++;
  275.                 }
  276.                 if(t1==99 && t0==99)
  277.                 {
  278.                         TR1=0;                 //關(guān)中斷
  279.                 }
  280.         }
  281. }
復(fù)制代碼

所有資料51hei提供下載:
簡(jiǎn)易時(shí)鐘 跑表 直流電壓表.rar (100.52 KB, 下載次數(shù): 91)


評(píng)分

參與人數(shù) 2黑幣 +105 收起 理由
didi123 + 5 很給力!
admin + 100 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表