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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3021|回復: 1
打印 上一主題 下一主題
收起左側

基于STM32的指示式電子時鐘源碼

[復制鏈接]
跳轉到指定樓層
樓主
ID:417567 發表于 2018-10-29 21:23 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
基于STM32的指示式電子時鐘

單片機源程序如下:
  1. #include "system.h"
  2. #include "SysTick.h"
  3. #include "led.h"
  4. #include "usart.h"
  5. #include "tftlcd.h"
  6. #include "rtc.h"
  7. #include "math.h"


  8. #define PI 3.1415926
  9. void get_circle(int x,int y,int r,int col)
  10. {
  11.         int xc=0;
  12.         int yc,p;
  13.         yc=r;
  14.         p=3-(r<<1);       
  15.         while(xc <= yc)
  16.         {
  17.                 LCD_DrawFRONT_COLOR(x+xc,y+yc,col);
  18.                 LCD_DrawFRONT_COLOR(x+xc,y-yc,col);       
  19.                 LCD_DrawFRONT_COLOR(x-xc,y+yc,col);
  20.                 LCD_DrawFRONT_COLOR(x-xc,y-yc,col);
  21.                 LCD_DrawFRONT_COLOR(x+yc,y+xc,col);       
  22.                 LCD_DrawFRONT_COLOR(x+yc,y-xc,col);
  23.                 LCD_DrawFRONT_COLOR(x-yc,y+xc,col);
  24.                 LCD_DrawFRONT_COLOR(x-yc,y-xc,col);
  25.                 if(p<0)
  26.                 {
  27.                         p += (xc++ << 2) + 6;       
  28.                 }
  29.                 else
  30.                         p += ((xc++ - yc--)<<2) + 10;
  31.         }
  32. }
  33. void draw_circle()         //畫圓
  34. {
  35.         get_circle(100,200,100,YELLOW);
  36.         get_circle(100,200,99,YELLOW);
  37.         get_circle(100,200,98,YELLOW);
  38.         get_circle(100,200,97,YELLOW);
  39.         get_circle(100,200,5,YELLOW);                       
  40. }
  41. void draw_dotline()  //畫格點
  42. {
  43.         u8 i;
  44.         u8 rome[][3]={"12","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11" } ; //表盤數字
  45.         int x1,y1,x2,y2,x3,y3;
  46.         for(i=0;i<60;i++)
  47.         {
  48.                 x1 = (int)(100 + (sin(i * PI / 30) * 92));
  49.                 y1 = (int)(100 - (cos(i * PI / 30) * 92));
  50.                 x2 = (int)(100 + (sin(i * PI / 30) * 97));
  51.                 y2 = (int)(100 - (cos(i * PI / 30) * 97));
  52.                 FRONT_COLOR=RED;
  53.                 LCD_DrawLine(x1,y1+100,x2,y2+100);

  54.                 if(i%5==0)
  55.                 {
  56.                         x1 = (int)(100 + (sin(i * PI / 30) * 85));
  57.                         y1 = (int)(100 - (cos(i * PI / 30) * 85));
  58.                         x2 = (int)(100 + (sin(i * PI / 30) * 97));
  59.                         y2 = (int)(100 - (cos(i * PI / 30) * 97));
  60.                         LCD_DrawLine(x1,y1+100,x2,y2+100);       

  61.                         x3 = (int)(92 + (sin((i ) * PI / 30) * 80));
  62.                         y3 = (int)(92 - (cos((i ) * PI / 30) * 80));
  63.                         FRONT_COLOR=YELLOW;
  64.                         LCD_ShowString(x3,y3+100,tftlcd_data.width,tftlcd_data.height,16,rome[i/5]);
  65.                        
  66.                 }
  67.                
  68.         }               
  69. }
  70. void draw_hand(int hhour,int mmin,int ssec)  //畫指針
  71. {
  72.         int xhour, yhour, xminute, yminute, xsecond, ysecond; //表心坐標系指針坐標
  73.         xhour = (int)(60 * sin( hhour * PI / 6 + mmin * PI / 360 + ssec * PI / 1800));
  74.         yhour = (int)(60 * cos( hhour * PI / 6 + mmin * PI / 360 + ssec * PI / 1800));
  75.         xminute = (int)(90 * sin( mmin * PI / 30 + ssec * PI / 1800));
  76.         yminute = (int)(90 * cos( mmin * PI / 30 + ssec * PI / 1800));
  77.         xsecond = (int)(100 * sin( ssec * PI / 30));
  78.         ysecond = (int)(100 * cos( ssec * PI / 30));

  79.         FRONT_COLOR=RED;
  80.         LCD_DrawLine(100 + xhour, 200 - yhour, 100 -xhour / 6, 200 + yhour / 6);
  81.         FRONT_COLOR=BLUE;
  82.         LCD_DrawLine(100 + xminute, 200 - yminute, 100 -xminute / 4, 200 + yminute / 4);
  83.         FRONT_COLOR=GREEN;
  84.         LCD_DrawLine(100 + xsecond, 200 - ysecond, 100 -xsecond / 3, 200 + ysecond / 3);
  85.        
  86. }
  87. void draw_hand_clear(int hhour,int mmin,int ssec)  //擦指針
  88. {
  89.         int xhour, yhour, xminute, yminute, xsecond, ysecond; //表心坐標系指針坐標
  90.         xhour = (int)(60 * sin( hhour * PI / 6 + mmin * PI / 360 + ssec * PI / 1800));
  91.         yhour = (int)(60 * cos( hhour * PI / 6 + mmin * PI / 360 + ssec * PI / 1800));
  92.         xminute = (int)(90 * sin( mmin * PI / 30 + ssec * PI / 1800));
  93.         yminute = (int)(90 * cos( mmin * PI / 30 + ssec * PI / 1800));
  94.         xsecond = (int)(100 * sin( ssec * PI / 30));
  95.         ysecond = (int)(100 * cos( ssec * PI / 30));

  96.         FRONT_COLOR=BLACK;
  97.         LCD_DrawLine(100 + xhour, 200 - yhour, 100 -xhour / 6, 200 + yhour / 6);
  98.         LCD_DrawLine(100 + xminute, 200 - yminute, 100 -xminute / 4, 200 + yminute / 4);
  99.         LCD_DrawLine(100 + xsecond, 200 - ysecond, 100 -xsecond / 3, 200 + ysecond / 3);
  100.        
  101. }

  102. int main()
  103. {
  104.         u8 buf[10];
  105.        
  106.         SysTick_Init(72);
  107.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  //中斷優先級分組 分2組
  108.         LED_Init();
  109.         USART1_Init(9600);
  110.         TFTLCD_Init();                        //LCD初始化
  111.        
  112.         LCD_Clear(BLACK);
  113.         FRONT_COLOR=YELLOW;
  114.         BACK_COLOR=BLACK;
  115.         LCD_ShowString(10,10,tftlcd_data.width,tftlcd_data.height,16,"This is a RTC text!");
  116.         RTC_Init();
  117.         draw_circle();
  118.         draw_dotline();
  119.        
  120.         while(1)
  121.         {
  122.                 if(timebz==1)
  123.                 {
  124.                         draw_hand_clear(calendar.hour,calendar.min,calendar.sec);
  125.                         timebz=0;
  126.                         RTC_Get();
  127.                         sprintf((char *)buf,"%.2d:%.2d:%.2d",calendar.hour,calendar.min,calendar.sec);
  128.                         draw_hand(calendar.hour,calendar.min,calendar.sec);

  129.                 }
  130.                 draw_circle();
  131.                 draw_dotline();
  132.                 LCD_ShowString(80,50,tftlcd_data.width,tftlcd_data.height,16,buf);               
  133.         }                       
  134. }
