这款单片机很多地方找不到源代码,我辛苦移植过来的希望大家下载加入自己的font.h使用
单片机源程序如下:
- #include "ST7789V.h"
- #include "intrins.h"
- #include "FONT.H"
- #define LCD_CS P34
- #define LCD_RST P37
- #define LCD_RS P33
- #define LCD_SLC P35
- #define LCD_SDA P36
-
- /*写指令到 LCD 模块*/
- void transfer_command(int data1)
- {
- char i;
- LCD_CS=0;
- LCD_RS=0;
- for(i=0;i<8;i++)
- {
- LCD_SLC=0;
- if(data1&0x80) LCD_SDA=1;
- else LCD_SDA=0;
- LCD_SLC=1;
- data1=data1<<=1;
- }
- LCD_CS=1;
- }
- /*写数据到 LCD 模块*/
- void transfer_data(int data1)
- {
- char i;
- LCD_CS=0;
- LCD_RS=1;
- for(i=0;i<8;i++)
- {
- LCD_SLC=0;
- if(data1&0x80) LCD_SDA=1;
- else LCD_SDA=0;
- LCD_SLC=1;
- data1=data1<<=1;
- }
- LCD_CS=1;
- }
- void Delay200ms() //@11.0592MHz
- {
- unsigned char i, j, k;
- _nop_();
- _nop_();
- i = 9;
- j = 104;
- k = 139;
- do
- {
- do
- {
- while (--k);
- } while (--j);
- } while (--i);
- }
- void lcd_initial()
- {
- LCD_RST=0;
- Delay200ms();
- LCD_RST=1;
- Delay200ms();
- //************* Start Initial Sequence **********//
- //------------------------------display and color format setting--------------------------------//
- transfer_command(0x36); //行扫描顺序及 RGB,列扫描顺序,横放/竖放
- transfer_data(0xa0);
- transfer_data(0x48);
-
- transfer_command(0xB6); //显示功能设置:列/行 显示顺序
- transfer_data(0x0A);
- transfer_data(0x82); //改变 SOURCE 线的方向:0xa2:左到右,0x82:右到左
-
- transfer_command(0x3a); //256K 16bit/pixel
- transfer_data(0x05);
- //--------------------------------ST7789V Frame rate setting----------------------------------//
- transfer_command(0xb2);
- transfer_data(0x0c);
- transfer_data(0x0c);
- transfer_data(0x00);
- transfer_data(0x33);
- transfer_data(0x33);
- transfer_command(0xb7);
- transfer_data(0x35);
- //---------------------------------ST7789V Power setting--------------------------------------//
- transfer_command(0xbb);
- transfer_data(0x28);
- transfer_command(0xc0);
- transfer_data(0x2c);
- transfer_command(0xc2);
- transfer_data(0x01);
- transfer_command(0xc3);
- transfer_data(0x10);
- transfer_command(0xc4);
- transfer_data(0x20);
- transfer_command(0xc6);
- transfer_data(0x0f);
- transfer_command(0xd0);
- transfer_data(0xa4);
- transfer_data(0xa1);
- //--------------------------------ST7789V gamma setting---------------------------------------//
- transfer_command(0xe0);
- transfer_data(0xd0);
- transfer_data(0x00);
- transfer_data(0x02);
- transfer_data(0x07);
- transfer_data(0x0a);
- transfer_data(0x28);
- transfer_data(0x32);
- transfer_data(0x44);
- transfer_data(0x42);
- transfer_data(0x06);
- transfer_data(0x0e);
- transfer_data(0x12);
- transfer_data(0x14);
- transfer_data(0x17);
-
- transfer_command(0xe1);
- transfer_data(0xd0);
- transfer_data(0x00);
- transfer_data(0x02);
- transfer_data(0x07);
- transfer_data(0x0a);
- transfer_data(0x28);
- transfer_data(0x31);
- transfer_data(0x54);
- transfer_data(0x47);
- transfer_data(0x0e);
- transfer_data(0x1c);
- transfer_data(0x17);
- transfer_data(0x1b);
- transfer_data(0x1e);
-
- transfer_command(0x11); //退出睡眠
- Delay200ms();
- transfer_command(0x29); //打开显示
- }
- //===传 16 位指令,16 位指令一起赋值
- void transfer_command_16(uint com_16bit)
- {
- transfer_command(com_16bit >>8); //先传高 8 位
- transfer_command(com_16bit ); //再传低 8 位
- }
- //连写 2 个字节(即 16 位)数据到 LCD 模块
- void transfer_data_16(uint data_16bit)
- {
- transfer_data(data_16bit>>8);
- transfer_data(data_16bit);
- }
- //===发送 1 个字节的指令及 1 个字节的数据================
- void Lcd_Write_Com_Data(uint com,uint val)
- {
- transfer_command_16(com); //先传指令
- transfer_data_16(val); //再传数据
- }
- void delay(long i)
- {
- int j,k;
- for(j=0;j<i;j++)
- for(k=0;k<110;k++);
- }
- void delay_us(long i)
- {
- int j,k;
- for(j=0;j<i;j++)
- for(k=0;k<10;k++);
- }
- //定义窗口坐标:开始坐标(XS,YS)以及窗口大小(x_total,y_total)
- void lcd_address(int XS,int YS,int x_total,int y_total)
- {
- int XE,YE;
- XE=XS+x_total-1;
- YE=YS+y_total-1;
- transfer_command(0x2a); // 设置 X 开始及结束的地址
- transfer_data_16(XS); // X 开始地址(16 位)
- transfer_data_16(XE); // X 结束地址(16 位)
-
- transfer_command(0x2b); // 设置 Y 开始及结束的地址
- transfer_data_16(YS); // Y 开始地址(16 位)
- transfer_data_16(YE); // Y 结束地址(16 位)
- transfer_command(0x2c); // 写数据开始
- }
- void mono_transfer_data_16(int mono_data,int font_color,int back_color)
- {
- int i;
- for(i=0;i<8;i++)
- {
- if(mono_data&0x80)
- {
- transfer_data_16(font_color); //当数据是 1 时,显示字体颜色
- }
- else
- {
- transfer_data_16(back_color); //当数据是 0 时,显示底色
- }
- mono_data<<=1;
- }
- }
- //全屏显示一种颜色
- void display_color(int color_data)
- {
- int i,j;
- lcd_address(0,0,320,240);
- for(i=0;i<320;i++)
- {
- for(j=0;j<240;j++)
- {
- transfer_data_16(color_data);
- }
- }
- }
- void display_black(void)
- {
- int i,j,k;
- transfer_command(0x2c); // 写数据开始
- for(i=0;i<240;i++)
- {
- transfer_data_16(0xffff);
- }
- for(i=0;i<318;i++)
- {
- for(k=0;k<1;k++)
- {
- transfer_data_16(0xffff);
- }
- for(j=0;j<238;j++)
- {
- transfer_data_16(0x0000);
- }
- for(k=0;k<1;k++)
- {
- transfer_data_16(0xffff);
- }
- }
- for(i=0;i<320;i++)
- {
- transfer_data_16(0xffff);
- }
- }
- //显示 8x16 点阵的字符串
- void disp_string_8x16(int x,int y,char *text,int font_color,int back_color)
- {
- int i=0,j,k;
-
- while(text[i]>0x00)
- {
- j=text[i];
- lcd_address(x,y,8,16);
- for(k=0;k<16;k++)
- {
- mono_transfer_data_16(ascii0816[j*16+k],font_color,back_color);
- }
- x+=8;
- i++;
- }
- }
- //显示 16x32 点阵的单色的图像
- void disp_string_16x32(int x,int y,char *text,int font_color,int back_color)
- {
- int i=0,j,k,l;
- while(text[i]>0x00)
- {
- j=text[i]-32;
- lcd_address(x,y,16,32);
- for(k=0;k<32;k++)
- {
- for(l=0;l<2;l++)
- {
- switch(l)
- {
- case 0:
- mono_transfer_data_16(ascii1632[j*64+2*k],font_color,back_color);
- break;
- case 1:
- mono_transfer_data_16(ascii1632[j*64+2*k+1],font_color,back_color);
- break;
- }
- }
-
- }
- x+=16;
- i++;
- }
- }
- extern uint16_t *chine_index;
- //显示 32x32 点阵的单色的图像
- void disp_char_32x32(int x,int y,int *text,int font_color,int back_color)
- {
- int i=0,j,k,l,a;
-
- for(a=0;a<43;a++)
- {
- if(*(chine_index+a)==text[i])
- {
- j=a;
- break;
- }
- }
- lcd_address(x,y,32,32);
- for(k=0;k<32;k++)
- {
- for(l=0;l<4;l++)
- {
- mono_transfer_data_16(china32132[j*128+4*k+l],font_color,back_color);
- }
- }
- i++;
- }
-
- void disp_string_32x32(int x,int y,int *text,int font_color,int back_color)
- {
- while(*text!=0)
- {
- disp_char_32x32( x, y, text, font_color, back_color);
- text=text+1;
- x=x+32;
- }
- }
- void disp_16x32_app()
- {
- disp_string_32x32(0,32*5+32,"放电测试",0XF000,0xffff) ;
- }
-
- //显示一幅彩图
- void display_image(int x,int y,uchar *dp)
- {
- uchar i,j,k=0;
- lcd_address(x,y,120,160);
- for(i=0;i<120;i++)
- {
- for(j=0;j<160;j++)
- {
- transfer_data(*dp); //传一个像素的图片数据的高位
- dp++;
- transfer_data(*dp); //传一个像素的图片数据的低位
- dp++;
- }
- }
- }
复制代码
上图2个文件下载 c代码(请自行移植到各单片机平台):
ST7789V.zip
(3.59 KB, 下载次数: 87)
|