找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1989|回复: 0
打印 上一主题 下一主题
收起左侧

FT32单片机+0.96OLED显示几何图形与简单动画的时钟程序

[复制链接]
跳转到指定楼层
楼主
简单的时间显示,时间可以在x 0-127 y 0-63任意地方显示,图形都是覆盖显示不会擦除原有的图案,还有一个简单的时钟动画


单片机源程序如下:
  1. #include "main.h"
  2. #include "FT32f0xx.h"
  3. #include "FT32f0xx_gpio.h"
  4. #include "FT32f0xx_syscfg.h"
  5. #include "FT32f0xx_rcc.h"
  6. #include "FT32f0xx_iwdg.h"
  7. #include "core_cm0.h"

  8. #include "delay.h"
  9. #include "timer.h"
  10. #include "gpio.h"
  11. #include "exti.h"
  12. #include "uart.h"
  13. #include "pwm.h"
  14. #include "ad.h"
  15. #include "IIC.h"
  16. #include "SPI.h"

  17. #include "OLEDDriver.h"
  18. #include "OLEDDraw.h"
  19. #include "stdio.h"
  20. #include "string.h"
  21. #include "OLED_TIME.h"
  22. #include "OLED_TIMEString.h"
  23. #include "pul.h"
  24. #include "OLED.h"
  25. /* Private functions ---------------------------------------------------------*/
  26. /**
  27.   * @brief  Main program.
  28.   * @param  None
  29.   * @retval None
  30.   */



  31. //独立看门狗
  32. //prescaler---0~0x06--IWDG_Prescaler_x---x=4,8,16,32,64,128,256
  33. //reload---0~0x0FFF
  34. //reset time=reload*prescaler/40KHZ(ms)
  35. void iwdg_init(uint8_t prescaler,uint16_t reload)
  36. {
  37.         //LSI 40KHZ for IWDG
  38.         RCC_LSICmd(ENABLE);
  39.         
  40.         //write KR=0x5555---enable write PR or RLR
  41.         IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  42.         //write PR
  43.         IWDG_SetPrescaler(prescaler);
  44.         //write RLR 0~0x0FFF
  45.         IWDG_SetReload(reload);
  46.         
  47.         //reload write KR 0xAAAA
  48.         IWDG_ReloadCounter();
  49.         
  50.         //enable IWDG write KR 0xCCCC
  51.         IWDG_Enable();
  52. }



  53. //uint8_t Flag = 0;
  54. //uint16_t Count = 0;

  55. uint8_t gAddMode = 0;
  56. //uint8_t gCountTrisFlag = 0;
  57. Cube Adress1,Adress2;
  58. uint8_t AdressX,AdressY;
  59. uint8_t AdressX2,AdressY2;
  60. int main(void)
  61. {
  62.         SYSCFG_DeInit();
  63.         SystemInit();//48MHZ
  64.         
  65.         RCC_HCLKConfig(RCC_SYSCLK_Div1);//AHB clock 48MHZ   APBH1CLK = PLLCLOCK * 1 = 48MHZ * 1 = 48MHZ
  66.         //APB分频为1时 timerx时钟时APB时钟 否则timerx时钟是APB时钟的2倍频
  67.         RCC_PCLKConfig(RCC_HCLK_Div1);//APB clock  48MHZ
  68.         
  69.         //以HCLK作时钟源48MHZ
  70.         //48000000/1000---1ms
  71.         //48000000/100000---10us
  72.         //48000000/1000000---1us
  73.         while(SysTick_Config(48000000/100000)){}
  74.         Time6Init(124,0);
  75.         SET_GPIO_Out_PP(GPIOC,GPIO_Pin_13);
  76.         SET_GPIO_Out_PP(GPIOC,GPIO_Pin_14);
  77.                
  78.         SET_GPIO_Out_PP(GPIOB,GPIO_Pin_13);
  79.         SET_GPIO_Out_PP(GPIOA,GPIO_Pin_5);
  80.                
  81.         GPIO_ResetBits(GPIOB,GPIO_Pin_13);
  82.         GPIO_ResetBits(GPIOA,GPIO_Pin_5);
  83.                
  84.                 SET_GPIO_Out_PP(GPIOA,GPIO_Pin_2);
  85.                 GPIO_ResetBits(GPIOA,GPIO_Pin_2);
  86.         SPI1_INIT(GPIOA,GPIO_Pin_4,GPIOA, GPIO_Pin_5,GPIOA, GPIO_Pin_6,GPIOA, GPIO_Pin_7);
  87.         OLED_Init();
  88.                
  89.         memset(BMP1,0x00,sizeof(BMP1));
  90.         DrawPic(BMP1[0]);
  91.                 AdressX = 0;
  92.                 AdressY = 16;
  93.                 AdressX2 = 67-32;
  94.                 AdressY2 = 63-32;
  95.   while (1)
  96.   {
  97.                 if(gFlashCount >= 256)
  98.                 {
  99.                         gFlashCount = 0;               
  100.         
  101.         //                DrawNumber1(0,2,NumberTable[12],TestTable[0]);
  102.                         
  103.                         DrawTime((uint8_t)(gTime / 3600),(uint8_t)(gTime % 3600 / 60),(uint8_t)(gTime % 60),97,32,30);        
  104.                         
  105.                         DrawNumber(0,0,NumberTable[(gTime / 3600) / 10],BMP1[0]);
  106.                         DrawNumber(8,0,NumberTable[(gTime / 3600) % 10],BMP1[0]);
  107.                         DrawNumber(16,0,NumberTable[10],BMP1[0]);
  108.                         DrawNumber(24,0,NumberTable[(gTime % 3600 / 60) / 10],BMP1[0]);
  109.                         DrawNumber(32,0,NumberTable[(gTime % 3600 / 60) % 10],BMP1[0]);
  110.                         DrawNumber(40,0,NumberTable[10],BMP1[0]);
  111.                         DrawNumber(48,0,NumberTable[(gTime % 60) / 10],BMP1[0]);
  112.                         DrawNumber(56,0,NumberTable[(gTime % 60) % 10],BMP1[0]);
  113.                         
  114.                         Adress1 = DrawSquare(AdressX2,AdressY2,(AdressX2 + 32),(AdressY2 + 32));
  115.                         Adress2 = DrawSquare(AdressX,AdressY,(AdressX + 32),(AdressY + 32));
  116.                         DrawCube(Adress1,Adress2);
  117.                         if(gAddMode == 0)
  118.                         {
  119.                                 if(AdressX < (67 - 32))
  120.                                 {
  121.                                         AdressX++;
  122.                                         AdressX2--;
  123.                                 }
  124.                                 else
  125.                                 {
  126.                                         gAddMode = 1;
  127.                                 }
  128.                         }
  129.                         else if(gAddMode == 1)
  130.                         {
  131.                                 if(AdressY < (63 - 32))
  132.                                 {
  133.                                         AdressY++;
  134.                                         AdressY2--;
  135.                                 }
  136.                                 else
  137.                                 {
  138.                                         gAddMode = 2;
  139.                                 }
  140.                         }
  141.                         else if(gAddMode == 2)
  142.                         {
  143.                                 if(AdressX > 0)
  144.                                 {
  145.                                         AdressX--;
  146.                                         AdressX2++;
  147.                                 }
  148.                                 else
  149.                                 {
  150.                                         gAddMode = 3;
  151.                                 }
  152.                         }
  153.                         else if(gAddMode == 3)
  154.                         {
  155.                                 if(AdressY > 16)
  156.                                 {
  157.                                         AdressY--;
  158.                                         AdressY2++;
  159.                                 }
  160.                                 else
  161.                                 {
  162.                                         gAddMode = 0;
  163.                                 }
  164.                         }
  165.                         
  166.                         DrawPic(BMP1[0]);
  167.                 }
  168.   }
  169. }



  170. ……………………

  171. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

Keil代码51hei附件下载:
OLED时钟.7z (179.01 KB, 下载次数: 18)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表