本帖最后由 jinglixixi 于 2020-12-18 00:52 编辑
为实现桌面式智能家居控制系统的设计,TFT显示屏的使用是不可或缺的。本已购置一块2.8寸的触摸屏,但由于时间的紧张只能暂时舍弃了。 就开发板所能直接使用的GPIO资源看,暂时将显示屏的连接关系指定为: CLK--- PH11 DIN--- PH12 RES--- PH13 DC --- PH15 CS--- PH7 BLK--- PH9
定义相关引脚输出高低电平的语句为: #define OLED_SCLK_Clr()HAL_GPIO_WritePin(GPIOH,GPIO_PIN_11,GPIO_PIN_RESET) //CLK #define OLED_SCLK_Set()HAL_GPIO_WritePin(GPIOH,GPIO_PIN_11,GPIO_PIN_SET)
#define OLED_SDIN_Clr()HAL_GPIO_WritePin(GPIOH,GPIO_PIN_12,GPIO_PIN_RESET) //DIN #define OLED_SDIN_Set()HAL_GPIO_WritePin(GPIOH,GPIO_PIN_12,GPIO_PIN_SET)
#define OLED_RST_Clr() HAL_GPIO_WritePin(GPIOH,GPIO_PIN_13,GPIO_PIN_RESET) //RES #define OLED_RST_Set() HAL_GPIO_WritePin(GPIOH,GPIO_PIN_13,GPIO_PIN_SET)
#define OLED_DC_Clr() HAL_GPIO_WritePin(GPIOH,GPIO_PIN_15,GPIO_PIN_RESET) //DC #define OLED_DC_Set() HAL_GPIO_WritePin(GPIOH,GPIO_PIN_15,GPIO_PIN_SET)
#define OLED_CS_Clr() HAL_GPIO_WritePin(GPIOH,GPIO_PIN_7,GPIO_PIN_RESET) //CS #define OLED_CS_Set() HAL_GPIO_WritePin(GPIOH,GPIO_PIN_7,GPIO_PIN_SET)
#define OLED_BLK_Clr() HAL_GPIO_WritePin(GPIOH,GPIO_PIN_9,GPIO_PIN_RESET) //BLK #define OLED_BLK_Set() HAL_GPIO_WritePin(GPIOH,GPIO_PIN_9,GPIO_PIN_SET)
配置相关引脚为输出功能的函数为: - void app_TFT_init(void)
- {
- GPIO_InitTypeDef GPIO_Initure;
- __HAL_RCC_GPIOH_CLK_ENABLE();
- GPIO_Initure.Pin=GPIO_PIN_7|GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_15;
- GPIO_Initure.Mode=GPIO_MODE_OUTPUT_PP;
- GPIO_Initure.Speed=GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOH,&GPIO_Initure);
- LCD_LED_High();
- }
复制代码
TFT显示屏的初始化函数为: - void Lcd_Init(void)
- {
- LCD_REST_Low();
- delay_ms(20);
- LCD_REST_High();
- delay_ms(20);
- LCD_CS_Low();
- LCD_WR_REG(0xCB);
- LCD_WR_DATA8(0x39);
- LCD_WR_DATA8(0x2C);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x34);
- LCD_WR_DATA8(0x02);
- LCD_WR_REG(0xCF);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0XC1);
- LCD_WR_DATA8(0X30);
- LCD_WR_REG(0xE8);
- LCD_WR_DATA8(0x85);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x78);
- LCD_WR_REG(0xEA);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x00);
- LCD_WR_REG(0xED);
- LCD_WR_DATA8(0x64);
- LCD_WR_DATA8(0x03);
- LCD_WR_DATA8(0X12);
- LCD_WR_DATA8(0X81);
- LCD_WR_REG(0xF7);
- LCD_WR_DATA8(0x20);
- LCD_WR_REG(0xC0);
- LCD_WR_DATA8(0x23);
- LCD_WR_REG(0xC1);
- LCD_WR_DATA8(0x10);
- LCD_WR_REG(0xC5);
- LCD_WR_DATA8(0x3e);
- LCD_WR_DATA8(0x28);
- LCD_WR_REG(0xC7);
- LCD_WR_DATA8(0x86);
- LCD_WR_REG(0x36);
- LCD_WR_DATA8(0x48);
- LCD_WR_REG(0x3A);
- LCD_WR_DATA8(0x55);
- LCD_WR_REG(0xB1);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x18);
- LCD_WR_REG(0xB6);
- LCD_WR_DATA8(0x08);
- LCD_WR_DATA8(0x82);
- LCD_WR_DATA8(0x27);
- LCD_WR_REG(0xF2);
- LCD_WR_DATA8(0x00);
- LCD_WR_REG(0x26);
- LCD_WR_DATA8(0x01);
- LCD_WR_REG(0xE0);
- LCD_WR_DATA8(0x0F);
- LCD_WR_DATA8(0x31);
- LCD_WR_DATA8(0x2B);
- LCD_WR_DATA8(0x0C);
- LCD_WR_DATA8(0x0E);
- LCD_WR_DATA8(0x08);
- LCD_WR_DATA8(0x4E);
- LCD_WR_DATA8(0xF1);
- LCD_WR_DATA8(0x37);
- LCD_WR_DATA8(0x07);
- LCD_WR_DATA8(0x10);
- LCD_WR_DATA8(0x03);
- LCD_WR_DATA8(0x0E);
- LCD_WR_DATA8(0x09);
- LCD_WR_DATA8(0x00);
- LCD_WR_REG(0XE1);
- LCD_WR_DATA8(0x00);
- LCD_WR_DATA8(0x0E);
- LCD_WR_DATA8(0x14);
- LCD_WR_DATA8(0x03);
- LCD_WR_DATA8(0x11);
- LCD_WR_DATA8(0x07);
- LCD_WR_DATA8(0x31);
- LCD_WR_DATA8(0xC1);
- LCD_WR_DATA8(0x48);
- LCD_WR_DATA8(0x08);
- LCD_WR_DATA8(0x0F);
- LCD_WR_DATA8(0x0C);
- LCD_WR_DATA8(0x31);
- LCD_WR_DATA8(0x36);
- LCD_WR_DATA8(0x0F);
- LCD_WR_REG(0x11);
- delay_ms(120);
- LCD_WR_REG(0x29);
- LCD_WR_REG(0x2c);
- }
复制代码
实现图标显示的函数为: - void show_tbh(unsigned int x,unsigned int y,unsigned int n) //200*200
- {
- unsigned int i,j,k;
- unsigned int da;
- k=0;
- for(i=0;i<50;i++)
- {
- for(j=0;j<50;j++)
- {
- if(n==0) da=gImage_tb[k*2];
- if(n==1) da=gImage_pwm[k*2];
- if(n==2) da=gImage_rtc[k*2];
- if(n==3) da=gImage_adc[k*2];
- if(n==4) da=gImage_tft[k*2];
- if(n==5) da=gImage_sz[k*2];
- if(n==6) da=gImage_kz[k*2];
- if(n==7) da=gImage_dht[k*2];
- da<<=8;
- if(n==0) da|=gImage_tb[k*2+1];
- if(n==1) da|=gImage_pwm[k*2+1];
- if(n==2) da|=gImage_rtc[k*2+1];
- if(n==3) da|=gImage_adc[k*2+1];
- if(n==4) da|=gImage_tft[k*2+1];
- if(n==5) da|=gImage_sz[k*2+1];
- if(n==6) da|=gImage_kz[k*2+1];
- if(n==7) da|=gImage_dht[k*2+1];
- POINT_COLOR=da;
- LCD_DrawPoint(x+i,y+j);
- k++;
- }
- }
- }
复制代码
实现界面显示效果的主程序是: - int main(void)
- {
- Cache_Enable();
- HAL_Init();
- Stm32_Clock_Init(160,5,2,4);
- delay_init(400);
- delay_ms(200);
- app_TFT_init();
- Lcd_Init();
- LCD_Clear(WHITE);
- show_tbh(20,240,0);
- showhanzi16h(80,280,3,0);
- showhanzi16h(80,264,4,0);
- show_tbh(20,180,1);
- show_tbh(20,120,2);
- show_tbh(20,60,3);
- showhanzi16h(80,100,5,1);
- showhanzi16h(80,84,6,1);
- show_tbh(120,60,4);
- show_tbh(120,120,5);
- show_tbh(120,180,6);
- show_tbh(120,240,7);
- showhanzi16h(180,280,13,1);
- showhanzi16h(180,264,14,1);
- showhanzi16h(180,220,11,1);
- showhanzi16h(180,204,12,1);
- showhanzi16h(180,160,9,1);
- showhanzi16h(180,144,10,1);
- showhanzi16h(180,100,7,1);
- showhanzi16h(180,84,8,1);
- BACK_COLOR=WHITE;
- POINT_COLOR=RED;
- LCD_ShowCharh(80,160,'R',1);
- LCD_ShowCharh(80,152,'T',1);
- LCD_ShowCharh(80,144,'C',1);
- LCD_ShowCharh(80,220,'P',1);
- LCD_ShowCharh(80,212,'W',1);
- LCD_ShowCharh(80,204,'M',1);
- delay_ms(2000);
- LED_Init();
- while(1)
- {
- LED2(1);
- delay_ms(500);
- LED2(0);
- delay_ms(500);
- }
- }
复制代码
经程序的编译下载,其显示效果图1和图2所示。 图1 功能选择界面
图2 功能选择
|