復制代碼

所有資料51hei提供下載:
指針式電子時鐘.zip (679.84 KB, 下載次數: 45)


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

使用道具 舉報

沙發
ID:1 發表于 2018-10-31 01:09 | 只看該作者
補全原理圖或者詳細說明一下電路連接即可獲得100+黑幣
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久精品视频在线观看 | 国产精品久久午夜夜伦鲁鲁 | 日韩视频在线一区 | avtt国产 | 国产精品18久久久久久久 | 99免费视频 | 欧美亚洲综合久久 | 日本xx视频免费观看 | 91精品国产91久久久久游泳池 | 亚洲情侣视频 | 中文字幕日韩欧美 | 亚洲视频一区 | 99久久日韩精品免费热麻豆美女 | 精产国产伦理一二三区 | www.啪啪.com| 视频在线亚洲 | 精品福利视频一区二区三区 | 亚洲一区国产精品 | 亚洲欧美综合精品久久成人 | 久久毛片 | 成人伊人网 | 免费高清av| 91精品国产色综合久久不卡98口 | 亚州精品天堂中文字幕 | 国产精品久久久久久中文字 | 久久综合伊人 | 精品欧美乱码久久久久久 | 欧美性生活一区二区三区 | 亚洲国产专区 | 伊人网影院 | 国产在线播 | 日韩欧美天堂 | 日韩精品中文字幕一区二区三区 | 久久国产精品网站 | 久久精品亚洲精品 | 超碰网址| 日韩免费高清视频 | 少妇诱惑av | 午夜免费网站 | 欧美日韩国产在线观看 | 久久久久国 |