简单的时间显示,时间可以在x 0-127 y 0-63任意地方显示,图形都是覆盖显示不会擦除原有的图案,还有一个简单的时钟动画
单片机源程序如下:
- #include "main.h"
- #include "FT32f0xx.h"
- #include "FT32f0xx_gpio.h"
- #include "FT32f0xx_syscfg.h"
- #include "FT32f0xx_rcc.h"
- #include "FT32f0xx_iwdg.h"
- #include "core_cm0.h"
- #include "delay.h"
- #include "timer.h"
- #include "gpio.h"
- #include "exti.h"
- #include "uart.h"
- #include "pwm.h"
- #include "ad.h"
- #include "IIC.h"
- #include "SPI.h"
- #include "OLEDDriver.h"
- #include "OLEDDraw.h"
- #include "stdio.h"
- #include "string.h"
- #include "OLED_TIME.h"
- #include "OLED_TIMEString.h"
- #include "pul.h"
- #include "OLED.h"
- /* Private functions ---------------------------------------------------------*/
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
- //独立看门狗
- //prescaler---0~0x06--IWDG_Prescaler_x---x=4,8,16,32,64,128,256
- //reload---0~0x0FFF
- //reset time=reload*prescaler/40KHZ(ms)
- void iwdg_init(uint8_t prescaler,uint16_t reload)
- {
- //LSI 40KHZ for IWDG
- RCC_LSICmd(ENABLE);
-
- //write KR=0x5555---enable write PR or RLR
- IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
- //write PR
- IWDG_SetPrescaler(prescaler);
- //write RLR 0~0x0FFF
- IWDG_SetReload(reload);
-
- //reload write KR 0xAAAA
- IWDG_ReloadCounter();
-
- //enable IWDG write KR 0xCCCC
- IWDG_Enable();
- }
- //uint8_t Flag = 0;
- //uint16_t Count = 0;
- uint8_t gAddMode = 0;
- //uint8_t gCountTrisFlag = 0;
- Cube Adress1,Adress2;
- uint8_t AdressX,AdressY;
- uint8_t AdressX2,AdressY2;
- int main(void)
- {
- SYSCFG_DeInit();
- SystemInit();//48MHZ
-
- RCC_HCLKConfig(RCC_SYSCLK_Div1);//AHB clock 48MHZ APBH1CLK = PLLCLOCK * 1 = 48MHZ * 1 = 48MHZ
- //APB分频为1时 timerx时钟时APB时钟 否则timerx时钟是APB时钟的2倍频
- RCC_PCLKConfig(RCC_HCLK_Div1);//APB clock 48MHZ
-
- //以HCLK作时钟源48MHZ
- //48000000/1000---1ms
- //48000000/100000---10us
- //48000000/1000000---1us
- while(SysTick_Config(48000000/100000)){}
- Time6Init(124,0);
- SET_GPIO_Out_PP(GPIOC,GPIO_Pin_13);
- SET_GPIO_Out_PP(GPIOC,GPIO_Pin_14);
-
- SET_GPIO_Out_PP(GPIOB,GPIO_Pin_13);
- SET_GPIO_Out_PP(GPIOA,GPIO_Pin_5);
-
- GPIO_ResetBits(GPIOB,GPIO_Pin_13);
- GPIO_ResetBits(GPIOA,GPIO_Pin_5);
-
- SET_GPIO_Out_PP(GPIOA,GPIO_Pin_2);
- GPIO_ResetBits(GPIOA,GPIO_Pin_2);
- SPI1_INIT(GPIOA,GPIO_Pin_4,GPIOA, GPIO_Pin_5,GPIOA, GPIO_Pin_6,GPIOA, GPIO_Pin_7);
- OLED_Init();
-
- memset(BMP1,0x00,sizeof(BMP1));
- DrawPic(BMP1[0]);
- AdressX = 0;
- AdressY = 16;
- AdressX2 = 67-32;
- AdressY2 = 63-32;
- while (1)
- {
- if(gFlashCount >= 256)
- {
- gFlashCount = 0;
-
- // DrawNumber1(0,2,NumberTable[12],TestTable[0]);
-
- DrawTime((uint8_t)(gTime / 3600),(uint8_t)(gTime % 3600 / 60),(uint8_t)(gTime % 60),97,32,30);
-
- DrawNumber(0,0,NumberTable[(gTime / 3600) / 10],BMP1[0]);
- DrawNumber(8,0,NumberTable[(gTime / 3600) % 10],BMP1[0]);
- DrawNumber(16,0,NumberTable[10],BMP1[0]);
- DrawNumber(24,0,NumberTable[(gTime % 3600 / 60) / 10],BMP1[0]);
- DrawNumber(32,0,NumberTable[(gTime % 3600 / 60) % 10],BMP1[0]);
- DrawNumber(40,0,NumberTable[10],BMP1[0]);
- DrawNumber(48,0,NumberTable[(gTime % 60) / 10],BMP1[0]);
- DrawNumber(56,0,NumberTable[(gTime % 60) % 10],BMP1[0]);
-
- Adress1 = DrawSquare(AdressX2,AdressY2,(AdressX2 + 32),(AdressY2 + 32));
- Adress2 = DrawSquare(AdressX,AdressY,(AdressX + 32),(AdressY + 32));
- DrawCube(Adress1,Adress2);
- if(gAddMode == 0)
- {
- if(AdressX < (67 - 32))
- {
- AdressX++;
- AdressX2--;
- }
- else
- {
- gAddMode = 1;
- }
- }
- else if(gAddMode == 1)
- {
- if(AdressY < (63 - 32))
- {
- AdressY++;
- AdressY2--;
- }
- else
- {
- gAddMode = 2;
- }
- }
- else if(gAddMode == 2)
- {
- if(AdressX > 0)
- {
- AdressX--;
- AdressX2++;
- }
- else
- {
- gAddMode = 3;
- }
- }
- else if(gAddMode == 3)
- {
- if(AdressY > 16)
- {
- AdressY--;
- AdressY2++;
- }
- else
- {
- gAddMode = 0;
- }
- }
-
- DrawPic(BMP1[0]);
- }
- }
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
Keil代码51hei附件下载:
OLED时钟.7z
(179.01 KB, 下载次数: 20)
|