void LCD_Img_Binary_Z(Site_t site, Size_t size, uint8 *img, Size_t imgsize) { uint32 temp, tempY; uint16 x, y; uint16 X, Y; uint8 *pimg = (uint8 *)img; LCD_PTLON(site, size); //开窗 LCD_RAMWR(); //写内存 for(y = 0; y < size.H; y++) { Y = ( ( y * imgsize.H ) / size.H) ; tempY = Y * imgsize.W ; for(x = 0; x < size.W; x++) { X = (( x * imgsize.W ) / size.W) ; temp = tempY + X; if( (pimg[temp>>3] & (1 << (7 - (temp & 0x07))) ) == 0 ) { LCD_WR_DATA( BINARY_BGCOLOR ); //写图像数据 } else { LCD_WR_DATA( BINARY_COLOR ); //写图像数据 } } }
void LCD_Img_Binary(Site_t site, Size_t size, uint8 *img) { uint32 total = (size.H * size.W) / 8; uint8 imgtemp; uint8 bitindex; uint8 *pimg = (uint8 *)img; LCD_PTLON(site, size); //开窗 LCD_RAMWR(); //写内存 while(total--) { imgtemp = *(pimg++); bitindex = 8; while(bitindex--) { if( imgtemp & (0x01 << bitindex) ) { LCD_WR_DATA( BINARY_COLOR ); //写图像数据 } else { LCD_WR_DATA( BINARY_BGCOLOR ); //写图像数据 } } } }
//在指定位置显示一个汉字(32*32大小) void showhanzi32(unsigned int x,unsigned int y,unsigned char index) { unsigned char i,j,k; const unsigned char *temp=hanzi32; temp+=index*128; for(j=0;j<32;j++) { LCD_SetCursor(x,y+j); LCD_WriteRAM_Prepare(); //开始写入GRAM for(k=0;k<4;k++) { for(i=0;i<8;i++) { if((*temp&(1<<i))!=0) { LCD_WR_DATA(POINT_COLOR); } else { LCD_WR_DATA(BACK_COLOR); } } temp++; } } }
/************************************************************* * 函数名称:PutGB1616 * 功 能:在指定位置显示单个汉字 * 参 数: * x: 窗体中X坐标中较小者 * y: 窗体中Y坐标中较小者 * C[]:待显示的汉字 * fColor:字体颜色 * bColor:背景颜色 * 返 回 值:无 *************************************************************/ void LCD_PutGB1616(u16 x, u16 y, u8 c[2], u16 fColor,u16 bColor) { unsigned int i,j,k; char_or_word=1; //设置为显示汉字,为0则为显示字符 LCD_SetPos(x,y); for(k=0;k<67;k++) { //64标示自建汉字库中的个数,循环查询内码 if ((codeGB_16[k].Index[0]==c[0])&&(codeGB_16[k].Index[1]==c[1])) //找到对应的汉字 { for(i=0;i<32;i++) { unsigned short m=codeGB_16[k].Msk[i]; for(j=0;j<8;j++) { if((m&0x80)==0x80) LCD_WR_DATA(fColor); //开始写入汉字颜色 else LCD_WR_DATA(bColor); //开始写入背景颜色 m<<=1; } } break; } } }
//设置一个GRAM范围以进行连续读写 void LCD_SetWindow(u16 x1,u16 y1,u16 x2,u16 y2) { LCD_WR_REG(0x0046);LCD_WR_DATA((x2<<8)| x1); //水平方向起点(高8位)和终点(低8位)坐标 LCD_WR_REG(0x0047);LCD_WR_DATA(y2); //垂直方向终点坐标 LCD_WR_REG(0x0048);LCD_WR_DATA(y1); //垂直方向起始坐标 //设置起点 LCD_WR_REG(0x0020);LCD_WR_DATA(x1); //定位横坐标 LCD_WR_REG(0x0021);LCD_WR_DATA(y1); //定位纵坐标 //开始写 LCD_WR_REG(0x0022); }
/************************************************* 函数名:LCD_SetWindows 功能:设置lcd显示窗口,在此区域写点数据自动换行 入口参数:xy起点和终点 返回值:无 *************************************************/ void LCD_SetWindows(u16 xStar, u16 yStar,u16 xEnd,u16 yEnd) { #if USE_HORIZONTAL==1 //使用横屏 LCD_WR_REG(lcddev.setxcmd); LCD_WR_DATA(xStar>>8); LCD_WR_DATA(0x00FF&xStar+3); LCD_WR_DATA(xEnd>>8); LCD_WR_DATA(0x00FF&xEnd+3); LCD_WR_REG(lcddev.setycmd); LCD_WR_DATA(yStar>>8); LCD_WR_DATA(0x00FF&yStar+2); LCD_WR_DATA(yEnd>>8); LCD_WR_DATA(0x00FF&yEnd+2); #else LCD_WR_REG(lcddev.setxcmd); LCD_WR_DATA(xStar>>8); LCD_WR_DATA(0x00FF&xStar+2); LCD_WR_DATA(xEnd>>8); LCD_WR_DATA(0x00FF&xEnd+2); LCD_WR_REG(lcddev.setycmd); LCD_WR_DATA(yStar>>8); LCD_WR_DATA(0x00FF&yStar+3); LCD_WR_DATA(yEnd>>8); LCD_WR_DATA(0x00FF&yEnd+3); #endif LCD_WriteRAM_Prepare(); //开始写入GRAM }
void LCD_Address_set(uint x1,uint y1,uint x2,uint y2) { LCD_WR_REG(0x002A); LCD_WR_DATA(x1>>8); LCD_WR_DATA(x1&0x00ff); LCD_WR_DATA(x2>>8); LCD_WR_DATA(x2&0x00ff); LCD_WR_REG(0x002b); LCD_WR_DATA(y1>>8); LCD_WR_DATA(y1&0x00ff); LCD_WR_DATA(y2>>8); LCD_WR_DATA(y2&0x00ff); LCD_WR_REG(0x002c); }
/*! * @brief 画点 * @param site 左上角坐标 * @param rgb565 颜色 * @since v5.0 * Sample usage: Site_t site = {10,20}; //x = 10 ,y = 20 LCD_point(site, RED); */ void LCD_point(Site_t site, uint16 rgb565) { Size_t size = {1, 1}; LCD_PTLON(site, size); LCD_RAMWR(); //写内存 LCD_WR_DATA(rgb565); //写数据 }
/************************************************************* * 函数名称:LCD_TEST_Picture1 * 功 能:显示图片 * 参 数: * *picture1:待显示的图片数组 * 返 回 值:无 * 说 明:直接把图片颜色数据烧入FLASH,实在太占空间,最好 * 使用别的方法,比如放入SD卡,直接读BMP格式。 * 如果这样使用时,一定要设置好待显示的图片的长宽, * 否则显示不出效果。 *************************************************************/ void LCD_TEST_Picture1(unsigned char const *picture1) { unsigned char i,j; u16 picdata,pixH,pixL; if (horizontal_or_vertical) { LCD_WR_CMD(0x0044,0xef00); //hs 横屏时 LCD_WR_CMD(0x0046,0x00ef); //vs } else { LCD_WR_CMD(0x0044,0xef00); //hs 竖屏时 LCD_WR_CMD(0x0046,0x013f); } LCD_WR_CMD(0x004e,0x0000); //h LCD_WR_CMD(0x045,0x0000); //he LCD_WR_CMD(0x004f,0x0000); //v LCD_WR_ADD(0x0022); for (i=0;i<240;i++) for (j=0;j<180;j++) { pixH=*picture1++; pixL=*picture1++; picdata=((pixH<<8)+pixL); LCD_WR_DATA(picdata); } }
//mode:叠加方式(1)还是非叠加方式(0) void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode) { u8 temp; u8 pos,t; u16 x0=x; u16 colortemp=POINT_COLOR; if(x>LCD_W-16||y>LCD_H-16)return; //设置窗口 num=num-' ';//得到偏移后的值 Address_set(x,y,x+8-1,y+16-1); //设置光标位置 if(!mode) //非叠加方式 { for(pos=0; pos<16; pos++) { temp=asc2_1608[(u16)num*16+pos]; //调用1608字体 for(t=0; t<8; t++) { if(temp&0x01)POINT_COLOR=colortemp; else POINT_COLOR=BACK_COLOR; LCD_WR_DATA(POINT_COLOR); temp>>=1; x++; } x=x0; y++; } } else//叠加方式 { for(pos=0; pos<16; pos++)
/*! * @brief 缩放灰度图像显示 * @param site 左上角坐标 * @param size 显示图像大小 * @param img 图像地址 * @param imgsize 图像大小 * @since v5.0 * Sample usage: Site_t site = {10,20}; //x = 10 ,y = 20 Size_t size = {80,60}; //W = 80,H = 60 Size_t imgsize = {320,240}; //W = 320,H = 240 LCD_Img_gray_Z(site, size, img,imgsize); */ void LCD_Img_gray_Z(Site_t site, Size_t size, uint8 *img, Size_t imgsize) { uint32 temp, tempY; uint16 x, y; uint16 X, Y; uint8 *pimg = (uint8 *)img; uint16 rgb; LCD_PTLON(site, size); //开窗 LCD_RAMWR(); //写内存 for(y = 0; y < size.H; y++) { Y = ( ( y * imgsize.H ) / size.H) ; tempY = Y * imgsize.W ; for(x = 0; x < size.W; x++) { X = ( x * imgsize.W ) / size.W ; temp = tempY + X; rgb = GRAY_2_RGB565(pimg[temp]); // LCD_WR_DATA(rgb); } } }
void LCD_ShowChar(uint x,uint y,uchar num,uchar mode) { uchar temp; uchar pos,t; uint x0=x; uint colortemp=POINT_COLOR; if(x>LCD_W-16||y>LCD_H-16)return; num=num-' '; LCD_Address_set(x,y,x+8-1,y+16-1); if(!mode) { for(pos=0;pos<16;pos++) { temp=asc2_1608[(uint)num*16+pos]; for(t=0;t<8;t++) { if(temp&0x01) POINT_COLOR=colortemp; else POINT_COLOR=BACK_COLOR; LCD_WR_DATA(POINT_COLOR); temp>>=1; x++; } x=x0; y++; } } else { for(pos=0;pos<16;pos++)
/************************************************************* * 函数名称:LCD_DrawRec * 功 能:在指定位置画矩形 * 参 数: * x: 窗体中X坐标中始点 * y: 窗体中Y坐标中始点 * Length:条形的长 * High: 矩形的高 * Colour:矩形的颜色 * 返 回 值:无 *************************************************************/ void LCD_DrawRec(u16 x,u16 y,u16 Length,u16 High,u16 Colour) { u16 i; if(horizontal_or_vertical) //横屏显示时 { if(x+Length>320) Length=320-Length; if(High+y>240) High=240-High; LCD_SetPosition(x,y); LCD_WR_CMD(0X0044,((High+y-1)<<8)+y); LCD_WR_CMD(0X0046,x+Length); } else //竖屏显示时 { if(x+Length>240) Length=240-Length; if(High+y>320) High=320-High; LCD_SetPosition(x,y); LCD_WR_CMD(0X0044,((Length+x-1)<<8)+x); LCD_WR_CMD(0X0046,y+High); } LCD_WR_ADD(0x0022); for(i=0;i<Length*High;i++) { LCD_WR_DATA(Colour); } }
/************************************************************* * 函数名称:LCD_DrawCir * 功 能:在指定位置画圆 * 参 数: * x: 窗体中圆心坐标 * y: 窗体中圆心坐标 * r: 圆的半径 * Colour:圆的颜色 * 返 回 值:无 *************************************************************/ void LCD_DrawCir(u16 x,u16 y,u16 r,u16 Colour) { u16 i,j; if(horizontal_or_vertical) //横屏显示时 { if(x+r>320||r-x>0) LCD_PutString(19,190,"ERRO!",Red,Black); if(r+y>240||r-y>0) LCD_PutString(19,190,"ERRO!",Red,Black); LCD_WR_CMD(0x0044,(y+r-1)<<8); LCD_WR_CMD(0x004e,y-r); //设置X方向初始值 /*R45、R46 垂直方向的起、止点*/ LCD_WR_CMD(0x0045,x-r); LCD_WR_CMD(0x0046,x+r-1); LCD_WR_CMD(0x004f,x-r); //设置y方向初始值 } else //竖屏显示时 { if(x+r>240||r-x>0) LCD_PutString(19,190,"ERRO!",Red,Black);; if(r+y>320||r-y>0) LCD_PutString(19,190,"ERRO!",Red,Black);; LCD_WR_CMD(0x0044,((x+r-1)<<8)+x-r); LCD_WR_CMD(0x004e,x-r); //设置X方向初始值 /*R45、R46 垂直方向的起、止点*/ LCD_WR_CMD(0x0045,y-r); LCD_WR_CMD(0x0046,y+r-1); LCD_WR_CMD(0x004f,y-r); //设置y方向初始值 } LCD_WR_ADD(0x0022); for(i=0;i<2*r;i++) for(j=0;j<2*r;j++) { if((abs(r-i)*abs(r-i)+abs(r-j)*abs(r-j))<=r*r) LCD_WR_DATA(Colour); else { LCD_WR_DATA(Red); } } }
//水平线,向右 void GUI_HLine(u8 x, u16 y, u8 length, u16 color) { GUI_SetWindow(x,y,x+length-1,y); do { LCD_WR_DATA(color);//逐点显示,描出水平线 length--; }while(length); }
//在指定区域内填充指定颜色 //区域大小: // (xend-xsta)*(yend-ysta) void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color) { u16 i,j; Address_set(xsta,ysta,xend,yend); //设置光标位置 for(i=ysta; i<=yend; i++) { for(j=xsta; j<=xend; j++)LCD_WR_DATA(color); //设置光标位置 } }
void LCD_Fill(uint xsta,uint ysta,uint xend,uint yend,uint color) { uint i,j; LCD_Address_set(xsta,ysta,xend,yend); for(i=ysta;i<=yend;i++) { for(j=xsta;j<=xend;j++)LCD_WR_DATA(color); } }
/************************************************************* * 函数名称:LCD_PutChar * 功 能:在指定位置显示一个字符 * 参 数: * x: 窗体中X坐标中较小者 * y: 窗体中Y坐标中较小者 * c:待显示的字符 * fColor:字体颜色 * bColor:背景颜色 * 返 回 值:无 *************************************************************/ void LCD_PutChar8x16(u16 x, u16 y, char c, u16 fColor, u16 bColor) { unsigned int i,j; char_or_word=0; //设置为显示为字符,1则为显示汉字 LCD_SetPos(x,y); for(i=0; i<16;i++) { unsigned char m=Font8x16[c*16+i]; //直接找到字符 for(j=0;j<8;j++) { if((m&0x80)==0x80) LCD_WR_DATA(fColor); else LCD_WR_DATA(bColor); m<<=1; } } }
//垂直线,向下 void GUI_VLine(u8 x, u16 y, u16 high, u16 color) { GUI_SetWindow(x,y,x,y+high-1); do { LCD_WR_DATA(color);// 逐点显示,描出垂直线 high--; }while(high); }
void LCD_Clear(u16 Color) { u32 index=0; LCD_SetCursor(0x00,0x0000);//设置光标位置 LCD_WR_REG(R34); for(index=0;index<76800;index++) { LCD_WR_DATA(Color); } }
//清屏函数 //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); } }
int main() { Clr_BUFFER_FLAG(); alt_video_display Display; TOUCH_HANDLE *pTouch; printf("Hi There !\n"); // Write 0x3C on LED[6:0] through the dedicated custom IP IOWR(LED_CTRL_BASE, 0x0, 0x3C); // TOUCH INITIALIZATION pTouch = Touch_Init(LT24_TOUCH_SPI_BASE, LT24_TOUCH_PENIRQ_N_BASE, LT24_TOUCH_PENIRQ_N_IRQ); if (!pTouch){ printf("Failed to init touch\r\n"); }else{ printf("Init touch successfully\r\n"); } // LCD INITIALIZATION LCD_Init(); // Pattern example //LCD_Pattern_Horizon(); // Sleep 3s //usleep(3*1000*1000); Set_BUFFER_FLAG(); unsigned int X, Y; unsigned int posTamper =0; while(1){ if(Touch_GetXY(pTouch, &X, &Y)){ //printf("X: %d Y: %d\n",X,Y); LCD_WR_DATA(Y); LCD_WR_REG(X); //we can modify the character (the image become progressively red when we touch it), we might do the same for the background IOWR_16DIRECT(PIC_MEM_BASE,posTamper,0xF800); posTamper++; } } // Painter demo /*Clr_BUFFER_FLAG(); Display.interlace = 0; Display.bytes_per_pixel = 2; Display.color_depth = 16; Display.height = SCREEN_HEIGHT; Display.width = SCREEN_WIDTH; GUI(&Display, pTouch);*/ return 0; }
//在指定区域内填充单个颜色 //(sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1) //color:要填充的颜色 void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color) { uint16_t i,j; uint16_t xlen=0; xlen=ex-sx+1; for(i=sy;i<=ey;i++) { LCD_SetCursor(sx,i); //设置光标位置 LCD_WriteRAM_Prepare(); //开始写入GRAM for(j=0;j<xlen;j++)LCD_WR_DATA(color); //设置光标位置 } }
//清屏 void LCD_Clear(u16 Color) { u16 i,j; LCD_SetWindow(0,0,LCD_WIDTH-1,LCD_HEIGHT-1); for(i=0;i<LCD_WIDTH;i++) { for (j=0;j<LCD_HEIGHT;j++) { LCD_WR_DATA(Color); } } }
/*! * @brief 显示实心矩形 * @param site 左上角坐标 * @param size 矩形大小 * @param rgb565 颜色 * @since v5.0 * Sample usage: Site_t site = {10,20}; //x = 10 ,y = 20 Size_t size = {50,60}; // W = 50 ,H = 60 LCD_rectangle(site, size, RED); */ void LCD_rectangle(Site_t site, Size_t size, uint16 rgb565) { uint32 n, temp; LCD_PTLON(site, size); //开窗 temp = (uint32)size.W * size.H; LCD_RAMWR(); //写内存 for(n = 0; n < temp; n++) { LCD_WR_DATA( rgb565 ); //写数据 } }
//在指定区域内填充指定颜色 //区域大小: // (xend-xsta)*(yend-ysta) void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color) { u16 i,j; u16 xlen=0; #if USE_HORIZONTAL==1 xlen=yend-ysta+1; for(i=xsta;i<=xend;i++) { LCD_SetCursor(i,ysta); //设置光标位置 LCD_WriteRAM_Prepare(); //开始写入GRAM for(j=0;j<xlen;j++)LCD_WR_DATA(color);//设置光标位置 } #else 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);//设置光标位置 } #endif }
/*! * @brief 显示字符 * @param site 左上角坐标 * @param ascii 字符 * @param Color 字体颜色 * @param bkColor 背景颜色 * @since v5.0 * Sample usage: Site_t site = {10,20}; //x = 10 ,y = 20 LCD_char(site,'0', BLUE,RED); */ void LCD_char(Site_t site, uint8 ascii, uint16 Color, uint16 bkColor) { #define MAX_CHAR_POSX (LCD_W-8) #define MAX_CHAR_POSY (LCD_H-16) uint8 temp, t, pos; Size_t size = {8, 16}; if(site.x > MAX_CHAR_POSX || site.y > MAX_CHAR_POSY) { return; } LCD_PTLON(site, size); LCD_RAMWR(); //写内存 for (pos = 0; pos < 16; pos++) { temp = ascii_8x16[((ascii-0x20)*16)+pos]; for(t = 0; t < 8; t++) { if(temp & 0x80) { LCD_WR_DATA(Color); } else { LCD_WR_DATA(bkColor); } temp <<= 1; } } return; #undef MAX_CHAR_POSX #undef MAX_CHAR_POSY }
/*! * @brief 灰度图像显示 * @param site 左上角坐标 * @param size 显示图像大小 * @param img 图像地址 * @since v5.0 * Sample usage: Site_t site = {10,20}; //x = 10 ,y = 20 Size_t size = {320,240}; //W = 320,H = 240 LCD_Img_gray(site, size, img); */ void LCD_Img_gray(Site_t site, Size_t size, uint8 *img) { uint32 total = (size.H * size.W); uint16 imgtemp; uint8 *pimg = (uint8 *)img; LCD_PTLON(site, size); //开窗 LCD_RAMWR(); //写内存 while(total--) { imgtemp = (uint16) * (pimg++); imgtemp = GRAY_2_RGB565(imgtemp); LCD_WR_DATA( imgtemp ); //写图像数据 } }
/************************************************************* * 函数名称:LCD_DrawLine * 功 能:在指定位置画条长度为Length的线 * 参 数: * x: 窗体中X坐标中始点 * y: 窗体中Y坐标中始点 * Length:线的长度,长度大于屏幕时,截去 * Colour:线的颜色 * 返 回 值:无 *************************************************************/ void LCD_DrawLine(u16 x,u16 y,u16 Length,u16 Colour) { u16 i; if(horizontal_or_vertical) //横屏显示时 { if(x+Length>320) Length=320-Length; } else { if(x+Length>240) Length=240-Length; } LCD_SetPosition(x,y); for(i=0;i<Length;i++) LCD_WR_DATA(Colour); }
void showimage(uint16_t x,uint16_t y) //显示40*40图片 { uint16_t i,j,k; uint16_t 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=qqimage[k*2+1]; da<<=8; da|=qqimage[k*2]; LCD_WR_DATA(da); k++; } } }