#include "8x16.h"
#include "GB3232.h"
#include "GB1616.h"
#include "asc20x40E.h"
/*----------------------------------------------------------------
定义硬件端口
----------------------------------------------------------------*/
#define LCD_CS_High GPIO_SetBits(GPIOB,GPIO_Pin_8) //片选 高
#define LCD_CS_Low GPIO_ResetBits(GPIOB,GPIO_Pin_8) //片选 低
#define LCD_RES_High GPIO_SetBits(GPIOB,GPIO_Pin_9) //复位 高
#define LCD_RES_Low GPIO_ResetBits(GPIOB,GPIO_Pin_9) //复位 低
#define LCD_RW_High GPIO_SetBits(GPIOB,GPIO_Pin_10) //读写 高
#define LCD_RW_Low GPIO_ResetBits(GPIOB,GPIO_Pin_10) //读写 低
#define LCD_RS_High GPIO_SetBits(GPIOB,GPIO_Pin_11) //数据/命令选择 0为命令,1为数据 高
#define LCD_RS_Low GPIO_ResetBits(GPIOB,GPIO_Pin_11) //数据/命令选择 0为命令,1为数据 低
#define LCD_H() Write_Cmd_Data(0x0003,0x10A8) //横屏写显示方式
#define LCD_V() Write_Cmd_Data(0x0003,0x10B0) //竖屏写显示方式
#define LCD_Write() Write_Cmd (0x00,0x22) //指向LCD的数据RAM寄存器
void delayms(uint32_t);
void Write_Data(uint8_t,uint8_t);
void Write_Cmd(uint8_t,uint8_t);
void Write_Data_U16(uint16_t);
void Write_Cmd_Data(uint8_t,uint32_t);
void ILI9325_Initial(void);
void LCD_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
ILI9325_Initial();
}
//void LCD_SetPos(unsigned int x_min,unsigned int x_max,unsigned int y_min,unsigned int y_max)
//{
// Write_Cmd_Data(0x50,x_min);
// Write_Cmd_Data(0x51,x_max);
// Write_Cmd_Data(0x52,y_min);
// Write_Cmd_Data(0x53,y_max);
// Write_Cmd_Data(0x20,x_max);
// Write_Cmd_Data(0x21,y_min);
// LCD_Write();
//}
/* 横屏定位 */
void LCD_SetPos(uint16_t x_min,uint16_t y_min,uint16_t x_max,uint16_t y_max)
{
Write_Cmd_Data(0x50,240-y_max);
Write_Cmd_Data(0x51,240-y_min);
Write_Cmd_Data(0x52,x_min);
Write_Cmd_Data(0x53,x_max);
Write_Cmd_Data(0x20,x_max);
Write_Cmd_Data(0x21,y_min);
LCD_Write();
}
/*----------------------------------------------------------------
清屏函数
输入参数:bColor 清屏所使用的背景色
----------------------------------------------------------------*/
void CLR_Screen(uint32_t background)
{
uint8_t DH=background>>8,DL=background;
uint32_t count=240*320;
Write_Cmd_Data(0x50,0);
Write_Cmd_Data(0x51,239);
Write_Cmd_Data(0x52,0);
Write_Cmd_Data(0x53,319);
Write_Cmd_Data(0x20,239);
Write_Cmd_Data(0x21,0);
Write_Cmd (0x00,0x22);
while(count--)
{
Write_Data(DH,DL);
}
}
/*----------------------------------------------------------------
写命令、写数据
输入参数:x 需要输入的命令 16位
y 需要输入的数据 16位
----------------------------------------------------------------*/
void Write_Cmd_Data (unsigned char x,unsigned int y)
{
unsigned char m,n;
m=y>>8;
n=y;
Write_Cmd(0x00,x);
Write_Data(m,n);
}
/*----------------------------------------------------------------
写16位数据
----------------------------------------------------------------*/
void Write_Data_U16(uint16_t dat)
{
uint8_t DH=dat>>8,DL=dat;
GPIOB->BSRR=1<<8<<16 //LCD_CS_Low;
|1<<11 // LCD_RS_High;
|DH |((uint8_t) ~DH)<<16 // GPIOB->ODR=DH;
|1<<10<<16; // LCD_RW_High;
GPIOB->BSRR=1<<10; // LCD_RW_High;
GPIOB->BSRR=1<<16<<10 // LCD_RW_Low;
|DL|((uint8_t) ~DL)<<16; // GPIOB->ODR=DL;
GPIOB->BSRR=1<<10 // LCD_RW_High;
|1<<8; // LCD_CS_High;
}
/*----------------------------------------------------------------
写命令
----------------------------------------------------------------*/
void Write_Cmd(unsigned char DH,unsigned char DL)
{
GPIOB->BSRR=1<<8<<16 //LCD_CS_Low;
|1<<11<<16//LCD_RS_Low;
|DH
|(uint8_t)~DH<<16
|1<<10<<16;//LCD_RW_Low;
GPIOB->BSRR=1<<10; //LCD_RW_High;
GPIOB->BSRR=DL
|(uint8_t)~DL<<16
|1<<10<<16; //LCD_RW_Low;
GPIOB->BSRR=1<<10 //LCD_RW_High;
|1<<8; //LCD_CS_High;
}
/*----------------------------------------------------------------
320*240 LIL9325 液晶控制器 写数据 双8位
8位数据线为 GPIOB_Pin_0 到GPIOB_Pin_7
LCD_CS 片选为 GPIOB_Pin_8
LCD_WR 读使能 GPIOB_Pin_9
LCD_RS 命令/数据 GPIOB_Pin_11
----------------------------------------------------------------*/
void Write_Data(unsigned char DH,unsigned char DL)
{
GPIOB->BSRR=1<<8<<16 //LCD_CS_Low; 片选低 开始
|1<<11 // LCD_RS_High; 写数据
|DH |((uint8_t) ~DH)<<16 // GPIOB->ODR=DH; 写8位数据
|1<<10<<16; // LCD_RW_Low; 读为低
GPIOB->BSRR=1<<10; // LCD_RW_High; 读为高,数据锁存
GPIOB->BSRR=1<<16<<10 // LCD_RW_Low; 读为低
|DL|((uint8_t) ~DL)<<16; // GPIOB->ODR=DL; 写8位数据
GPIOB->BSRR=1<<10 // LCD_RW_High; 读为高,数据锁存
|1<<8; //LCD_CS_High; 片选高 结束
}
/*----------------------------------------------------------------
延时函数
----------------------------------------------------------------*/
void delayms(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
{
for(j=0;j<260;j++);
}
}
/*----------------------------------------------------------------
液晶初始化
----------------------------------------------------------------*/
void ILI9325_Initial(void)
{
LCD_CS_High;
delayms(50);
LCD_RES_Low;
delayms(50);
LCD_RES_High;
delayms(500);
Write_Cmd_Data(0x0001,0x0100);
Write_Cmd_Data(0x0002,0x0700);
Write_Cmd_Data(0x0003,0x10B0); // Write_Cmd_Data(0x0003,0x1030); Write_Cmd_Data(0x0003,0x10A8)横屏
Write_Cmd_Data(0x0004,0x0000);
Write_Cmd_Data(0x0008,0x0207);
Write_Cmd_Data(0x0009,0x0000);
Write_Cmd_Data(0x000A,0x0000);
Write_Cmd_Data(0x000C,0x0000);
Write_Cmd_Data(0x000D,0x0000);
Write_Cmd_Data(0x000F,0x0000);
//power on sequence VGHVGL
Write_Cmd_Data(0x0010,0x0000);
Write_Cmd_Data(0x0011,0x0007);
Write_Cmd_Data(0x0012,0x0000);
Write_Cmd_Data(0x0013,0x0000);
//vgh
Write_Cmd_Data(0x0010,0x1290);
Write_Cmd_Data(0x0011,0x0227);
//delayms(100);
//vregiout
Write_Cmd_Data(0x0012,0x001d); //0x001b
//delayms(100);
//vom amplitude
Write_Cmd_Data(0x0013,0x1500);
//delayms(100);
//vom H
Write_Cmd_Data(0x0029,0x0018);
Write_Cmd_Data(0x002B,0x000D);
//gamma
Write_Cmd_Data(0x0030,0x0004);
Write_Cmd_Data(0x0031,0x0307);
Write_Cmd_Data(0x0032,0x0002);// 0006
Write_Cmd_Data(0x0035,0x0206);
Write_Cmd_Data(0x0036,0x0408);
Write_Cmd_Data(0x0037,0x0507);
Write_Cmd_Data(0x0038,0x0204);//0200
Write_Cmd_Data(0x0039,0x0707);
Write_Cmd_Data(0x003C,0x0405);// 0504
Write_Cmd_Data(0x003D,0x0F02);
//ram
Write_Cmd_Data(0x0050,0x0000);
Write_Cmd_Data(0x0051,0x00EF);
Write_Cmd_Data(0x0052,0x0000);
Write_Cmd_Data(0x0053,0x013F);
Write_Cmd_Data(0x0060,0xA700);
Write_Cmd_Data(0x0061,0x0001);
Write_Cmd_Data(0x006A,0x0000);
//
Write_Cmd_Data(0x0080,0x0000);
Write_Cmd_Data(0x0081,0x0000);
Write_Cmd_Data(0x0082,0x0000);
Write_Cmd_Data(0x0083,0x0000);
Write_Cmd_Data(0x0084,0x0000);
Write_Cmd_Data(0x0085,0x0000);
//
Write_Cmd_Data(0x0090,0x0010);
Write_Cmd_Data(0x0092,0x0600);
Write_Cmd_Data(0x0093,0x0003);
Write_Cmd_Data(0x0095,0x0110);
Write_Cmd_Data(0x0097,0x0000);
Write_Cmd_Data(0x0098,0x0000);
Write_Cmd_Data(0x0007,0x0133);
delayms(10000);
}
/********输出32X32中文字符*********/
void PutGB3232(uint16_t x_point,uint16_t y_point,uint8_t Char_Index[2],uint16_t Font_Color,uint16_t Back_Color)
{
uint16_t Word_Byte_Index,j,Word_Index;
LCD_SetPos(x_point, y_point,x_point+32-1,y_point+32-1); //定位
for (Word_Index=0;Word_Index<100;Word_Index++)
{
if ((GB_32[Word_Index].Index[0]==Char_Index[0])&&(GB_32[Word_Index].Index[1]==Char_Index[1]))
{
for(Word_Byte_Index=0;Word_Byte_Index<128;Word_Byte_Index++)
{
uint8_t m=GB_32[Word_Index].Msk[Word_Byte_Index];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80)
{
Write_Data_U16(Font_Color);
}
else
{
Write_Data_U16(Back_Color);
}
m<<=1;
}
}
break;
}
}
}
/********输出16X16中文字符*********/
void PutGB1616(uint16_t x_point, uint16_t y_point, uint8_t c[2],uint16_t fColor,uint16_t bColor)
{
uint16_t i,j,k;
LCD_SetPos(x_point, y_point,x_point+16-1,y_point+16-1); //定位
for (k=0;k<100;k++)
{
if ((GB_16[k].Index[0]==c[0])&&(GB_16[k].Index[1]==c[1]))
{
for(i=0;i<32;i++)
{
uint8_t m=GB_16[k].Msk[i];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80)
{
Write_Data_U16(fColor);
}
else
{
Write_Data_U16(bColor);
}
m<<=1;
}
}
break;
}
}
}
/********输出16X16中文字符串*********/
void PutGB1616_string(uint16_t x_point, uint16_t y_point, uint8_t * c,uint16_t fColor,uint16_t bColor)
{
uint8_t c2[2];
while(*c)
{
c2[0]=*c;
c2[1]=*(c+1);
PutGB1616((x_point+=16)-16, y_point, c2, fColor, bColor);
c+=2;
}
}
/********输出8x16英文字符*********/
void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor)
{
unsigned int i,j;
LCD_SetPos(x,y,x+8-1,y+16-1);
for(i=0; i<16;i++) {
unsigned char m=Font8x16[c*16+i];
for(j=0;j<8;j++) {
if((m&0x80)==0x80) {
Write_Data_U16(fColor);
}
else {
Write_Data_U16(bColor);
}
m<<=1;
}
}
}
/********输出8x16英文字符串*********/
void LCD_Putstring8x16(unsigned short x, unsigned short y, char * c, unsigned int fColor, unsigned int bColor)
{
while(*c)
{
LCD_PutChar8x16(x+=8,y, *c, fColor, bColor);
c++;
}
}
/********输出20x40数字字符*********/
void LCD_PutChar20x40number(unsigned short x, unsigned short y, char number, unsigned int fColor, unsigned int bColor)
{
unsigned int i,j;
LCD_SetPos(x,y,x+24-1,y+40-1);
for(i=0; i<120;i++)
{
unsigned char m=ASCII20x40number[number*120+i];
for(j=0;j<8;j++)
{
if((m&0x80)==0x80)
{
Write_Data_U16(fColor);
}
else
{
Write_Data_U16(bColor);
}
m<<=1;
}
}
}
/**
* @brief 画一个长方形
* @param x_point: 长方形左上角的X坐标.
* @param y_point: 长方形左上角的Y坐标.
* @param Square_length: 长方形的长度,x方向增长.
* @param Square_high: 长方形的高度,y方向增长.
* @param Color: 长主形的填充颜色.
* This parameter can be:
* @retval None
*/
void LCD_Draw_Square(uint16_t x_point, uint16_t y_point,uint16_t Square_length,uint16_t Square_high,uint16_t Color)
{
uint8_t Color_High_Byte=Color>>8,Color_Low_Byte=Color; //把颜色分解成高位字节和低位字节
uint16_t area=Square_length * Square_high; //面积=长 * 高. 表示长方形里的点数
LCD_SetPos(x_point,y_point,x_point+Square_length-1,y_point+Square_high-1);
while(area--)
{
Write_Data(Color_High_Byte,Color_Low_Byte);
}
}
看我的程序,或许有帮助. |