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

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

QQ登錄

只需一步,快速開始

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

基于STM32的指示式電子時(shí)鐘源碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:417567 發(fā)表于 2018-10-29 21:23 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
基于STM32的指示式電子時(shí)鐘

單片機(jī)源程序如下:
  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()  //畫格點(diǎn)
  42. {
  43.         u8 i;
  44.         u8 rome[][3]={"12","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11" } ; //表盤數(shù)字
  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; //表心坐標(biāo)系指針坐標(biāo)
  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; //表心坐標(biāo)系指針坐標(biāo)
  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);  //中斷優(yōu)先級(jí)分組 分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. }
復(fù)制代碼

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


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

使用道具 舉報(bào)

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

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 国产目拍亚洲精品99久久精品 | 99re6在线视频精品免费 | 亚洲电影第三页 | 在线观看国产视频 | 亚洲精品国产偷自在线观看 | 在线一区二区三区 | 亚洲综合色自拍一区 | 91 久久| 久久精品一 | 国产精品久久久久久久免费大片 | 日韩成人免费av | www网站在线观看 | 国产成人高清视频 | 国产精品www | 国产免费拔擦拔擦8x高清 | 中文字幕成人av | 日韩成人免费视频 | 毛片免费观看视频 | 黄色成人国产 | 中文字幕在线看 | 一区二区三区视频 | 午夜视频在线免费观看 | 精品二三区 | 99色综合 | 国内精品久久久久久久 | 国产成人精品免高潮在线观看 | 国产精品一区二区不卡 | 国产成人99久久亚洲综合精品 | 毛片一级黄色 | 国产精品爱久久久久久久 | 国内自拍视频在线观看 | 日日干夜夜操天天操 | 亚洲一区二区国产 | 九色在线| 一区二区免费视频 | 午夜影院黄 | 日本中文字幕一区 | 国产欧美一级二级三级在线视频 | 中文在线www| 欧美xxxx在线 | 一区二区三区高清 |