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

QQ登錄

只需一步,快速開始

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

數(shù)碼管多功能時(shí)鐘程序資料(附仿真文件電路圖使用說明)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:34643 發(fā)表于 2017-5-28 09:44 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
這是一款多功能數(shù)碼管時(shí)鐘程序資料,單片機(jī)是AT89C51,6位數(shù)碼管顯示、DS1302時(shí)鐘、DS18B20溫度測(cè)量。時(shí)間,溫度可以交替顯示。附件中含濤程序,仿真文件,使用說明,電路圖等資料下載:
6位數(shù)碼管顯示DS1302時(shí)鐘DS18B20溫度仿真及C語言程序.zip (1.15 MB, 下載次數(shù): 46)

下面是仿真效果圖:







程序標(biāo)注簡(jiǎn)潔明了。比較適合初學(xué)者下載學(xué)習(xí)。

  1. include <intrins.h>

  2. #define uchar unsigned char
  3. #define uint  unsigned int

  4. sbit    dis_bit1=P2^7;//定義數(shù)碼管控制口
  5. sbit    dis_bit2=P2^6;//定義數(shù)碼管控制口
  6. sbit    dis_bit3=P2^4;//定義數(shù)碼管控制口
  7. sbit    dis_bit4=P2^3;//定義數(shù)碼管控制口
  8. sbit    dis_bit5=P2^1;//定義數(shù)碼管控制口
  9. sbit    dis_bit6=P2^0;//定義數(shù)碼管控制口
  10. sbit    led1_bit=P2^2;//定時(shí)LED的控制口
  11. sbit    led2_bit=P2^5;//定時(shí)LED的控制口
  12. sbit    s1_bit=P1^0;  //定義S1控制口
  13. sbit    s2_bit=P1^1;  //定義S2控制口
  14. sbit    s3_bit=P1^2;  //定義S3控制口
  15. sbit    dq_ds18b20=P3^3;//定義控制DS18B20
  16. sbit    speak=P3^7;   //定義蜂鳴器控制口
  17. sbit    clk_ds1302=P3^6;//定義控制DS1302的時(shí)鐘線
  18. sbit    io_ds1302=P3^5;//定義控制DS1302的串行數(shù)據(jù)
  19. sbit    rest_ds1302=P3^4;
  20. #define smg_data    P0//定義數(shù)碼管數(shù)據(jù)口

  21. void  delay_3us();//3US的延時(shí)程序
  22. void  delay_8us(uint t);//8US延時(shí)基準(zhǔn)程序
  23. void  delay_50us(uint t);//延時(shí)50*T微妙函數(shù)的聲明
  24. void  display1(uchar dis_data);//數(shù)碼管1顯示子程序
  25. void  display2(uchar dis_data);//數(shù)碼管2顯示子程序
  26. void  display3(uchar dis_data);//數(shù)碼管3顯示子程序
  27. void  display4(uchar dis_data);//數(shù)碼管4顯示子程序
  28. void  display5(uchar dis_data);//數(shù)碼管5顯示子程序
  29. void  display6(uchar dis_data);//數(shù)碼管6顯示子程序
  30. void  init_t0();//定時(shí)器0初始化函數(shù)
  31. void  dis_led();//LED處理函數(shù)
  32. void  judge_s1();//S1按鍵處理函數(shù)
  33. void  judge_s2();//S2按鍵處理函數(shù)
  34. void  judge_s3();//S3按鍵處理函數(shù)
  35. void  dis(uchar s6,uchar s5,uchar s4,uchar s3,uchar s2,uchar s1);//顯示子程序
  36. void  dis_san(uchar s6,uchar s5,uchar s4,uchar s3,uchar s2,uchar s1,uchar san);//閃爍顯示子程序
  37. void  judge_dis();//顯示處理函數(shù)
  38. void  judge_clock();//顯示處理函數(shù)
  39. void  set_ds1302();//設(shè)置時(shí)間
  40. void  get_ds1302();//讀取當(dāng)前時(shí)間

  41. void  w_1byte_ds1302(uchar t);//向DS1302寫一個(gè)字節(jié)的數(shù)據(jù)
  42. uchar r_1byte_ds1302();//從DS1302讀一個(gè)字節(jié)的數(shù)據(jù)
  43. //***********************************************************************
  44. //DS18B20測(cè)溫函數(shù)定義
  45. void w_1byte_ds18b20(uchar value);//向DS18B20寫一個(gè)字節(jié)
  46. uchar r_1byte_ds18b20(void);//從DS18B20讀取一個(gè)字節(jié)的數(shù)據(jù)
  47. void rest_ds18b20(void);//DS18B20復(fù)位程序
  48. void readtemp_ds18b20(void);//讀取溫度
  49. void dis_temp();//溫度顯示函數(shù)




  50. //共陽數(shù)碼管斷碼表
  51. const uchar tabl1[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
  52.                        // 0  1    2    3    4    5
  53.                        0x82,0xf8,0x80,0x90,0x86,0x87,0xFF,
  54.                        //6   7     8    9     E    T   B
  55.                        0xc6,0xbf,0xff};
  56.                         //    C      -
  57. const uchar tabl3[]={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09};
  58. uchar t0_crycle;
  59. uchar hour_count,minute_count,second_count,msecond_count;
  60. uchar clock_hour,clock_minute;
  61. uchar countdown_second;
  62. uchar countdown_hour,countdown_minute;
  63. uchar clock_en;//鬧鐘關(guān)閉和開啟的標(biāo)志,1開啟,0關(guān)閉
  64. uchar flag1,second_flag,zancun1,zancun2,zancun3;
  65. uchar zancun4,zancun5,zancun6,zancun7;
  66. uchar clock_flag,countdown_flag;
  67. uchar msecond_minute,msecond_second,msecond_msecond,msecond_flag;//秒表相關(guān)參數(shù)
  68. uint  speak_count;
  69. uchar templ,temph,temp_flag;
  70. uchar  t_b,t_s,t_g,t_x,temp_flag2;//從左到右分別存儲(chǔ)溫度百位,十位,個(gè)位,小數(shù)位
  71. uchar tab23[3];//={0x40,0x59,0x23,0x28,0x11,0x06,0x09};//上電時(shí)默認(rèn)的時(shí)間
  72. //主程序
  73. void main()
  74. {
  75.     P3=0x00;
  76.     flag1=0;   
  77.     zancun3=0;
  78.     msecond_minute=0;//置秒表相關(guān)參數(shù)為0
  79.     msecond_second=0;
  80.     msecond_msecond=0;
  81.     speak=1;//關(guān)閉蜂鳴器
  82.     speak_count=0;
  83.     clock_hour=0;
  84.     clock_minute=0;
  85.     clock_flag=0;
  86.     countdown_flag=0;//倒計(jì)時(shí)標(biāo)志位為0
  87.     clock_en=0;//開機(jī)時(shí)默認(rèn)關(guān)閉鬧鐘
  88.     init_t0();
  89.     TR0=1;//

  90.    // set_ds1302();//設(shè)置DS1302的初始時(shí)間
  91.    //接下來開始編寫讓數(shù)碼管顯示的程序
  92.     while(1)
  93.     {
  94.       get_ds1302();
  95.       judge_dis();//顯示處理
  96.       judge_s1();
  97.       judge_s2();
  98.       judge_s3();
  99.       judge_clock();//鬧鐘處理程序
  100.     }
  101. }
  102. void timer0() interrupt 1
  103. {
  104.         TH0=(65536-50000)/256;
  105.         TL0=(65536-50000)%256;
  106.         t0_crycle++;
  107.         if(t0_crycle==2)// 0.1秒
  108.         {
  109.           t0_crycle=0;
  110.       msecond_flag=1;
  111.           msecond_count++;
  112.       if(msecond_count==10)//1秒
  113.       {
  114.         msecond_count=0;
  115.         second_flag=1;
  116.       }   
  117.         }
  118. }
  119. //**************************************************
  120. //顯示處理函數(shù)
  121. void  judge_dis()
  122. {     
  123.     if(flag1==0)
  124.     {
  125.      if(second_flag==1)
  126.       {
  127.         zancun7++;
  128.         second_flag=0;
  129.       }
  130.       if(zancun7<1)
  131.       {
  132.         if(temp_flag2==1)
  133.         {
  134.           readtemp_ds18b20();//讀取溫度  
  135.           temp_flag2=0;
  136.         }
  137.         dis_temp();//溫度顯示函數(shù)
  138.       }
  139.      if(zancun7>=1)
  140.       {

  141.          temp_flag2=1;
  142.          zancun4=hour_count&0xf0;
  143.          zancun4>>=4;
  144.          zancun5=minute_count&0xf0;
  145.          zancun5>>=4;
  146.          zancun6=second_count&0xf0;
  147.          zancun6>>=4;
  148.          dis(zancun4,hour_count&0x0f,zancun5,minute_count&0x0f,zancun6,second_count&0x0f);
  149.          dis_led();
  150.          if(zancun7==5)zancun7=0;
  151. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼


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

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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