社区导航

 

搜索
查看: 269|回复: 0

[原创] 【 ST NUCLEO-H743ZI测评】+ 5、LCD驱动

[复制链接]

25

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2020-5-27 22:07 | 显示全部楼层 |阅读模式

 

     这节使用Arduino方式来驱动LCD显示字符。

 

    一、电路图

 

    1.1、开发板Arduino接口

    使用到红色框内的引脚 。
01.png

    1.2、arduino扩展板LCD驱动电路图

    使用IO口扩展的方式来驱动LCD,在显示速度上会有些延迟。 02.png

      03.png

     04.png

 

    二、驱动程序

    

    2.1、lcd.c

#include "config.h"

void delay_1ms(uint32_t dl)
{
	HAL_Delay(dl);
}

static void lcd_Reset(void)
{
	lcd_rst_h();    
	delay_1ms(10); 
	lcd_rst_l(); 
	delay_1ms(500);
	lcd_rst_h();    
	delay_1ms(500);
		
	lcd_dir_h();  				//dir=1 A->B
	lcd_en1_h();						//LCD_EN=0   2A->2B
	lcd_en2_h();
	lcd_rd_h();//LCD_RD=1;  //rd=1
}

void lcd_sendat(uint16_t dat)
{
	uint8_t i;
//	lcd_dir_h();  				//dir=1 A->B
//	lcd_en1_h();						//LCD_EN=0   2A->2B
//	lcd_en2_h();
	write_busdat(dat);		//P3=dat;		//D7..D0;
	lcd_le_h();						//LCD_LE=1;
	write_busdat(dat>>8);	//D7..D0;
	lcd_le_l();	
}
void LCD_WR_CMD(uint16_t LCD_Reg)
{
	lcd_cs_l();//LCD_CS=0;  //cs=0
  lcd_rs_l();//LCD_RS=0;  //rs=0
	lcd_rd_h();//LCD_RD=1;  //rd=1
	
  lcd_wr_l();//LCD_WR=0;  //wr=0
	lcd_sendat(LCD_Reg);
  lcd_wr_h();//LCD_WR=1;   //wr=1
  lcd_cs_h();//LCD_CS=1;   //cs=1
	lcd_rs_h();//LCD_RS=1;   //rs=1
}

void LCD_WR_DATA(uint16_t LCD_Data)	
{
	lcd_rs_h();//LCD_RS=1;  //rs=1
  lcd_cs_l();//LCD_CS=0;  //cs=0 
  lcd_rd_h();//LCD_RD=1;  //rd=1	
	lcd_wr_l();//LCD_WR=0;  //wr=0
	lcd_sendat(LCD_Data);
	lcd_wr_h();//LCD_WR=1;   //wr=1
  lcd_cs_h();//LCD_CS=1;   //cs=1
}

void LCD_WriteReg(uint16_t reg,uint16_t val)
{
	LCD_WR_CMD(reg);
	LCD_WR_DATA(val);
}

void Init_lcd(void)
{
	
	lcd_bk_on();//LCD_BK=1;
	lcd_Reset();
	
	LCD_WriteReg(0x0000,0x0001); 
	delay_1ms(10); 
	LCD_WriteReg(0x00A4,0x0001); 
	delay_1ms(10); 
	LCD_WriteReg(0x0070,0x9B00); 
	delay_1ms(10); 
	LCD_WriteReg(0x0007,0x0031); 
	delay_1ms(10); 
	//power supply setting 
	LCD_WriteReg(0x0018,0x0001); 
	delay_1ms(5); 
	LCD_WriteReg(0x0010,0x16B0);     
	delay_1ms(5); 
	LCD_WriteReg(0x0011,0x0200); 
	delay_1ms(5); 
	LCD_WriteReg(0x0012,0x1118); 
	delay_1ms(5); 
	LCD_WriteReg(0x0013,0x880F); 
	delay_1ms(5); 
	LCD_WriteReg(0x0014,0x0000); 
	delay_1ms(5); 
	LCD_WriteReg(0x0012,0x1138); 
	delay_1ms(5); 
	LCD_WriteReg(0x0090,0x0004); 
	LCD_WriteReg(0x0091,0x0000); 
	LCD_WriteReg(0x0092,0x0007); 
	LCD_WriteReg(0x0098,0x0002); 
	//display contral 
	LCD_WriteReg(0x0001,0x0100); 
	LCD_WriteReg(0x0002,0x0400); 
	LCD_WriteReg(0x0003,0x1030); 
	LCD_WriteReg(0x0008,0x0708); 
	LCD_WriteReg(0x0070,0x1B00); 
	LCD_WriteReg(0x0071,0x0001); 
	//gamma contral 
	LCD_WriteReg(0x0030,0x0305); 
	LCD_WriteReg(0x0031,0x0005); 
	LCD_WriteReg(0x0032,0x0000); 
	LCD_WriteReg(0x0033,0x0003); 
	LCD_WriteReg(0x0034,0x0900); 
	LCD_WriteReg(0x0035,0x0607); 
	LCD_WriteReg(0x0036,0x0307); 
	LCD_WriteReg(0x0037,0x0305); 
	LCD_WriteReg(0x0038,0x1305); 
	LCD_WriteReg(0x0039,0x1C00); 
	LCD_WriteReg(0x003A,0x1500); 
	//panel interface 
	LCD_WriteReg(0x0020,0x0000); 
	LCD_WriteReg(0x0021,0x0000); 
	//address set 
	LCD_WriteReg(0x0050,0x0000);
	LCD_WriteReg(0x0051,LCD_X); 
	LCD_WriteReg(0x0052,0x0000); 
	LCD_WriteReg(0x0053,LCD_Y);//176*220
	//display on 
	delay_1ms(5); 

	LCD_WriteReg(0x0007,0x0001); 
	delay_1ms(10); 
	LCD_WriteReg(0x0007,0x0021); 
	delay_1ms(10); 
	LCD_WriteReg(0x0007,0x0233); 

//lcd_sendat(0xffff);
//delay_1ms(100);
//lcd_sendat(0x0000);
//delay_1ms(100);

}

