#include "DataType.h"
#include "gd32e23x.h"
#include "tftDriver.h"
#define RES_PORT GPIOB
#define RES_PIN GPIO_PIN_10
#define RS_PORT GPIOB
#define RS_PIN GPIO_PIN_11
#define CS_PORT GPIOB
#define CS_PIN GPIO_PIN_12
#define LIGHT_PORT GPIOA
#define LIGHT_PIN GPIO_PIN_7
#define DC_H gpio_bit_set(RS_PORT, RS_PIN)
#define DC_L gpio_bit_reset(RS_PORT, RS_PIN)
#define CS_H gpio_bit_set(CS_PORT, CS_PIN)
#define CS_L gpio_bit_reset(CS_PORT, CS_PIN)
#define WR_DATA 1
#define WR_CMD 0
#define BLACK_COLOR 0
#define FONT_COLOR 0x001F
static UINT32 led_direction = 0;
typedef enum{
LCD_DIRECTION_HP,
LCD_DIRECTION_HN,
LCD_DIRECTION_VP,
LCD_DIRECTION_VN,
}LCD_DIRECTION;
// Select SPI OLED: ChipSelect pin low
static void tft_select(void)
{
gpio_bit_reset(GPIOB, GPIO_PIN_12);
}
static void tft_release(void)
{
gpio_bit_set(GPIOB, GPIO_PIN_12);
}
static void tft_select_command(void)
{
gpio_bit_reset(GPIOB, GPIO_PIN_11);
}
static void tft_select_data(void)
{
gpio_bit_set(GPIOB, GPIO_PIN_11);
}
static UCHAR tft_send_byte(UCHAR byte)
{
// Loop while DR register in not emplty
while(spi_i2s_flag_get(SPI1, I2S_FLAG_TBE) == RESET);
// Send byte through the SPI2 peripheral
spi_i2s_data_transmit(SPI1, byte);
//while(RESET == spi_i2s_flag_get(SPI1,SPI_FLAG_RBNE));
while(RESET == spi_i2s_flag_get(SPI1,SPI_FLAG_TBE));//(SPI1,SPI_FLAG_TRANS));
/* return the byte read from the SPI bus */
//return(spi_i2s_data_receive(SPI1));
}
void delay(UINT16 ms)
{
UINT16 i;
while(ms--)
{
for (i = 0; i < 134; i++);
}
}
static void send_byte(UCHAR byte)
{
UCHAR i = 0;
for(i = 0;i < 8;i++){
gpio_bit_reset(GPIOB, GPIO_PIN_13);
delay(1);
if(byte & 0x80){
gpio_bit_set(GPIOB, GPIO_PIN_15);
}else{
gpio_bit_reset(GPIOB, GPIO_PIN_15);
}
byte = byte << 1;
delay(1);
gpio_bit_set(GPIOB, GPIO_PIN_13);
delay(1);
}
delay(1);
gpio_bit_reset(GPIOB, GPIO_PIN_13);
}
#if 1
#define LCD_Write(dc, tdata) \
{\
if (dc) \
{ \
DC_H; \
} \
else \
{ \
DC_L; \
} \
tft_send_byte(tdata); \
}
#else
#define LCD_Write(dc, data) \
{ \
UCHAR ucRetry = 20; \
if (dc) \
{ \
DC_H; \
} \
else \
{ \
DC_L; \
} \
SPI_DATA(SPI1) = (UINT32)data; \
while((RESET == spi_i2s_flag_get(SPI1, SPI_FLAG_RBNE))&&(--ucRetry)); \
}
#endif
void LCD_3022_Open_Light(void)
{
gpio_bit_set(LIGHT_PORT, LIGHT_PIN);
}
void LCD_3022_Close_Light(void)
{
gpio_bit_set(LIGHT_PORT, LIGHT_PIN);
}
void LCD_3022_Reset(void)
{
gpio_bit_set(RES_PORT, RES_PIN);
delay_1ms(100);
gpio_bit_reset(RES_PORT, RES_PIN);
delay_1ms(100);
gpio_bit_set(RES_PORT, RES_PIN);
delay_1ms(20);
}
void Write_Register(uint8_t tdata)
{
CS_L;
LCD_Write(0,tdata);
CS_H;
}
void Write_Parameter(uint8_t tdata)
{
CS_L;
LCD_Write(1,tdata);
CS_H;
}
void Write_Param(uint8_t reg,uint8_t *pdata,uint8_t len)
{
uint8_t i = 0;
CS_L;
DC_L;
tft_send_byte(reg);
DC_H;
for(i=0;i<len;i++){
tft_send_byte(pdata[i]);
}
CS_H;
}
void Write_data(uint8_t *pdata,uint16_t len)
{
uint8_t i = 0;
// CS_L;
// DC_H;
for(i=0;i<len;i++){
tft_send_byte(pdata[i]);
}
// CS_H;
}
void address(void)
{
uint8_t temp[5] = {0};
temp[0] = 0x00;
temp[1] = 0x34;
temp[2] = 0x00;
temp[3] = 186;
Write_Param(0x2A,temp,4);
temp[0] = 0x00;
temp[1] = 0x28;
temp[2] = 0x01;
temp[3] = 0X17;
Write_Param(0x2B,temp,4);
Write_Param(0x2C,NULL,0);
}
void lcd_set_rect(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
{
uint8_t buff[5] = {0};
uint16_t temp = 0;
uint8_t x_offset = 0;
uint8_t y_offset = 0;
if((led_direction == 2)||(led_direction == 3)){
y_offset=24;//26;
}else{
x_offset=24;//25;
}
temp = x_offset+y1;//52
buff[0] = temp >> 8;
buff[1] = temp & 0xFF;
temp = x_offset+y2;
buff[2] = temp >> 8;
buff[3] = temp & 0xFF;
Write_Param(0x2A,buff,4);
temp = y_offset+x1;
buff[0] = temp >> 8;
buff[1] = temp & 0xFF;
temp = y_offset+x2;
buff[2] = temp >> 8;
buff[3] = temp & 0xFF;
Write_Param(0x2B,buff,4);
Write_Param(0x2C,NULL,0);
}
void fillcolor(unsigned char dat1,unsigned char dat2)
{
unsigned char i,j;
uint8_t temp[2] = {0};
lcd_set_rect(0,0,LCD_WIDTH,LCD_HEIGHT);
temp[0] = dat1;
temp[1] = dat2;
CS_L;
DC_H;
for (i=0;i<=LCD_WIDTH;i++){
for (j=0;j<=LCD_HEIGHT;j++){
Write_data(temp,2);
}
}
CS_H;
}
void lcd_clear_rect(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color)
{
uint8_t i,j = 0;
uint8_t buff[5] = {0};
lcd_set_rect(x1,y1,x2,y2);
buff[0] = color>>8;
buff[1] = color&0xFF;
CS_L;
DC_H;
for (i=x1;i<=x2;i++){
for (j=y1;j<=y2;j++)
{
Write_data(buff,2);
}
}
CS_H;
}
void lcd_clear_screen(uint16_t color)
{
if((led_direction == LCD_DIRECTION_VP)||(led_direction == LCD_DIRECTION_VN)){
lcd_clear_rect(0,0,LCD_HEIGHT,LCD_WIDTH,color);
}else{
lcd_clear_rect(0,0,LCD_WIDTH,LCD_HEIGHT,color);
}
}
void lcd_put_pixel(uint16_t color)
{
uint8_t buff[2] = {0};
buff[0] = color>>8;
buff[1] = color&0xFF;
CS_L;
DC_H;
Write_data(buff,2);
CS_H;
}
void lcd_set_direct(uint8_t dir)
{
Write_Register(0x36); //MX, MY, RGB mode
switch(dir)
{
case 0:
case 4:
Write_Parameter(0xC0); //HP
led_direction = LCD_DIRECTION_HP;
break;
case 1:
Write_Parameter(0x00); //HN
led_direction = LCD_DIRECTION_HN;
break;
case 2:
Write_Parameter(0x60); //VN
led_direction = LCD_DIRECTION_VN;
break;
case 3:
Write_Parameter(0xA0); //VP
led_direction = LCD_DIRECTION_VP;
break;
}
}
extern void ui_draw_string_at(UCHAR *str,UCHAR x,UCHAR y);
extern const unsigned char gParamDescript8_16[];
uint16_t x1 = 0,y1=0, x2=0,y2=0;
void init_tft(void)
{
LCD_3022_Reset();
delay_1ms(100);
Write_Register(0x11); //Sleep out
delay_1ms(100); //Delay 120ms
Write_Register(0x36); //MX, MY, RGB mode
Write_Parameter(0xC0); //c0
Write_Register(0x3A); //MX, MY, RGB mode
Write_Parameter(0x05); //c0
Write_Register(0x21);
Write_Register(0xB2);
Write_Parameter(0x05);
Write_Parameter(0x05);
Write_Parameter(0x00);
Write_Parameter(0x33);
Write_Parameter(0x33);
Write_Register(0xB7);
Write_Parameter(0x23);
Write_Register(0xBB);
Write_Parameter(0x22);
Write_Register(0xC0);
Write_Parameter(0x2C);
Write_Register(0xC2);
Write_Parameter(0x01);
Write_Register(0xC3);
Write_Parameter(0x13);
Write_Register(0xC4);
Write_Parameter(0x20);
Write_Register(0xC6);
Write_Parameter(0x0F);
Write_Register(0xD0);
Write_Parameter(0xA4);
Write_Parameter(0xA1);
Write_Register(0xD6);
Write_Parameter(0xA1);
Write_Register(0xE0);
Write_Parameter(0x70);
Write_Parameter(0x06);
Write_Parameter(0x0C);
Write_Parameter(0x08);
Write_Parameter(0x09);
Write_Parameter(0x27);
Write_Parameter(0x2E);
Write_Parameter(0x34);
Write_Parameter(0x46);
Write_Parameter(0x37);
Write_Parameter(0x13);
Write_Parameter(0x13);
Write_Parameter(0x25);
Write_Parameter(0x2A);
Write_Register(0xE1);
tft lcd驱动 gd32 C语言 NV3022B
需积分: 32 192 浏览量
2022-11-17
22:48:43
上传
评论 1
收藏 3KB ZIP 举报
单片机的码农
- 粉丝: 63
- 资源: 16
最新资源
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- 关于mybatis的一些相关资源
- 关于mybatist的一些相关资源
- uni-app实战社区交友类app开发&带视频教程
- mybatis动态sql的一些相关资源
- 隐马尔可夫模型在期货市场的应用_曾琦裕 (1).caj
- 极域解控和极域反控!!!
- 安卓android-serialport-api 串口demo源代码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