本帖最后由 muyichuan2012 于 2021-1-6 11:22 编辑
XMC 8080驱动 LCDAT32F403A作为主控芯片
主频200MHz
GUI: LittlevGL V7
显示效果:
视频链接:点我
/**
**************************************************************************
* @file : EXTI/EXTI_Config/main.c
* @author : Artery Technology
* @version : V1.0.4
* @date : 2020-09-28
* @brief : Main program body
*/
/* Includes ------------------------------------------------------------------*/
#ifdef CHOSE_LCD9341
#include "xmc_lcd_9341.h"
#endif
#ifdef CHOSE_LCD5510
#include "xmc_lcd_5510.h"
#endif
#include "at32f4xx.h"
#include "at32_board.h"
#include <stdio.h>
#include "lvgl.h"
#ifdef CHOSE_LCD9341
#include "xmc_lcd_9341.h"
#endif
#ifdef CHOSE_LCD5510
#include "xmc_lcd_5510.h"
#endif
#include "touch.h"
#include "iwdg.h"
#include "lv_port_disp_template.h"
#include "lv_port_indev_template.h"
#include "../lvgl.h"
#include <stdio.h>
#include <stdlib.h>
#include "lv_test_core/lv_test_core.h"
#include "task_breathing_led.h"
/** @addtogroup AT32F413_StdPeriph_Examples
* @{
*/
/** @addtogroup EXTI_Config
* @{
*/
/* Define External SPI flash unlock key --------------------------------------*/
#define FLASH_KEY1 ((UINT32)0x45670123)
#define FLASH_KEY2 ((UINT32)0xCDEF89AB)
#define FLASH_BANK3_TYPE1 1
#define FLASH_BANK3_TYPE2 2
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void TRM3_Int_Init(u16 arr, u16 psc);
void TRM2_Int_Init(u16 arr, u16 psc);
/**
* @brief Configures the ext.flash
* @param None
* @retval None
*/
void FLASH_InitExtFlash(void)
{
GPIO_InitType GPIO_InitStructure;
/* Enable ext.flash GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_AFIO|RCC_APB2PERIPH_GPIOA|RCC_APB2PERIPH_GPIOB, ENABLE);
GPIO_PinsRemapConfig(GPIO_Remap_XMC_NADV,ENABLE);
/* Configure ext.flash pin */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_8;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_1|GPIO_Pins_6|GPIO_Pins_7|GPIO_Pins_10|GPIO_Pins_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Select PB10, PB11 as SPIF_TX and SPIF_RX */
GPIO_PinsRemapConfig(GPIO_Remap_EXT_FLASH, ENABLE);
GPIO_PinsRemapConfig(AFIO_MAP7_SPIF_1001, ENABLE);
/* In this example, use on-board EN25QH128A as ext.flash */
FLASH->B3SEL = FLASH_BANK3_TYPE2;
/* Unlock the ext.flash program erase controller */
while (BIT_READ(FLASH->STS3, FLASH_STS_BSY));
FLASH->FCKEY3 = FLASH_KEY1;
FLASH->FCKEY3 = FLASH_KEY2;
while (BIT_READ(FLASH->CTRL3, FLASH_CTRL_LCK));
/* If the data written to ext.flash need to be scrambled, please specify the scrambled range */
FLASH->DA = 0;
return;
}
/**
* @brief main function
* @param None
* @retval None
*/
int main(void)
{
//初始化SPIM 用于存放图片字体等大文件
FLASH_InitExtFlash();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
//Initialize LED 、KEY、USART1
AT32_Board_Init();
UART_Print_Init(115200);
printf("init ok\r\n");
//用于防呆
// IWDG_init();
//初始化LCD
LCD_init();
// 2400000/(999+1)/(239+1)=1 KHz操作lv_tick_inc each 1 ms
TRM3_Int_Init(999, 239);
//刷lv_task_handler
TRM2_Int_Init(99, 239);
//初始化lvgl
lv_init();
lv_port_disp_init();
lv_port_indev_init();
//调用呼吸灯任务
task_breathing_led();
//调用数字显示任务
task_font();
//调用电池进度显示任务
task_battery();
while (1)
{
}
}
void TRM3_Int_Init(u16 arr, u16 psc)
{
TMR_TimerBaseInitType TMR_TimeBaseStructure;
NVIC_InitType NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR3, ENABLE);
TMR_TimeBaseStructure.TMR_Period = arr;
TMR_TimeBaseStructure.TMR_DIV = psc;
TMR_TimeBaseStructure.TMR_ClockDivision = TMR_CKD_DIV1;
TMR_TimeBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;
TMR_TimeBaseInit(TMR3, &TMR_TimeBaseStructure);
TMR_INTConfig(TMR3, TMR_INT_Overflow, ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = TMR3_GLOBAL_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TMR_Cmd(TMR3, ENABLE);
}
void TMR3_GLOBAL_IRQHandler(void)
{
if(TMR3->STS&0X0001)
{
TMR3->STS&=~(1<<0);
lv_tick_inc(1);
// IWDG->KEY = (uint16_t)0xAAAA; //喂狗 用于防呆
}
}
void TRM2_Int_Init(u16 arr, u16 psc)
{
TMR_TimerBaseInitType TMR_TimeBaseStructure;
NVIC_InitType NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR2, ENABLE);
TMR_TimeBaseStructure.TMR_Period = arr;
TMR_TimeBaseStructure.TMR_DIV = psc;
TMR_TimeBaseStructure.TMR_ClockDivision = TMR_CKD_DIV1;
TMR_TimeBaseStructure.TMR_CounterMode = TMR_CounterDIR_Up;
TMR_TimeBaseInit(TMR2, &TMR_TimeBaseStructure);
TMR_INTConfig(TMR2, TMR_INT_Overflow, ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = TMR2_GLOBAL_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TMR_Cmd(TMR2, ENABLE);
}
void TMR2_GLOBAL_IRQHandler(void)
{
TMR2->STS&=~(1<<0);
lv_task_handler();
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2018 ArteryTek *****END OF FILE****/
|