久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

MSP430單片機(jī)的實時時鐘及溫度顯示程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:395176 發(fā)表于 2019-4-14 09:23 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
最近學(xué)習(xí)MSP430,把以前學(xué)習(xí)的DS1302和DB18B20移植過來了,把時序搞清楚還是比較簡單的,溫度顯示做得比較粗糙,分享一下(PS:后續(xù)有時間添加按鍵設(shè)置及其他功能


單片機(jī)源程序如下:
  1. #include<msp430x14x.h>
  2. #include"lcd1602.c"
  3. #include"ds1302.c"
  4. #include"ds18b20.c"
  5. //typedef unsigned char uchar;
  6. //typedef unsigned int uint;
  7. //uchar str1[]="hongchao12345678";
  8. //uchar str2[]="hongchao12345678";
  9. //uchar LcdMove[16+sizeof(str1)+16];
  10. uchar index=0,T500MSfg=0,flash=0;
  11. uchar psec=0xaa;
  12. uchar time[8],str[12];
  13. //uchar second=10,minute=20,hour=11;
  14. /*
  15. void Lcd_Move()
  16. {
  17.     uchar i;
  18.     for(i=0;i<16;i++)
  19.     {
  20.         LcdMove[i]=' ';
  21.     }
  22.     for(i=0;i<sizeof(str1);i++)
  23.     {
  24.         LcdMove[16+i]=str1[i];
  25.     }
  26.     for(i=16+sizeof(str1);i<sizeof(LcdMove);i++)
  27.     {
  28.         LcdMove[i]=' ';
  29.     }
  30. }
  31. */
  32. void Time0_Init()
  33. {
  34.     TACTL=TASSEL_1+ ID_3+ MC_1;
  35.     CCTL0=CCIE;
  36.     CCR0=1024;

  37. }
  38. /*
  39. void clock()
  40. {
  41.      second++;
  42.      if(second>59)
  43.      {
  44.             second=0;
  45.             minute++;
  46.             if(minute>59)
  47.             {
  48.                   minute=0;
  49.                   hour++;
  50.             }
  51.      }
  52. }
  53. void Display()
  54. {
  55.       uchar s0,s1;
  56.       uchar m0,m1;
  57.       uchar h0,h1;
  58.       s0=second/10;
  59.       s1=second%10;
  60.       m0=minute/10;
  61.       m1=minute%10;
  62.       h0=hour/10;
  63.       h1=hour%10;
  64.       s0+=0x30;
  65.       s1+=0x30;

  66.       m0+=0x30;
  67.       m1+=0x30;

  68.       h0+=0x30;
  69.       h1+=0x30;
  70.        LcdShowStr1(4,0,h0);
  71.        LcdShowStr1(5,0,h1);
  72.        LcdShowStr1(7,0,m0);
  73.        LcdShowStr1(8,0,m1);
  74.        LcdShowStr1(10,0,s0);
  75.        LcdShowStr1(11,0,s1);
  76. }
  77. */
  78. void DS1302_Time()
  79. {
  80.                         //for(index=0; index<7; index++)
  81.                         //{
  82.                                 //time[index] = DS1302SingleRead(index);
  83.                         DS1302BurstRead(time);
  84.                         //}
  85.                         if(psec != time[0])
  86.                         {
  87.                                 str[0] = '2';
  88.                                 str[1] = '0';
  89.                                 str[2] = (time[6] >> 4) + 0x30;
  90.                                 str[3] = (time[6] & 0x0F) + 0x30;
  91.                                 str[4] = '-';
  92.                                 str[5] = (time[4] >> 4) + 0x30;
  93.                                 str[6] = (time[4] & 0x0F) + 0x30;
  94.                                 str[7] = '-';
  95.                                 str[8] = (time[3] >> 4) + 0x30;
  96.                                 str[9] = (time[3] & 0x0F) + 0x30;
  97.                                 str[10] = '\0';
  98.                                 LcdShowStr(0, 0, str);

  99.                                 str[0] = (time[5] & 0x0F) + 0x30;
  100.                                 str[1] = '\0';
  101.                                 LcdShowStr(11, 0, "WEEK");
  102.                                 LcdShowStr(15, 0, str);

  103.                                 str[0] = (time[2] >> 4) + 0x30;
  104.                                 str[1] = (time[2] & 0x0F) + 0x30;
  105.                                 str[2] = ':';
  106.                                 str[3] = (time[1] >> 4) + 0x30;
  107.                                 str[4] = (time[1] & 0x0F) + 0x30;
  108.                                 str[5] = ':';
  109.                                 str[6] = (time[0] >> 4) + 0x30;
  110.                                 str[7] = (time[0] & 0x0F) + 0x30;
  111.                                 str[8] = '\0';
  112.                                 LcdShowStr(8, 1, str);

  113.                                 psec = time[0];
  114.                         }
  115. }
  116. void DS18b20_Temp()
  117. {
  118.     uchar ack;
  119.     uchar num0,num1;
  120.     int temp=0;
  121.     // ack=DS_Ready();
  122.     ack=GetTemp(&temp);
  123.     if(ack==0)
  124.     {
  125.         num1=temp>>4;
  126.        // num2=temp<<4;
  127.        // num2=num2>>4;
  128.         num0=num1/10+0x30;
  129.         num1=num1%10+0x30;
  130.        // num2=num2%10+0x30;
  131.         LcdShowStr1(0,1,'T');
  132.         LcdShowStr1(1,1,'H');
  133.         LcdShowStr1(2,1,' ');
  134.         LcdShowStr1(3,1,num0);
  135.         LcdShowStr1(4,1,num1);
  136.       //  LcdShowStr1(5,1,'.');
  137.      //   LcdShowStr1(6,1,num2);

  138.     }
  139.     else
  140.     {
  141.       // LcdShowStr1(0,1,'E');
  142.       // LcdShowStr1(1,1,'R');
  143.       // LcdShowStr1(2,1,'R');
  144.       // LcdShowStr1(3,1,'0');
  145.       // LcdShowStr1(4,1,'R');
  146.        LcdShowStr(0,1,"ERR0R");
  147.     }
  148.     DSStart();
  149. }
  150. void main()
  151. {
  152.       /*下面六行程序關(guān)閉所有的IO口*/
  153.     P1DIR = 0XFF;P1OUT = 0XFF;
  154.     P2DIR = 0XFF;P2OUT = 0XFF;
  155.     P3DIR = 0XFF;P3OUT = 0XFF;
  156.     P4DIR = 0XFF;P4OUT = 0XFF;
  157.     P5DIR = 0XFF;P5OUT = 0XFF;
  158.     P6DIR = 0XFF;P6OUT = 0XFF;
  159.    // uchar i;
  160.     WDTCTL = WDTPW + WDTHOLD;
  161.     InitLcd1602();
  162.   //  TACTL=TASSEL_2;
  163.    // Lcd_Move();
  164.     Time0_Init();    //定時器使用32768,250ms
  165.     DS1302_Init();
  166.     DSStart();
  167.     _EINT();
  168.    // LcdShowStr(0,1," CLOCK  TIME ");
  169.   //  LcdShowStr1(6,0,':');
  170.   //  LcdShowStr1(9,0,':');
  171.    // LcdShowStr(0,0,"   :   :   ")
  172.     while(1)
  173.     {
  174.        //  LcdShowStr(1,0,"w23123123!");
  175.         // LcdShowStr(0,1,"hongchao 123");
  176.             if(flash)
  177.             {
  178.                   flash=0;
  179.                   DS1302_Time();
  180.                  DS18b20_Temp();
  181.                  // LcdShowStrLen(1,0,LcdMove+index,16);
  182.                  // index++;
  183.                   //if(index>sizeof(LcdMove))
  184.                 //  {
  185.                 //        index=0;
  186.                  // }
  187.                //   Display();
  188.            }
  189.     }

  190. }
  191. #pragma vector =TIMERA0_VECTOR
  192. __interrupt void TIME_A()
  193. {
  194.      // T500MSfg++;
  195.       flash=1;
  196.       //if(T500MSfg>2)
  197.      // {
  198.        // T500MSfg=0;
  199.       //  flash=1;
  200.        // clock();
  201.      // }
  202. }
復(fù)制代碼

全部資料51hei下載地址:
demo.zip (54.25 KB, 下載次數(shù): 46)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

沙發(fā)
ID:243174 發(fā)表于 2019-4-14 22:34 | 只看該作者
非常不錯,謝謝分享
回復(fù)

使用道具 舉報

板凳
ID:413728 發(fā)表于 2019-4-19 14:41 | 只看該作者
謝謝分享
回復(fù)

使用道具 舉報

地板
ID:541533 發(fā)表于 2019-5-23 18:35 | 只看該作者
作者請問

在運行你這個程序后出現(xiàn)這個怎么解決啊    function"get Temp"declared implicitly
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 国产精品一区在线观看你懂的 | 欧美福利影院 | 九九热精品在线视频 | 日韩欧美在线免费观看 | 久久精品色欧美aⅴ一区二区 | 有码一区| 欧美一区二区三区视频在线播放 | 日韩视频在线一区 | 亚洲综合色自拍一区 | m豆传媒在线链接观看 | 天天插天天操 | 91免费电影| 久久久久国产精品 | 黄色一级大片在线免费看产 | 蜜桃一区二区三区在线 | 日韩精品一区在线 | 亚洲国产成人av好男人在线观看 | 国产精久久久久久久 | 亚洲欧美日韩在线不卡 | 国产精品久久久久久中文字 | 亚洲福利一区二区 | 国产精品亚洲综合 | 综合九九 | 中文字幕在线观看视频一区 | 在线观看免费黄色片 | 亚洲国产精品一区二区三区 | 日韩视频a| 三极网站 | av网站免费观看 | 欧美一区二区三区视频 | 国产在线a| 日韩福利 | 精品一区av | 欧美成人综合 | 久久久久久久久99 | 久久久久亚洲精品 | 四季久久免费一区二区三区四区 | 久热伊人 | 欧美网站一区二区 | 欧美性生交大片免费 | 九九热精品在线 |