void LCD_SetPos(uint16_t x,uint16_t y)
{
    LCD_WriteReg(0x0020, x & 0xFF); 
    LCD_WriteReg(0x0021, y & 0x1FF);
	
    LCD_WR_CMD(0x0022);//?GRAM
}

void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t p)
{
	LCD_SetPos(x,y);
	LCD_WR_DATA(p);
}

void LCD_Fill(uint16_t x,uint16_t y,uint16_t x_len,uint16_t y_len,uint16_t Color)
{
   uint16_t i,j;
	
	for(i = y;i < y+y_len;i ++)
	{
		j = x;
		LCD_SetPos(j,i);
		
		for(;j < x+x_len;j ++)
		{
			LCD_WR_DATA(Color);
		}
	}
}

    2.2、lcd.h

#ifndef __LCD_H
#define __LCD_H


#define LCD_X 176
#define LCD_Y 220

#define	BLACK	0x0000
#define	BLUE	0x001F
#define	RED 	0xF800
#define	GREEN 	0x07E0
#define CYAN	0x07FF
#define MAGENTA 0xF81F
#define YELLOW	0xFFE0
#define WHITE	0xFFFF	
#define BACKCOLOR 0xFFFF	
#define	WORDCOLOR 0x0000

void Init_lcd(void);
void LCD_SetPos(uint16_t x,uint16_t y);
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t p);
void LCD_Fill(uint16_t x,uint16_t y,uint16_t x_len,uint16_t y_len,uint16_t Color);


#endif

    2.3、main.c

#include"config.h"
int main(void)
{
	uint8_t txdat[100]="www.eeworld.com.cn-stm32h743 usart test\r\n";
	uint8_t rxdat[100];
	uint8_t i=0;
	uint8_t js=0;
	uint8_t jsdat=0;
	uint8_t t;
	uint8_t str[6]={'0','0','0','.','0','m'};
  CPU_CACHE_Enable();
  HAL_Init();
  SystemClock_Config();
	LED_Init();
	KEY_Init();
	UART_Init();
	BUS_Init();
	Init_lcd();
	led_test();
	
	LCD_Fill(0,0,LCD_X,LCD_Y,RED);
	HAL_Delay(100);
	LCD_Fill(0,0,LCD_X,LCD_Y,GREEN);
	HAL_Delay(100);
	LCD_Fill(0,0,LCD_X,LCD_Y,BLUE);
	HAL_Delay(100);
	LCD_Fill(0,0,LCD_X,LCD_Y,BLACK);
	GUI_DrawStr24(0,0,RED,BLACK,"STM32H743 TEST");
  while (1)
  {
		jsdat++;
		str[0]=(jsdat/1000)+0x30;
		str[1]=(jsdat%1000)/100+0x30;
		str[2]=((jsdat%1000)%100)/10+0x30;
		str[4]=((jsdat%1000)%100)%10+0x30;
		GUI_DrawStr24(26,0,WHITE,BLACK,str);

//			
  }
}

 

    三、执行结果

     100.gif

    

此帖出自stm32/stm8论坛

回复

使用道具 举报

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

关闭

站长推荐上一条 1/6 下一条

  • 论坛活动 E手掌握

    扫码关注
    EEWORLD 官方微信

  • EE福利  唾手可得

    扫码关注
    EE福利 唾手可得

Archiver|手机版|小黑屋|电子工程世界 ( 京ICP证 060456 )

GMT+8, 2020-7-5 12:46 , Processed in 0.085204 second(s), 21 queries , Gzip On, MemCache On.

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