一天到晚的在黑坛下载程序,也分享一个吧!程序是用别人的板子,自己量IO口,敲敲打打搞出来的RM68090的程序。
这个片子没9341那么多人用,发出来供大家参考,花了一天搞出来。
不到之处请大神多多指点。
源代码不能发,见谅!
lcd.c
#include "lcd.h"
#include "stdlib.h"
#include "font.h"
#include "delay.h"
//画笔颜色,背景颜色
u16 POINT_COLOR = WHITE, BACK_COLOR = BLACK;//0xFFFF; WHITE
u16 LCD_RD_DATA(void)
{
u16 t;
GPIOC->CRL=0X88888888; //PB0-7 上拉输入
GPIOC->CRH=0X88888888; //PB8-15 上拉输入
GPIOC->ODR=0X0000; //全部输出0
LCD_RS_SET;
LCD_CS_CLR;
//读取数据(读寄存器时,并不需要读2次)
LCD_RD_CLR;
//if(lcddev.id==0X8989)delay_us(2);//FOR 8989,延时2us
t=DATAIN;
LCD_RD_SET;
LCD_CS_SET;
GPIOC->CRL=0X33333333; //PB0-7 上拉输出
GPIOC->CRH=0X33333333; //PB8-15 上拉输出
GPIOC->ODR=0XFFFF; //全部输出高
return t;
}
//写寄存器函数
void LCD_WR_REG(u8 data)
{
LCD_RS_CLR;//写地址
LCD_CS_CLR;
DATAOUT(data);
LCD_WR_CLR;
LCD_WR_SET;
LCD_CS_SET;
}
void LCD_WR_DATA(u16 data)//写数据
{
LCD_RS_SET;
LCD_CS_CLR;
DATAOUT(data);
LCD_WR_CLR;
LCD_WR_SET;
LCD_CS_SET;
}
//写寄存器
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue)
{
LCD_WR_REG(LCD_Reg);
LCD_WR_DATA(LCD_RegValue);
}
//读寄存器
//LCD_Reg:寄存器编号
//返回值:读到的值
u16 LCD_ReadReg(u16 LCD_Reg)
{
LCD_WR_REG(LCD_Reg); //写入要读的寄存器号
return LCD_RD_DATA();
}
//开始写GRAM
void LCD_WriteRAM_Prepare(void)
{
LCD_WR_REG(0x22);
}
//LCD写GRAM
void LCD_WriteRAM(u16 RGB_Code)
{
LCD_WR_DATA(RGB_Code);//写十六位GRAM
}
//从ILI93xx读出的数据为GBR格式,而我们写入的时候为RGB格式。
//通过该函数转换
//c:GBR格式的颜色值
//返回值:RGB格式的颜色值
u16 LCD_BGR2RGB(u16 c)
{
u16 r,g,b,rgb;
b=(c>>0)&0x1f;
g=(c>>5)&0x3f;
r=(c>>11)&0x1f;
rgb=(b<<11)+(g<<5)+(r<<0);
return(rgb);
}
u8 Set_LCD_Direc(u8 Direction)
{
if(Direction==1) //横屏
{
LCD_WriteReg(0X0003, 0x1018);
return 1;
}
else //竖屏
{
LCD_WriteReg(0X0003, 0x1030);
return 0;
}
}
//LCD开启显示 ILI9341
void LCD_DisplayOn(void)
{
LCD_WR_REG(0X29); //26万色显示开启
}
//LCD关闭显示 ILI9341
void LCD_DisplayOff(void)
{
LCD_WR_REG(0X28);//关闭显示
}
//设置光标位置
//Xpos:横坐标
//Ypos:纵坐标
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
LCD_WriteReg(0X20, Ypos);
LCD_WriteReg(0X21, 319-Xpos);
}
//画点
//x:0~239
//y:0~319
//POINT_COLOR:此点的颜色
void LCD_DrawPoint(u16 x,u16 y)
{
LCD_SetCursor(x, y);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WR_DATA(POINT_COLOR); /*这三行相当于绘制一个点*/
}
void LCD_Fast_DrawPoint(u16 x,u16 y,u16 color)
{
LCD_WR_REG(0x2A);
LCD_WR_DATA(x>>8);
LCD_WR_DATA(x&0XFF);
LCD_WR_REG(0x2B);
LCD_WR_DATA(y>>8);
LCD_WR_DATA(y&0XFF);
LCD_WR_REG(0X2C);//开始写入GRAM
LCD_WR_DATA(color);
}
//初始化lcd
//该初始化函数可以初始化各种ILI93XX液晶,但是其他函数是基于ILI9320的!!!
//在其他型号的驱动芯片上没有测试!
void LCD_Init(void)
{
// u16 ID[6];
GPIO_InitTypeDef GPIO_InitStructure;
/*开启相应时钟 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); //JTAG-DP 失能 + SW-DP使能
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_1|GPIO_Pin_10|GPIO_Pin_12|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOC,GPIO_Pin_All);//16位数据线变高
GPIO_SetBits(GPIOB,GPIO_Pin_1|GPIO_Pin_10|GPIO_Pin_12|GPIO_Pin_15);//控制脚变高
//LCDRESET
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输LCDRESET GPIO_Mode_Out_PP
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_0|GPIO_Pin_13);
LCDBKON;//点亮LCD背光
//***************************RESET LCD Driver******************************
LCD_RESET_SET; //reset-->1
delay_ms(1); //Delay 1ms
LCD_RESET_CLR; //reset-->0
delay_ms(10); //Delay 10ms
LCD_RESET_SET; //reset-->1
delay_ms(120); //Delay 200ms
//************************Start initial sequence***************************
LCD_WriteReg(0x0001, 0x0000); // set SS and SM bit
LCD_WriteReg(0x0002, 0x0200); // set 1 line inversion
LCD_WriteReg(0x0003, 0x1030); // set GRAM write direction and BGR=1
LCD_WriteReg(0x0004, 0x0000); // Resize register
LCD_WriteReg(0x0008, 0x0202); // set the back porch and front porch
LCD_WriteReg(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
LCD_WriteReg(0x000A, 0x0000); // FMARK function disable
LCD_WriteReg(0x000C, 0x0000); // RGB interface setting
LCD_WriteReg(0x000D, 0x0000); // Frame marker Position
LCD_WriteReg(0x000F, 0x0000); // RGB interface polarity
delay_ms(1);; // Delay 10 ms
//*************Power On sequence ****************//
LCD_WriteReg(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
LCD_WriteReg (0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
LCD_WriteReg (0x0012, 0x0000); // VREG1OUT voltage
LCD_WriteReg(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
LCD_WriteReg(0x0007, 0x0001);
LCD_WriteReg (0x0007, 0x0020);
delay_ms(1); // Dis-charge capacitor power voltage
LCD_WriteReg(0x0010, 0x1290); // SAP, BT[3:0], AP, DSTB, SLP, STB
LCD_WriteReg(0x0011, 0x0221); // Set DC1[2:0], DC0[2:0], VC[2:0]
delay_ms(50); // Delay 50ms
LCD_WriteReg(0x0012, 0x0082); // Internal reference voltage
delay_ms(10); // Delay 10ms
LCD_WriteReg(0x0013, 0x1900); // VDV[4:0] for VCOM amplitude
LCD_WriteReg(0x0029, 0x0026); // VCM[5:0] for VCOMH
LCD_WriteReg(0x002B, 0x000d); // Set Frame Rate
delay_ms(50); // Delay 50ms
LCD_WriteReg(0x0020, 0x0000); // GRAM horizontal Address
LCD_WriteReg(0x0021, 0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
LCD_WriteReg(0x0030, 0x0000);
LCD_WriteReg(0x0031, 0x0507);
LCD_WriteReg(0x0032, 0x0304);
LCD_WriteReg(0x0035, 0x0007);
LCD_WriteReg(0x0036, 0x1000);
LCD_WriteReg(0x0037, 0x0304);
LCD_WriteReg(0x0038, 0x0002);
LCD_WriteReg(0x0039, 0x0707);
LCD_WriteReg(0x003C, 0x0700);
LCD_WriteReg(0x003D, 0x0010);
//------------------ Set GRAM area ---------------//
LCD_WriteReg(0x0050, 0x0000); // Horizontal GRAM Start Address
LCD_WriteReg(0x0051, 0x00EF); // Horizontal GRAM End Address
LCD_WriteReg(0x0052, 0x0000); // Vertical GRAM Start Address
LCD_WriteReg(0x0053, 0x013F); // Vertical GRAM Start Address
LCD_WriteReg(0x0060, 0x2700); // Gate Scan Line
LCD_WriteReg(0x0061, 0x0003); // NDL,VLE, REV
LCD_WriteReg(0x006A, 0x0000); // set scrolling line
//-------------- Panel Control -------------------//
LCD_WriteReg(0x0090, 0x0010);
LCD_WriteReg(0x0092, 0x0000);
delay_ms(10); // Delay 10ms
LCD_WriteReg(0x0007, 0x0133); // 262K color and display ON //列首址0
Set_LCD_Direc(1);
}
//清屏函数
//Color:要清屏的填充色
void LCD_Clear(u16 Color)
{
u32 index=0;
LCD_SetCursor(0x00,0x0000);//设置光标位置
LCD_WriteRAM_Prepare(); //开始写入GRAM
for(index=0;index<76800;index++)
{
LCD_WR_DATA(Color);
}
}
//在指定区域内填充指定颜色
//区域大小:
//(xend-xsta)*(yend-ysta)
void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)
{
u16 i,j;
u16 xlen=0;
xlen=xend-xsta+1;
for(i=ysta;i<=yend;i++)
{
LCD_SetCursor(xsta,i);//设置光标位置
LCD_WriteRAM_Prepare();//开始写入GRAM
for(j=0;j<xlen;j++)LCD_WR_DATA(color);//设置光标位置
}
}
//在指定区域内填充指定颜色块
//(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
//color:要填充的颜色
void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color)
{
u16 height,width;
u16 i,j;
width=ex-sx+1; //得到填充的宽度
height=ey-sy+1; //高度
for(i=0;i<height;i++)
{
LCD_SetCursor(sx,sy+i); //设置光标位置
LCD_WriteRAM_Prepare(); //开始写入GRAM
for(j=0;j<width;j++)
LCD_WR_DATA(color[i*height+j]);//写入数据
}
}
//画线
//x1,y1:起点坐标
//x2,y2:终点坐标
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)
{
u16 t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x=x2-x1; //计算坐标增量
delta_y=y2-y1;
uRow=x1;
uCol=y1;
if(delta_x>0)incx=1; //设置单步方向
else if(delta_x==0)incx=0;//垂直线
else {incx=-1;delta_x=-delta_x;}
if(delta_y>0)incy=1;
else if(delta_y==0)incy=0;//水平线
else{incy=-1;delta_y=-delta_y;}
if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴
else distance=delta_y;
for(t=0;t<=distance+1;t++ )//画线输出
{
LCD_DrawPoint(uRow,uCol);//画点
xerr+=delta_x ;
yerr+=delta_y ;
if(xerr>distance)
{
xerr-=distance;
uRow+=incx;
}
if(yerr>distance)
{
yerr-=distance;
uCol+=incy;
}
}
}
//画矩形
void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2)
{
LCD_DrawLine(x1,y1,x2,y1);
LCD_DrawLine(x1,y1,x1,y2);
LCD_DrawLine(x1,y2,x2,y2);
LCD_DrawLine(x2,y1,x2,y2);
}
//在指定位置画一个指定大小的圆
//(x,y):中心点
//r :半径
void Draw_Circle(u16 x0,u16 y0,u8 r)
{
int a,b;
int di;
a=0;b=r;
di=3-(r<<1); //判断下个点位置的标志
while(a<=b)
{
LCD_DrawPoint(x0-b,y0-a); //3
LCD_DrawPoint(x0+b,y0-a); //0? ???
LCD_DrawPoint(x0-a,y0+b);//1? ?? ?
LCD_DrawPoint(x0-b,y0-a);//7? ?? ?? ???
LCD_DrawPoint(x0-a,y0-b);//2? ?? ?? ?? ?
LCD_DrawPoint(x0+b,y0+a);//4? ?? ?? ?? ?? ?
LCD_DrawPoint(x0+a,y0-b);//5
LCD_DrawPoint(x0+a,y0+b);//6
LCD_DrawPoint(x0-b,y0+a);
a++;
//使用Bresenham算法画圆
if(di<0)di +=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
LCD_DrawPoint(x0+a,y0+b);
}
}
void Draw_Circle2(u16 x0,u16 y0,u8 r)
{
int a,b;
int di;
a=0;b=r;
di=3-(r<<1); //判断下个点位置的标志
while(a<=b)
{
//LCD_DrawPoint(x0-b,y0-a);
LCD_DrawPoint(x0+b,y0-a); //0
//LCD_DrawPoint(x0-a,y0+b); //1
//LCD_DrawPoint(x0-b,y0-a);//7
LCD_DrawPoint(x0-a,y0-b); //2
LCD_DrawPoint(x0+b,y0+a); //4
LCD_DrawPoint(x0+a,y0-b); //5
//LCD_DrawPoint(x0+a,y0+b);
//LCD_DrawPoint(x0-b,y0+a);
a++;
//使用Bresenham算法画圆
if(di<0)di +=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
//LCD_DrawPoint(x0+a,y0+b);
}
}
//在指定位置显示一个字符
//x:0~234
//y:0~308
//num:要显示的字符:" "--->"~"
//size:字体大小 12/16
//mode:叠加方式(1)还是非叠加方式(0)
//在指定位置显示一个字符
//x:0~234
//y:0~308
//num:要显示的字符:" "--->"~"
//size:字体大小 12/16
//mode:叠加方式(1)还是非叠加方式(0)
void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode)
{
u8 temp,t1,t;
u16 y0=y;
u16 colortemp=POINT_COLOR;
//设置窗口
u8 csize=(size/8+((size%8)?1:0))*(size/2);
num=num-' ';//得到偏移后的值
if(!mode) //非叠加方式
{
for(t=0;t<csize;t++)
{
if(size==12)
temp=asc2_1206[num][t]; //调用1206字体
else if(size == 16)
temp=asc2_1608[num][t]; //调用1608字体
else
temp=asc2_2412[num][t]; //调用2412字体
for(t1=0;t1<8;t1++)
{
if(temp&0x80)POINT_COLOR=colortemp;
else POINT_COLOR=BACK_COLOR;
LCD_DrawPoint(x,y);
temp<<=1;
y++;
if(y>=LCDHEIGHT){POINT_COLOR=colortemp;return;}//超区域了
if((y-y0)==size)
{
y=y0;
x++;
if(x>=LCDWIDTH){POINT_COLOR=colortemp;return;}//超区域了
break;
}
}
}
}else//叠加方式
{
for(t=0;t<csize;t++)
{
if(size==12)temp=asc2_2412[num][t]; //调用1206字体
else if(size == 16) temp=asc2_2412[num][t]; //调用1608字体
else temp=asc2_2412[num][t];
for(t1=0;t1<8;t1++)
{
if(temp&0x80)LCD_DrawPoint(x,y);
temp<<=1;
y++;
if(y>=LCDHEIGHT){POINT_COLOR=colortemp;return;}//超区域了
if((y-y0)==size)
{
y=y0;
x++;
if(x>=LCDWIDTH){POINT_COLOR=colortemp;return;}//超区域了
break;
}
}
}
}
POINT_COLOR=colortemp;
// u8 temp;
// u8 pos,t;
// u16 x0=x;
// u16 colortemp=POINT_COLOR;
//
// if(x>(LCDWIDTH-size/2)||y>(LCDHEIGHT-size))return;
// //设置窗口
// num=num-' ';//得到偏移后的值
// if(!mode) //非叠加方式
// {
// for(pos=0;pos<size;pos++)
// {
// if(size==12)
// temp=asc2_1206[num][pos];//调用1206字体
// else
// temp=asc2_1608[num][pos]; //调用1608字体
// for(t=0;t<size/2;t++)
// {
// if(temp&0x01)
// POINT_COLOR=colortemp;
// else
// POINT_COLOR=WHITE;//BACK_COLOR;
// LCD_DrawPoint(x,y);
// temp>>=1;
// x++;
// }
// x=x0;
// y++;
// }
// }else//叠加方式
// {
// for(pos=0;pos<size;pos++)
// {
// if(size==12)temp=asc2_1206[num][pos]; //调用1206字体
// else temp=asc2_1608[num][pos]; //调用1608字体
// for(t=0;t<size/2;t++)
// {
// if(temp&0x01)LCD_DrawPoint(x+t,y+pos);//画一个点? ??
// temp>>=1;
// }
// }
// }
// POINT_COLOR=colortemp;
}
//m^n函数
//返回值:m^n次方.
u32 LCD_Pow(u8 m,u8 n)
{
u32 result=1;
while(n--)result*=m;
return result;
}
//显示数字,高位为0,则不显示
//x,y :起点坐标
//len :数字的位数
//size:字体大小
//color:颜色
//num:数值(0~4294967295);
void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size)
{
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/LCD_Pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
LCD_ShowChar(x+(size/2)*t,y,' ',size,0);
continue;
}else enshow=1;
}
LCD_ShowChar(x+(size/2)*t,y,temp+'0',size,0);
}
}
//显示数字,高位为0,还是显示
//x,y:起点坐标
//num:数值(0~999999999);
//len:长度(即要显示的位数)
//size:字体大小
//mode:
//[7]:0,不填充;1,填充0.
//[6:1]:保留
//[0]:0,非叠加显示;1,叠加显示.
void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode)
{
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/LCD_Pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
if(mode&0X80)LCD_ShowChar(x+(size/2)*t,y,'0',size,mode&0X01);
else LCD_ShowChar(x+(size/2)*t,y,' ',size,mode&0X01);
continue;
}else enshow=1;
}
LCD_ShowChar(x+(size/2)*t,y,temp+'0',size,mode&0X01);
}
}
//显示字符串
//x,y:起点坐标
//width,height:区域大小
//size:字体大小
//*p:字符串起始地址
void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p)
{
u8 x0=x;
width+=x;
height+=y;
while((*p<='~')&&(*p>=' '))//判断是不是非法字符!
{
if(x>=width){x=x0;y+=size;}
if(y>=height)break;//退出
LCD_ShowChar(x,y,*p,size,0);
x+=size/2;
p++;
}
}
void LCDOpenWindows(u16 x, u16 y, u16 len, u16 wid)
{
LCD_WR_REG(0X2A);
LCD_WR_DATA(x>>8); //start
LCD_WR_DATA(x-((x>>8)<<8));
LCD_WR_DATA((x+len-1)>>8); //end
LCD_WR_DATA((x+len-1)-(((x+len-1)>>8)<<8));
LCD_WR_REG(0X2B);
LCD_WR_DATA(y>>8);//start
LCD_WR_DATA(y-((y>>8)<<8));
LCD_WR_DATA((y+wid-1)>>8);//end
LCD_WR_DATA((y+wid-1)-(((y+wid-1)>>8)<<8));
LCD_WR_REG(0x2C);
}
/****************************************************************************
* 名称:void ili9341_DrawPicture(u16 StartX,u16 StartY,u16 EndX,u16 EndY,u16 *pic)
* 功能:在指定座标范围显示一副图片
* 入口参数:StartX行起始座标
* StartY列起始座标
* EndX 行结束座标
* EndY 列结束座标
pic图片头指针
* 出口参数:无
* 说明:图片取模格式为水平扫描,16位颜色模式
* 调用方法:ili9320_DrawPicture(0,0,100,100,(u16*)demo);
****************************************************************************/
void ili9341_DrawPicture(u16 StartX,u16 StartY,u16 Xend,u16 Yend,u8 *pic)
{
static u16 i=0,j=0;
u16 *bitmap = (u16 *)pic;
LCDOpenWindows(StartX,StartY,Xend,Yend);
for(i=0;i<Yend;i++)
{
for(j=0;j<Xend;j++) LCD_WriteRAM(*bitmap++);
}
}
void showimage(u16 x,u16 y) //显示40*40图片
{
u16 i,j,k;
u16 da;
k=0;
for(i=0;i<32;i++)
{
LCD_SetCursor(x,y+i);
LCD_WriteRAM_Prepare(); //开始写入GRAM
for(j=0;j<32;j++)
{
da=gImage_ICO1[k*2+1];
da<<=8;
da|=gImage_ICO1[k*2];
LCD_WR_DATA(da);
k++;
}
}
// u16 i,j,k;
// u16 da;
// k=0;
// for(i=0;i<40;i++)
// {
// LCD_SetCursor(x,y+i);
// LCD_WriteRAM_Prepare(); //开始写入GRAM
// for(j=0;j<40;j++)
// {
// da=gImage_ICO1[k*2+1];
// da<<=8;
// da|=gImage_ICO1[k*2];
// LCD_WR_DATA(da);
// k++;
// }
// }
}
void Show_Hanzi(u16 x,u16 y,u8 num,u8 size,u8 mode) //,u8 *font
{
u8 temp,t1,t;
u16 y0=y;
u16 colortemp=POINT_COLOR;
//设置窗口
//num=num-' ';//得到偏移后的值
if(!mode) //非叠加方式
{
for(t=0;t<size*3;t++)
{
// if(size==12)temp=asc2_1206[num][t]; //调用1206字体
// else if(size==16) temp=asc2_1608[num][t]; //调用1608字体
// else if(size==32) temp=asc2_1616[num][t]; //调用1616汉字字体
if(size==24) temp=hanzi16[num][t];
for(t1=0;t1<8;t1++)
{
if(temp&0x80)POINT_COLOR=colortemp;
else POINT_COLOR=BACK_COLOR;
LCD_DrawPoint(x,y);
temp<<=1;
y++;
if(x>=LCDWIDTH){POINT_COLOR=colortemp;return;}//超区域了
if(size==32)
{
if((y-y0)==16)
{
y=y0;
x++;
if(x>=LCDWIDTH){POINT_COLOR=colortemp;return;}//超区域了
break;
}
}
else if((y-y0)==size)
{
y=y0;
x++;
if(x>=LCDWIDTH){POINT_COLOR=colortemp;return;}//超区域了
break;
}
}
}
}else//叠加方式
{
for(t=0;t<size*3;t++)
{
// if(size==12)temp=asc2_1206[num][t]; //调用1206字体
// else if(size==16)temp=asc2_1608[num][t]; //调用1608字体
// else if(size==32) temp=asc2_1616[num][t];
if(size==24) temp=hanzi16[num][t];
for(t1=0;t1<8;t1++)
{
if(temp&0x80)LCD_DrawPoint(x,y);
temp<<=1;
y++;
if(x>=LCDHEIGHT){POINT_COLOR=colortemp;return;}//超区域了
if(size==32)
{
if((y-y0)==16)
{
y=y0;
x++;
if(x>=LCDWIDTH){POINT_COLOR=colortemp;return;}//超区域了
break;
}
}
else if((y-y0)==size)
{
y=y0;
x++;
if(x>=LCDWIDTH){POINT_COLOR=colortemp;return;}//超区域了
break;
}
}
}
}
POINT_COLOR=colortemp;
}
void show_Bkg(void)
{
u16 bkg_x = 0;
u8 bkg_y = 0;
u16 temp_color = BACK_COLOR, temp_color2 = POINT_COLOR;
LCD_Clear(BLACK);
//制氧机
bkg_x = 10;
bkg_y = 18;
LCD_Fill(4,56,158,119,GREEN);
LCD_Fill(160,56,315,119,YELLOW);
LCD_Fill(4,121,158,184,BLUE);
Show_Hanzi(bkg_x,bkg_y,4,24,0);
Show_Hanzi(bkg_x+24,bkg_y,5,24,0);
Show_Hanzi(bkg_x+24*2,bkg_y,6,24,0);
Show_Hanzi(bkg_x+24*3,bkg_y,16,24,0);
Show_Hanzi(bkg_x+24*4,bkg_y,17,24,0);
Show_Hanzi(bkg_x+24*5,bkg_y,18,24,0);
// Show_Hanzi(102,30,3,24,0);
LCD_ShowChar(bkg_x+24*6,bkg_y,':',24,0);
// //氧气
bkg_x = 40;
bkg_y = 64;
BACK_COLOR = GREEN;
Show_Hanzi(bkg_x,bkg_y,9,24,0);
Show_Hanzi(bkg_x+24*2,bkg_y,10,24,0);
BACK_COLOR = temp_color;
// LCD_ShowChar(bkg_x+24*3,bkg_y,':',16,0);
// Show_Hanzi(bkg_x+10,bkg_y+28,2,24,0);
// Show_Hanzi(bkg_x+39,bkg_y+28,3,24,0);
// //弥散
// bkg_y = 98;
bkg_x = 159+40;
BACK_COLOR = YELLOW;
POINT_COLOR = BLACK;
Show_Hanzi(bkg_x,bkg_y,7,24,0);
Show_Hanzi(bkg_x+24*2,bkg_y,8,24,0);
BACK_COLOR = temp_color;
POINT_COLOR = temp_color2;
// Show_Hanzi(bkg_x+10,bkg_y+28,2,24,0);
// Show_Hanzi(bkg_x+39,bkg_y+28,3,24,0);
// LCD_ShowChar(bkg_x+24*3,bkg_y,':',16,0);
// //负离子
bkg_y = 128;
bkg_x = 40;
BACK_COLOR = BLUE;
Show_Hanzi(bkg_x-5,bkg_y,4,24,0);
Show_Hanzi(bkg_x+24,bkg_y,5,24,0);
Show_Hanzi(bkg_x+24*2+5,bkg_y,6,24,0);
BACK_COLOR = temp_color;
// LCD_ShowChar(bkg_x+24*3,bkg_y,':',24,0);
// Show_Hanzi(bkg_x+10,bkg_y+28,2,24,0);
// Show_Hanzi(bkg_x+39,bkg_y+28,3,24,0);
//定时时间
bkg_y = 200;
bkg_x = 30;
Show_Hanzi(bkg_x-5,bkg_y,13,24,0);
Show_Hanzi(bkg_x+24,bkg_y,14,24,0);
Show_Hanzi(bkg_x+24*2+5,bkg_y,14,24,0);
Show_Hanzi(bkg_x+24*3+10,bkg_y,15,24,0);
LCD_ShowChar(bkg_x+24*4+12,bkg_y,':',24,0);
LCD_DrawRectangle(0,0,319,239);
LCD_DrawRectangle(1,1,318,238);
LCD_DrawRectangle(2,2,317,237);
LCD_DrawLine(3,3,3,237);
LCD_DrawLine(316,3,316,237);
LCD_DrawLine(3,55,316,55);
LCD_DrawLine(3,120,316,120);
LCD_DrawLine(3,185,316,185);
LCD_DrawLine(159,55,159,185);
show_time(0);
showimage(280,12);
}
void show_ctr(u8 st, u8 index)
{
u16 bkg_x = 112, temp_color = BACK_COLOR, temp_color2 = POINT_COLOR;
u8 bkg_y = 0;
if(index == 0){
bkg_y = 18;
bkg_x = 178;
}
else if(index == 1){
bkg_y = 92;
bkg_x = 60;
BACK_COLOR = GREEN;
}
else if(index == 2){
bkg_y = 92;
bkg_x = 209;
BACK_COLOR = YELLOW;
POINT_COLOR = BLACK;
}
else if(index == 3){
bkg_y = 156;
bkg_x = 60;
BACK_COLOR = BLUE;
}
else if(index == 4){
bkg_y = 166;
}
if(st==0)//停止
{
Show_Hanzi(bkg_x,bkg_y,2,24,0);
Show_Hanzi(bkg_x+24,bkg_y,3,24,0);
}else //开启
{
BACK_COLOR = BLUE;
POINT_COLOR = BLACK;
Show_Hanzi(bkg_x,bkg_y,0,24,0);
Show_Hanzi(bkg_x+24,bkg_y,1,24,0);
// BACK_COLOR = temp_color;
}
BACK_COLOR = temp_color;
POINT_COLOR = temp_color2;
}
u16 Ctdown_time = 0; //倒计时时间
u8 Ctdown_flag = 0; //倒计时状态
void show_time(u32 num)
{
u32 min = 0, sec = 0;
sec = num % 60;
min = num / 60;
// LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode)
LCD_ShowxNum(172, 200, min, 2, 24, 0);
if(min < 10)
LCD_ShowChar(172, 200,'0', 24, 0);
LCD_ShowChar(172+24+2, 200,':', 24, 0);
LCD_ShowxNum(172+24*2-5, 200, sec, 2, 24, 0);
if(sec < 10)
LCD_ShowChar(172+24*2-5, 200,'0', 24, 0);
}
lcd.h
#ifndef __LCD_H#define __LCD_H #include "sys.h" #include "stdlib.h"#define LCDWIDTH 320#define LCDHEIGHT 240//TFTLCD部分外要调用的函数extern u16 POINT_COLOR;//默认黑色extern u16 BACK_COLOR; //背景颜色.默认为白色extern u16 Ctdown_time; //倒计时时间extern u8 Ctdown_flag; //倒计时状态//扫描方向定义#define L2R_U2D 0 //从左到右,从上到下#define L2R_D2U 1 //从左到右,从下到上#define R2L_U2D 2 //从右到左,从上到下#define R2L_D2U 3 //从右到左,从下到上#define U2D_L2R 4 //从上到下,从左到右#define U2D_R2L 5 //从上倒下,从右到左#define D2U_L2R 6 //从下到上,从左到右#define D2U_R2L 7 //从下到上,从右到左#define DFT_SCAN_DIR U2D_R2L //默认的扫描方向 //////////////////////////////////////////////////////////////////////-----------------LCD端口定义---------------- #define LCD_BL PBout(13) //LCD背光? ? ? ? ? ? ? ? ? ???PB3 #define LCDBKON GPIO_ResetBits(GPIOB, GPIO_Pin_13) #define LCDBKOFF GPIO_SetBits(GPIOB, GPIO_Pin_13) //如果使用快速IO,则定义下句,如果不使用,则去掉即可!//使用快速IO,刷屏速率可以达到28帧每秒!//普通IO,只能14帧每秒! //PB0,PB1,PB10,PB12,PB15//#define CS_PIN 1 //有显示//#define RS_PIN 10//#define WR_PIN 12//#define RD_PIN 0//#define REST_PIN 15#define CS_PIN 1#define RS_PIN 10#define WR_PIN 12#define RD_PIN 0#define REST_PIN 15#define LCD_CS_SET GPIOB->BSRR=1<<CS_PIN //片选端口??? ? ? ?? ?? ?PB7#define LCD_RS_SET GPIOB->BSRR=1<<RS_PIN //数据/命令? ?? ?? ?PB6? ? ? ?? ? #define LCD_WR_SET GPIOB->BSRR=1<<WR_PIN //写数据? ? ? ? ? ? ? ? ? ? ? ???PB5#define LCD_RD_SET GPIOB->BSRR=1<<RD_PIN //读数据? ? ? ? ? ? ? ? ? ? ? ???PB4#define LCD_RESET_SET GPIOB->BSRR=1<<REST_PIN //复位? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???PB3#define LCD_CS_CLR GPIOB->BRR=1<<CS_PIN //片选端口??? ? ? ?? ?? ?#define LCD_RS_CLR GPIOB->BRR=1<<RS_PIN //数据/命令? ?? ?? ? ? ? ? ?? ? #define LCD_WR_CLR GPIOB->BRR=1<<WR_PIN //写数据? ? ? ? ? ? ? ? ? ? ? ???#define LCD_RD_CLR GPIOB->BRR=1<<RD_PIN //读数据? ? ? ? ? ? ? ? ? ? ? ???#define LCD_RESET_CLR GPIOB->BRR=1<<REST_PIN //复位? ? ? ? //写8位数据函数//用宏定义,提高速度.//#define LCD_WR_DATA(data){\//LCD_RS_SET;\//LCD_CS_CLR;\//LCD_RD_SET;\//LCD_WR_CLR;\//DATAOUT(data);\//LCD_WR_SET;\//LCD_CS_SET;\//}//PD0~15,作为数据线#define DATAOUT(x) GPIOC->ODR=x; //数据输出#define DATAIN GPIOC->IDR;//数据输入////////////////////////////////////////////////////////////////////////画笔颜色#define WHITE 0xFFFF#define BLACK 0x0000#define BLUE 0x001F#define BRED 0XF81F#define GRED 0XFFE0#define GBLUE 0X07FF#define RED 0xF800#define MAGENTA 0xF81F#define GREEN 0x07E0#define CYAN 0x7FFF#define YELLOW 0xFFE0#define BROWN 0XBC40 //棕色#define BRRED 0XFC07 //棕红色#define GRAY 0X8430 //灰色#define color1 0xFBEF#define color2 0xEDB1#define color3 0x8410#define color4 0x69a0#define color5 0x52AA#define color6 YELLOW#define bluel0 0xF6CC#define bluel1 0xE60A#define bluel2 0xD549#define bluel3 0xC488#define bluel4 0xB3E7#define bluel5 0xA326#define bluel6 0x9265#define bluel7 0x79A4#define bluel8 0x6903#define bluel9 0x5842#define gray0 0xB575#define gray5 0x73AE#define gray6 0x630C#define gray7 0x526A#define gray8 0x39E8#define gray9 0x2945#define backgroundcolor1 0xEF7D#define backgroundcolor2 0xEDB1#define backgroundcolor3 0x8410#define backgroundcolor4 0xE71C#define backgroundcolor5 0xC638#define backgroundcolor6 gray_L10//----------------------------------------------------------------------#define gray_L0 0X0#define gray_L1 0X821#define gray_L2 0X861#define gray_L3 0X1082#define gray_L4 0X18A3#define gray_L5 0X18C3#define gray_L6 0X2104#define gray_L7 0X2124#define gray_L8 0X2945#define gray_L9 0X3166#define gray_L10 0X31A6#define gray_L11 0X39C7#define gray_L12 0X41E8#define gray_L13 0X4208#define gray_L14 0X4A49#define gray_L15 0X4A69#define gray_L16 0X528A#define gray_L17 0X5AAB#define gray_L18 0X5AEB#define gray_L19 0X630C#define gray_L20 0X6B2D#define gray_L21 0X6B4D#define gray_L22 0X738E#define gray_L23 0X73AE#define gray_L24 0X7BCF#define gray_L25 0X83F0#define gray_L26 0X8430#define gray_L27 0X8C51#define gray_L28 0X9472#define gray_L29 0X9492#define gray_L30 0X9CD3#define gray_L31 0X9CF3#define gray_L32 0XA514#define gray_L33 0XAD35#define gray_L34 0XAD75#define gray_L35 0XB596#define gray_L36 0XBDB7#define gray_L37 0XBDD7#define gray_L38 0XC618#define gray_L39 0XC638#define gray_L40 0XCE59#define gray_L41 0XD67A#define gray_L42 0XD6BA#define gray_L43 0XDEDB#define gray_L44 0XE6FC#define gray_L45 0XE71C#define gray_L46 0XEF5D#define gray_L47 0XEF7D#define gray_L48 0XF79E#define gray_L49 0XFFBF#define gray_L50 0XFFFF//----------------------------------------------------------------------void LCD_WR_REG(u8 data);void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue);void LCD_WriteRAM_Prepare(void);void LCD_WriteRAM(u16 RGB_Code);u16 LCD_BGR2RGB(u16 c);void LCD_DisplayOn(void);void LCD_DisplayOff(void);void LCD_SetCursor(u16 Xpos, u16 Ypos);void LCD_DrawPoint(u16 x,u16 y);//画点void LCD_Fast_DrawPoint(u16 x,u16 y,u16 color);void LCD_Init(void);void LCD_Clear(u16 Color);void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color);void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color);void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2);void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2);void Draw_Circle(u16 x0,u16 y0,u8 r);void Draw_Circle2(u16 x0,u16 y0,u8 r);void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode);//显示一个字符void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size);//显示一个数字void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode);//显示2个数字void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p); //显示一个字符串,16字体void LCDOpenWindows(u16 x, u16 y, u16 len, u16 wid);void ili9341_DrawPicture(u16 StartX,u16 StartY,u16 Xend,u16 Yend,u8 *pic);void Show_Hanzi(u16 x,u16 y,u8 num,u8 size,u8 mode);void show_Bkg(void);void show_ctr(u8 st, u8 index);void show_time(u32 num);#endif
|