共享一份資料,LCD彩色液晶屏顯示漢字、英文、數字的程序,適合初學者,單片機用STM32
單片機源程序如下:
- #include "pbdata.h"
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void NVIC_Configuration(void);
- void USART_Configuration(void);
- int fputc(int ch,FILE *f)
- {
- USART_SendData(USART1,(u8)ch);
- while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
- return ch;
- }
- int main(void)
- {
- u8 i=0;
- RCC_Configuration(); //系統時鐘初始化
- GPIO_Configuration();//端口初始化
- USART_Configuration();
- NVIC_Configuration();
- FSMC_Configuration();
- SSD1963_Init();
- delay_ms(1000);
- SSD1963_CLEAR(WHITE);
- for(i=0;i<4;i++)
- {
- Show_Font(30+i*50,50,i,RED,WHITE);
- }
-
- for(i=0;i<15;i++)
- {
- Show_Str(10+i*15,100,i,RED,WHITE);
- }
- while(1)
- {
- TFT_Draw_Rectangle(10,150,230,160,RED);
- delay_ms(200);
- TFT_Draw_Rectangle(10,150,230,160,BLUE);
- delay_ms(200);
- TFT_Draw_Rectangle(10,150,230,160,GREEN);
- delay_ms(200);
- }
- }
- void RCC_Configuration(void)
- {
- SystemInit();//72m
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);//使能FSMC接口時鐘
- }
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;//TX
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//RX
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- //FSMC 管腳初始化///////////
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //背光控制
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽輸出
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- GPIO_SetBits(GPIOD, GPIO_Pin_13); //打開背光
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //TFT 復位腳
- GPIO_Init(GPIOE, &GPIO_InitStructure);
-
- //啟用FSMC復用功能 設置為復用上拉
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 //D0
- | GPIO_Pin_15 //D1
- | GPIO_Pin_0 //D2
- | GPIO_Pin_1 //D3
- | GPIO_Pin_8 //D13
- | GPIO_Pin_9 //D14
- | GPIO_Pin_10 ;//D15
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//復用模式
- GPIO_Init(GPIOD, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 //D4
- | GPIO_Pin_8 //D5
- | GPIO_Pin_9 //D6
- | GPIO_Pin_10 //D7
- | GPIO_Pin_11 //D8
- | GPIO_Pin_12 //D9
- | GPIO_Pin_13 //D10
- | GPIO_Pin_14 //D11
- | GPIO_Pin_15;//D12
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 //RS
- | GPIO_Pin_4 //nOE
- | GPIO_Pin_5; //nWE
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //NE1
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- }
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- void USART_Configuration(void)
- {
- USART_InitTypeDef USART_InitStructure;
- USART_InitStructure.USART_BaudRate=9600;
- USART_InitStructure.USART_WordLength=USART_WordLength_8b;
- USART_InitStructure.USART_StopBits=USART_StopBits_1;
- USART_InitStructure.USART_Parity=USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
- USART_Init(USART1,&USART_InitStructure);
- USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
- USART_Cmd(USART1,ENABLE);
- USART_ClearFlag(USART1,USART_FLAG_TC);
- }
復制代碼
所有資料51hei提供下載:
Keil程序.7z
(1.03 MB, 下載次數: 40)
2022-10-10 04:13 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|