کد:
#include "stm32f1xx_hal.h"
#include "font.h"
#include "hardware.h"
#include "ili932x.h"
#include "delay.h"
//#include "PE & EN font1.h"
//#include "FAmap.h"
int font_color,x_font,y_font;
char highlight,fa_num;
char effect = 0 , italic = 0;
unsigned int highlight_color;
/* Global Variables */
int x_base=0;
#define LCD_REG (*((volatile unsigned short *) 0x60000000)) /* RS = 0 */
#define LCD_RAM (*((volatile unsigned short *) 0x60020000)) /* RS = 1 */
#define u32 long
#define unit8_t char
#define uint8_t char
#define unit32_t long
#define uint32_t long
#define uint16_t int
unsigned int HDP=479;
unsigned int HT=531;
unsigned int HPS=43;
unsigned int LPS=8;
unsigned char HPW=10;
unsigned int VDP=271;
unsigned int VT=288;
unsigned int VPS=12;
unsigned int FPS=4;
unsigned char VPW=10;
uint16_t DeviceCode;
void WriteOneCharF4(int x, int y, u8 num, u16 PenColor)
{
u16 size = 16;
u16 temp;
u16 pos,t;
//num=num-' ';
for(pos=0;pos<size;pos++)
{
//temp=asc2_1608[num][pos]; //temp=mmb_1808[num][pos];
temp= image_code[num][pos];
for(t=0;t<size;t++)
{
if(temp&0x01) //if(temp&0x01)
{
LCD_DrawPixel(x+t , y+pos , PenColor);
}
temp>>=1;
}
}
}
////////////////////////////////////////////////////
void WriteOneChar(u16 x, u16 y, u8 num, u16 PenColor, u16 BackColor)
{
u8 size = 16;
u8 temp;
u8 pos,t;
num=num-' '; /*??????? */
for(pos=0;pos<size;pos++)
{
if(size==12)
temp=asc2_1206[num][pos];
else
temp=asc2_1608[num][pos];
for(t=0;t<size/2;t++)
{
if(temp&0x01)
{
LCD_DrawPixel(x+t, y+pos, PenColor); /*????? ???*/
}
else
LCD_DrawPixel(x+t, y+pos, BackColor); /*????? ???*/
temp>>=1;
}
}
}
////////////////////////////////////////////////////
void LCD_WR_REG(uint16_t LCD_Reg)
{
// RD_SET; /*???*/
// CS_CLR; /*??*/
// RS_CLR; /*0????*/
// DataToWrite(LCD_Reg);
// WR_CLR;
// WR_SET; /*?????*/
// CS_SET;
LCD_REG = LCD_Reg;
}
////////////////////////////////////////////////////
void LCD_WR_DATA(uint16_t LCD_Data)
{
// RD_SET; /*???*/
// CS_CLR;
// RS_SET; /*1????*/
// DataToWrite(LCD_Data);
// WR_CLR;
// WR_SET; /*?????*/
// CS_SET;
LCD_RAM = LCD_Data;
}
////////////////////////////////////////////////////
void lcd_goto_xy(int x,int y)
{
if((x >= TS_SIZE_X) || (x < 0))
{
x_font = 0;
x_base = 0;
}
else
{
x_font = x;
x_base = x;
}
if((y >= TS_SIZE_Y) || (y < 0))
y_font = 0;
else
y_font = y;
}
////////////////////////////////////////////////////
//void LCD_WriteReg2(uint16_t LCD_Reg ,uint16_t LCD_RegValue)
//{
//// RD_SET; /*???*/
//// CS_CLR; /*??*/
//// RS_CLR; /*0????*/
//// DataToWrite(LCD_Reg);
//// WR_CLR;
//// WR_SET; /*?????*/
//// RS_SET; /*1????*/
//// DataToWrite(LCD_RegValue);
//// WR_CLR;
//// WR_SET; /*?????*/
//// CS_SET;
//LCD_REG = LCD_Reg;
//LCD_RAM = LCD_RegValue;
//}
////////////////////////////////////////////////////
void LCD_WR_DATA_Prepare(void)
{
LCD_WR_REG(0x002C);
}
////////////////////////////////////////////////////
void LCD_SetCursor(u16 Xpos, u16 Ypos)
{
LCD_WR_REG(0x002A);
LCD_WR_DATA(Xpos>>8);
LCD_WR_DATA(Xpos&0x00ff);
LCD_WR_DATA(800>>8);
LCD_WR_DATA(800&0x00ff);
LCD_WR_REG(0x002b);
LCD_WR_DATA(Ypos>>8);
LCD_WR_DATA(Ypos&0x00ff);
LCD_WR_DATA(480>>8);
LCD_WR_DATA(480&0x00ff);
}
////////////////////////////////////////////////////
void LCD_Clear(uint16_t Color)
{
unsigned int l=480,w,f;
LCD_WR_REG(0X002A);
LCD_WR_DATA(0);
LCD_WR_DATA(0);
LCD_WR_DATA(HDP>>8);
LCD_WR_DATA(HDP&0XFF);
/* Y? */
LCD_WR_REG(0X002B);
LCD_WR_DATA(0);
LCD_WR_DATA(0);
LCD_WR_DATA(VDP>>8);
LCD_WR_DATA(VDP&0X00FF);
LCD_WR_REG(0X002C);
while(l--) /* 480? */
{
for(w = 0; w < HDP+1; w++) /* ??800???? */
{
f = 50;
LCD_WR_DATA(Color);
}
}
}
////////////////////////////////////////////////////
void LCD_DrawPixel(uint16_t xsta, uint16_t ysta, uint16_t color)
{
LCD_SetCursor(xsta, ysta); /*?????? */
LCD_WR_DATA_Prepare(); /*????GRAM */
LCD_WR_DATA(color);
}
void LCD_DrawPixel2(uint16_t xsta, uint16_t ysta, uint16_t color)
{
//LCD_SetCursor(xsta, ysta); /*?????? */
LCD_WR_DATA_Prepare(); /*????GRAM */
LCD_WR_DATA(color);
}
////////////////////////////////////////////////////
void LCD_WindowMax (unsigned int xsta,unsigned int ysta,unsigned int xend,unsigned int yend)
{
LCD_WR_REG(0X002A);
LCD_WR_DATA(xsta>>8);
LCD_WR_DATA(xsta&0X00FF);
LCD_WR_DATA(xend>>8);
LCD_WR_DATA(xend&0X00FF);
LCD_WR_REG(0X002B);
LCD_WR_DATA(ysta>>8);
LCD_WR_DATA(ysta&0X00FF);
LCD_WR_DATA(yend>>8);
LCD_WR_DATA(yend&0X00FF);
}
////////////////////////////////////////////////////
void LCD_Fill(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t colour)
{
u32 n;
LCD_WindowMax (xsta, ysta, xend, yend);
LCD_WR_DATA_Prepare();
n=(u32)(yend-ysta+1)*(xend-xsta+1);
while(n--){LCD_WR_DATA(colour);}
}
////////////////////////////////////////////////////
void LCD_DrawLine(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color)
{
int x, y, t;
if((xsta==xend)&&(ysta==yend))
LCD_DrawPixel(xsta, ysta, color);
else
if(abs(yend-ysta)>abs(xend-xsta))
{
if(ysta>yend)
{
t=ysta;
ysta=yend;
yend=t;
t=xsta;
xsta=xend;
xend=t;
}
for(y=ysta;y<yend;y++)
{
x=(u32)(y-ysta)*(xend-xsta)/(yend-ysta)+xsta;
LCD_DrawPixel(x, y, color);
}
}
else
{
if(xsta>xend)
{
t=ysta;
ysta=yend;
yend=t;
t=xsta;
xsta=xend;
xend=t;
}
for(x=xsta;x<=xend;x++)
{
y =(u32)(x-xsta)*(yend-ysta)/(xend-xsta)+ysta;
LCD_DrawPixel(x, y, color);
}
}
}
////////////////////////////////////////////////////
void Draw_Circle(uint16_t x0, uint16_t y0, uint8_t r, uint16_t color)
{
int a,b;
int di;
a=0;b=r;
di=3-(r<<1);
while(a<=b)
{
LCD_DrawPixel(x0-b, y0-a, color); //3
LCD_DrawPixel(x0+b, y0-a, color); //0
LCD_DrawPixel(x0-a, y0+b, color); //1
LCD_DrawPixel(x0-b, y0-a, color); //7
LCD_DrawPixel(x0-a, y0-b, color); //2
LCD_DrawPixel(x0+b, y0+a, color); //4
LCD_DrawPixel(x0+a, y0-b, color); //5
LCD_DrawPixel(x0+a, y0+b, color); //6
LCD_DrawPixel(x0-b, y0+a, color);
a++;
if(di<0)di +=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
LCD_DrawPixel(x0+a, y0+b, color);
}
}
////////////////////////////////////////////////////
void LCD_DrawRectangle(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color)
{
LCD_DrawLine(xsta, ysta, xend, ysta, color);
LCD_DrawLine(xsta, ysta, xsta, yend, color);
LCD_DrawLine(xsta, yend, xend, yend, color);
LCD_DrawLine(xend, ysta, xend, yend, color);
}
////////////////////////////////////////////////////
u32 mypow(u8 m,u8 n)
{
u32 result=1;
while(n--)result*=m;
return result;
}
////////////////////////////////////////////////////
void LCD_ShowNum(uint16_t x,uint16_t y,u32 num,u8 len, u16 PenColor, u16 BackColor)
{
u8 size = 16;
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/mypow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
WriteOneChar(x+(size/2)*t,y, ' ', PenColor, BackColor);
continue;
}else enshow=1;
}
WriteOneChar(x+(size/2)*t,y,temp+'0', PenColor, BackColor);
}
}
////////////////////////////////////////////////////
u16 findHzIndex(u8 *hz)
{
u16 i=0;
FNT_GB16 *ptGb16 = (FNT_GB16 *)GBHZ_16;
while(ptGb16[i].Index[0] > 0x80)
{
if ((*hz == ptGb16[i].Index[0]) && (*(hz+1) == ptGb16[i].Index[1]))
{
return i;
}
i++;
if(i > (sizeof((FNT_GB16 *)GBHZ_16) / sizeof(FNT_GB16) - 1))
{
break;
}
}
return 0;
}
////////////////////////////////////////////////////
uint8_t WriteOneHz(u16 x0, u16 y0, u8 *pucMsk, u16 PenColor, u16 BackColor)
{
u16 i,j;
u16 mod[16];
u16 *pusMsk;
u16 y;
int size = 16;
pusMsk = (u16 *)pucMsk;
for(i=0; i<16; i++)
{
mod[i] = *pusMsk;
mod[i] = ((mod[i] & 0xff00) >> 8) | ((mod[i] & 0x00ff) << 8);
pusMsk = pusMsk+1;
}
y = y0;
for(i=0; i<16; i++)
{
for(j=0; j<16; j++)
{
if((mod[i] << j) & 0x8000)
{
LCD_DrawPixel(x0+j, y0+i, PenColor);
}
else
{
LCD_DrawPixel(x0+j, y0+i, BackColor);
}
}
y++;
}
return (16);
}
////////////////////////////////////////////////////
void LCD_ShowString(u16 x0, u16 y0, u8 *pcStr, u16 PenColor, u16 BackColor)
{
u16 usIndex;
u16 usWidth = 0;
FNT_GB16 *ptGb16 = 0;
ptGb16 = (FNT_GB16 *)GBHZ_16;
while(1)
{
if(*pcStr == 0)
{
break;
}
x0 = x0 + (usWidth);
if(*pcStr > 0x80)
{
if((x0 + 16) > LCD_W)
{
x0 = 0;
y0 = y0 + 16;
if(y0 > LCD_H)
{
y0 = 0;
}
}
usIndex = findHzIndex(pcStr);
usWidth = WriteOneHz(x0, y0, (u8 *)&(ptGb16[usIndex].Msk[0]), PenColor, BackColor);
/* ???? */
pcStr += 2;
}
else
{ /* ?????? */
if (*pcStr == '\r') /* ?? */
{
y0 = y0 + 16; /* ?????? */
if(y0 > LCD_H) /* ????? */
{
y0 = 0;
}
pcStr++;
usWidth = 0;
continue;
}
else if (*pcStr == '\n') /* ????? */
{
x0 = 0;
pcStr++;
usWidth = 0;
continue;
}
else
{
if((x0 + 8) > LCD_W) /* ?????????? */
{
x0 = 0;
y0 = y0 + 16; /* ?????? */
if(y0 > LCD_H) /* ????? */
{
y0 = 0;
}
}
WriteOneChar(x0, y0, *pcStr, PenColor, BackColor);
usWidth = 8;
/* ASCII??21H???????3?*/
pcStr += 1;
}
}
}
}
////////////////////////////////////////////////////
u16 LCD_RGBtoBGR(u16 Color)
{
u16 r, g, b, bgr;
b = (Color>>0) & 0x1f; /* ??B */
g = (Color>>5) & 0x3f; /* ???? */
r = (Color>>11) & 0x1f; /* ??R */
bgr = (b<<11) + (g<<5) + (r<<0);
return( bgr );
}
////////////////////////////////////////////////////
void LCD_DrawPicture(u16 StartX,u16 StartY,u16 Xend,u16 Yend,u8 *pic)
{
static u16 i=0,j=0;
u16 *bitmap = (u16 *)pic;
for(j=0; j<Yend-StartY; j++)
{
for(i=0; i<Xend-StartX; i++)
LCD_DrawPixel(StartX+i, StartY+j, *bitmap++);
}
}
////////////////////////////////////////////////////
////////////////////////////////////////////////////
void LCD_Configuration()
{
// GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
// __HAL_RCC_GPIOC_CLK_ENABLE();
// __HAL_RCC_GPIOB_CLK_ENABLE();
//__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
// |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
// |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
// |GPIO_PIN_12|GPIO_PIN_13
// , GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
// HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
// |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12
// |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
// , GPIO_PIN_SET);
/*Configure GPIO pins : PC13 PC0 PC1 PC2
PC3 PC4 PC5 PC6
PC7 PC8 PC9 PC10
PC11 PC12 */
// GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
// |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
// |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
// |GPIO_PIN_12|GPIO_PIN_13;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : PB10 PB11 PB12 PB13
PB14 PB15 PB5 PB6
PB7 PB8 PB9 */
//GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
// |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
//GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
//GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
//HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
void LCD_Init(void)
{
//SSD_RESET;
//LCD_Configuration();lcd_write_command
#define LCD_WriteCom LCD_WR_REG
#define LCD_WriteRAM LCD_WR_DATA
#define SSD1963_WriteCommand LCD_WriteCom
#define SSD1963_WriteData LCD_WriteRAM
#define TimeDelay(x) Delay_10ms(x/2)
LCD_WriteCom(0x0001); // software reset
LCD_WriteCom(0x0001); // software reset
LCD_WriteCom(0x0001); // software reset
/*ssd1963?????*/
LCD_WriteCom(0x00E2);
LCD_WriteRAM(0x0023);
// Set PLL with OSC = 10MHz (hardware)
// Multiplier N = 35, VCO (>250MHz)= OSC*(N+1), VCO = 360MHz
LCD_WriteRAM(0x0001);
// Divider M = 2, PLL = 360/(M+1) = 120MHz
LCD_WriteRAM(0x0004);
// Validate M and N values
SSD1963_WriteCommand(SSD1963_SET_PLL_MN);
SSD1963_WriteData(0x1D); // PLLclk = REFclk * 30 (300MHz)
SSD1963_WriteData(0x02); // SYSclk = PLLclk / 3 (100MHz)
SSD1963_WriteData(0x54); // dummy
TimeDelay(1);
LCD_WriteCom(0x00E0); // PLL enable
LCD_WriteRAM(0x0001);
TimeDelay(50);
LCD_WriteCom(0x00E0);
LCD_WriteRAM(0x0003);
TimeDelay(1);
LCD_WriteCom(0x0001); // software reset
TimeDelay(1);
LCD_WriteCom(0x00E6);
LCD_WriteRAM(0x0004);
LCD_WriteRAM(0x0093);
LCD_WriteRAM(0x00e0);
LCD_WriteCom(0x00B0); //LCD SPECIFICATION
LCD_WriteRAM(0x0000);
LCD_WriteRAM(0x0000);
LCD_WriteRAM((HDP>>8)&0X00FF); //Set HDP
LCD_WriteRAM(HDP&0X00FF);
LCD_WriteRAM((VDP>>8)&0X00FF); //Set VDP
LCD_WriteRAM(VDP&0X00FF);
LCD_WriteRAM(0x0000);
TimeDelay(1);
LCD_WriteCom(0x00B4); //HSYNC
LCD_WriteRAM((HT>>8)&0X00FF); //Set HT
LCD_WriteRAM(HT&0X00FF);
LCD_WriteRAM((HPS>>8)&0X00FF); //Set HPS
LCD_WriteRAM(HPS&0X00FF);
LCD_WriteRAM(HPW); //Set HPW
LCD_WriteRAM((LPS>>8)&0X00FF); //Set HPS
LCD_WriteRAM(LPS&0X00FF);
LCD_WriteRAM(0x0000);
TimeDelay(1);
LCD_WriteCom(0x00B6); //VSYNC
LCD_WriteRAM((VT>>8)&0X00FF); //Set VT
LCD_WriteRAM(VT&0X00FF);
LCD_WriteRAM((VPS>>8)&0X00FF); //Set VPS
LCD_WriteRAM(VPS&0X00FF);
LCD_WriteRAM(VPW); //Set VPW
LCD_WriteRAM((FPS>>8)&0X00FF); //Set FPS
LCD_WriteRAM(FPS&0X00FF);
TimeDelay(1);
LCD_WriteCom(0x00BA);
LCD_WriteRAM(0x0005);//0x000F); //GPIO[3:0] out 1
TimeDelay(1);
LCD_WriteCom(0x00B8);
LCD_WriteRAM(0x0007); //GPIO3=input, GPIO[2:0]=output
LCD_WriteRAM(0x0001); //GPIO0 normal
TimeDelay(1);
LCD_WriteCom(0x0036); //rotation
LCD_WriteRAM(0x0008);
TimeDelay(1);
LCD_WriteCom(0x00F0); //pixel data interface
LCD_WriteRAM(0x0003);
TimeDelay(1);
TimeDelay(1);
LCD_WriteCom(0x0029); //display on
TimeDelay(1);
LCD_WriteCom(0x00BE); //set PWM for B/L
LCD_WriteRAM(0x0006);
LCD_WriteRAM(0x0080);
TimeDelay(1);
LCD_WriteRAM(0x0001);
LCD_WriteRAM(0x00f0);
LCD_WriteRAM(0x0000);
LCD_WriteRAM(0x0000);
TimeDelay(1);
LCD_WriteCom(0x00d0);//??????????
LCD_WriteRAM(0x000d);
TimeDelay(1);
//LCD_Clear(BLACK);
}
//*****************************************************************************
//*****************************************************************************
//----------------------------------------------------------------------------------------------------
// Show a farsi-englisg string on the LCD with specific size
// size : Scale factor size:1,2,3,...
//----------------------------------------------------------------------------------------------------
int font_color,x_font,y_font;
char highlight,fa_num;
unsigned int highlight_color;
unsigned int x_text=0,y_text=0;
void lcd_write_pixel(int x,int y,int color)
{
LCD_DrawPixel(x,y,color);
}
//_______________________________________________
void lcd_put_bold_char(char character , int size)
{
int counter_x,counter_y,i,j;
char letter_length,flag_p;
letter_length = font12x16[character][0]>>12;
for(counter_y=0;counter_y<16;counter_y++)
for(counter_x=0;counter_x<letter_length;counter_x++)
{
flag_p = font12x16[character][counter_y]>>(counter_x);
flag_p = flag_p&0x01;
if(flag_p)
{
if(effect == 0)
for(i=0;i<size;i++)
for(j=0;j<size;j++)
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + i -(x_font+(size*counter_x)),y_font+size*counter_y + j,font_color);
// Very good effect (1)
else if(effect == 1)
{
// good for size = 2
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y - 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
}
else if(effect == 2)
{
// good for size = 2
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y - 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 2,font_color);
}
else if(effect == 3)
{
// good for size = 3
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y - 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y - 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 2 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
}
else if(effect == 4)
{
// good for size = 3
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y - 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y - 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 2 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 2 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 2,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 2,font_color);
}
else if(effect == 5)
{
// good for size = 1,3
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,font_color);
}
//lcd_draw_circle(TS_SIZE_X - 3 -(x_font+(size*counter_x)),y_font+size*counter_y,size,1,font_color);
}
else if(highlight)
{
if(effect == 0)
for(i=0;i<size;i++)
for(j=0;j<size;j++)
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + i -(x_font+(size*counter_x)),y_font+size*counter_y + j,highlight_color);
// Very good effect (1)
else if(effect == 1)
{
// good for size = 2
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,font_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y - 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
}
else if(effect == 2)
{
// good for size = 2
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y - 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 2,highlight_color);
}
else if(effect == 3)
{
// good for size = 3
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y - 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y - 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 2 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
}
else if(effect == 4)
{
// good for size = 3
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y - 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y - 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 2 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) - 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 2 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 2,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 2,highlight_color);
}
else if(effect == 5)
{
// good for size = 1,3
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y,highlight_color);
lcd_write_pixel(TS_SIZE_X - 3 + italic*(-counter_y+7) + 1 -(x_font+(size*counter_x)),y_font+size*counter_y + 1,highlight_color);
}
//lcd_draw_circle(TS_SIZE_X - 3 + italic*(-counter_y+7) -(x_font+(size*counter_x)),y_font+size*counter_y,size,1,highlight_color);
}
}
x_font += size*letter_length;
if(x_font > TS_SIZE_X - 1)
{
x_font = x_base;
y_font += size*16;
if(y_font > TS_SIZE_Y-0)
y_font = 0;
}
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
void lcd_putsf_mix(int x,int y,const unsigned char *string , int size,int highlight, int color)
{
unsigned int letter,nt_letter,pr_letter;
unsigned int CN=0,CP=0,pr_CN=0,nt_CP=0,place=0,flag1=0;
unsigned int letter_counter=0,letter_count=0,length=0,enter=0;
unsigned int text_buffer[32];
lcd_text_highlight_color(highlight);
lcd_goto_xy(x,y);
font_color = color;
flag1 = 0;
while(*string)
{
if(*string > 0x80)
{
while(*string > 0x80)
{
if (flag1 == 0)
pr_letter = 0x20;
else
pr_letter = *(string - 1);
letter = *string++;
if (*string == 0)
nt_letter = 0x20;
else
nt_letter = *string;
flag1 = 1;
if(letter > 0x98) letter = letter;
else if(letter == 0x98) letter = 0xBC;
else if(letter == 0x90) letter = 0xC0;
else if(letter == 0x8D) letter = 0xBE;
else if(letter == 0x81) letter = 0xBD;
else if(letter == 0x8E) letter = 0xBF;
if(pr_letter > 0x98) pr_letter = pr_letter;
else if(pr_letter == 0x98) pr_letter = 0xBC;
else if(pr_letter == 0x90) pr_letter = 0xC0;
else if(pr_letter == 0x8D) pr_letter = 0xBE;
else if(pr_letter == 0x81) pr_letter = 0xBD;
else if(pr_letter == 0x8E) pr_letter = 0xBF;
if(nt_letter > 0x98) nt_letter = nt_letter;
else if(nt_letter == 0x98) nt_letter=0xBC;
else if(nt_letter == 0x90) nt_letter=0xC0;
else if(nt_letter == 0x8D) nt_letter=0xBE;
else if(nt_letter == 0x81) nt_letter=0xBD;
else if(nt_letter == 0x8E) nt_letter=0xBF;
if(pr_letter > 0x80)
pr_CN = ((FAmap[(pr_letter - 0xBC)][5]) == 1);
else
pr_CN = 0;
if(nt_letter > 0x80)
nt_CP = ((FAmap[(nt_letter - 0xBC)][4]) == 1);
else
nt_CP = 0;
if(letter > 0x80)
CP = ((FAmap[(letter - 0xBC)][4]) == 1);
else
CP = 0;
if(letter > 0x80)
CN = ((FAmap[(letter-0xBC)][5]) == 1);
else
CN = 0;
CP = pr_CN && CP;
CN = CN && nt_CP;
place = (CP << 1) | CN;
text_buffer[letter_counter++] = FAmap[(letter - 0xBC)][place];
length += size*(font12x16 [FAmap[(letter - 0xBC)][place]][1]>>12);
}
if(length < TS_SIZE_X - x_font - 3)
for(letter_count=0;letter_count<letter_counter;letter_count++)
lcd_put_bold_char(text_buffer[letter_count],size);
else
{
x_font = x_base;
y_font += size*16;
if(y_font > TS_SIZE_Y - size*16)
y_font = 0;
for(letter_count=0;letter_count<letter_counter;letter_count++)
lcd_put_bold_char(text_buffer[letter_count],size);
}
letter_counter = 0;
length = 0;
}
else if(*string == 0x20) //Space detect
lcd_put_bold_char(*string++,size);
else //English letter & Number & Enter detect
{
if(*string == 0x0D) //Enter detect
{
x_font = x_base;
y_font += size*16;
if(y_font > TS_SIZE_Y - size*16)
y_font = 0;
string += 2;
goto p1;
}
//letter_counter = 0;
while((*string < 0x81) && (*(string+1) < 0x81) && (*string != 0x00))
{
if(fa_num)
{
if((*string > 0x2F) && (*string < 0x3A) && (*string != 0x00))
{
letter = (*string) - 0x20;
text_buffer[letter_counter++] = letter;
string++;
goto P2;
}
}
text_buffer[letter_counter++] = *string++;
P2:
if((*string == 0x20) && ((letter_counter * size*8) < (TS_SIZE_X - x_font - 1)))
flag1 = letter_counter;
if((letter_counter * size*8) > (TS_SIZE_X - x_font - 1))
{
string -= (letter_counter - flag1 + 1);
letter_counter = flag1 - 1;
enter = 1;
break;
}
}
if((letter_counter * size*8) < (TS_SIZE_X - x_font - 1))
{
for(letter_count=(letter_counter);letter_count>0;letter_count--)
lcd_put_bold_char(text_buffer[letter_count - 1],size);
if(enter)
{
enter = 0;
x_font = x_base;
y_font += size*16;
if(y_font > TS_SIZE_Y - size*16)
y_font = 0;
}
}
p1:
letter_counter = 0;
flag1 = 0;
}
}
flag1 = 0;
}
//-------------------------------------TAVABE JADID AZ 2.8 INCH
//----------------------------------------------------------------------------------------------------
// Set number format to farsi
//----------------------------------------------------------------------------------------------------
void lcd_fa_num(void)
{
fa_num = 1;
}
// Set number format to english
//----------------------------------------------------------------------------------------------------
void lcd_en_num(void)
{
fa_num = 0;
}
// Set efect of the farsi font
// ef : effect number ef:1,2,...,5
//----------------------------------------------------------------------------------------------------
void lcd_font_effect(int ef)
{
if(ef >= 0 && ef <= 5)
effect = ef;
}
//----------------------------------------------------------------------------------------------------
// Enable Italic effect for farsi font
//----------------------------------------------------------------------------------------------------
void lcd_italic_on(void)
{
italic = 1;
}
//----------------------------------------------------------------------------------------------------
// Disable Italic effect for farsi font
//----------------------------------------------------------------------------------------------------
void lcd_italic_off(void)
{
italic = 0;
}
// Enable Farsi font Highlight
//----------------------------------------------------------------------------------------------------
void lcd_text_highlight_on(void)
{
highlight = 1;
}
//----------------------------------------------------------------------------------------------------
// Disable Farsi font Highlight
//----------------------------------------------------------------------------------------------------
void lcd_text_highlight_off(void)
{
highlight = 0;
}
//----------------------------------------------------------------------------------------------------
// Set Farsi font Highlight color
//----------------------------------------------------------------------------------------------------
void lcd_text_highlight_color(unsigned int color)
{
highlight_color = color;
}
//----------------------------------------------------------------------------------------------------
// Make an ascii string from an unicode string
//----------------------------------------------------------------------------------------------------
void unicode2ascii(char *uni_str , char *ascii_str)
{
int counter = 0;
int Uch = 0;
char chl,chh;
while(*uni_str)
{
chl = *uni_str++;
chh = *uni_str++;
Uch = 0;
Uch = ((Uch | chh) << 8) | chl;
if(Uch > 1574 && Uch < 1591)
*(ascii_str + counter) = (char)(Uch - 1376);
else if(Uch > 1590 && Uch < 1595)
*(ascii_str + counter) = (char)(Uch - 1375);
else if(Uch > 1600 && Uch < 1603)
*(ascii_str + counter) = (char)(Uch - 1380);
else if(Uch == 1705)
*(ascii_str + counter) = (char)(Uch - 1482);
else if(Uch == 1604)
*(ascii_str + counter) = (char)(Uch - 1379);
else if(Uch > 1604 && Uch < 1609)
*(ascii_str + counter) = (char)(Uch - 1378);
else if(Uch == 1740)
*(ascii_str + counter) = (char)(Uch - 1503);
else if(Uch == 1574)
*(ascii_str + counter) = (char)(Uch - 1381);
else if(Uch == 1662)
*(ascii_str + counter) = (char)(Uch - 1533);
else if(Uch == 1670)
*(ascii_str + counter) = (char)(Uch - 1529);
else if(Uch == 1688)
*(ascii_str + counter) = (char)(Uch - 1546);
else if(Uch == 1711)
*(ascii_str + counter) = (char)(Uch - 1567);
else if(Uch == 1570)
*(ascii_str + counter) = (char)(Uch - 1376);
else if(Uch > 1631 && Uch < 1642)
*(ascii_str + counter) = (char)(Uch - 1584);
else if(Uch == 65536)
*(ascii_str + counter) = NULL;
else
*(ascii_str + counter) = (char) Uch;
counter++;
}
*(ascii_str + counter) = NULL;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++
void LCD_WRITE_ICONE32(int Xi , int Yi , int COLOR,int BACKLIGHT,char SIZE ,const char *pic){
int i,T=0;
int i2;
long x,y;
char data;
int s,c;
y=Yi;
for(i2=0 ; i2<128 ; i2+=4){
data=pic[i2+3];
x=Xi;
for(i=0 ; i<32 ; i++){
if(i==8)data=pic[i2+2];
else if(i==16)data=pic[i2+1];
else if(i==24)data=pic[i2];
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if((data & 1)==0 ){
for(c=0 ; c<SIZE; c++)
{
LCD_SetCursor(x+s+i,y+c);
for(s=0 ; s<SIZE ; s++)LCD_DrawPixel(x+s+i,y+c,BACKLIGHT);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
else {
for(c=0 ; c<SIZE; c++){
LCD_SetCursor(x+s+i,y+c);
for(s=0 ; s<SIZE ; s++)LCD_DrawPixel(x+s+i,y+c,COLOR);
}
}
data>>=1;
x=(x+SIZE)-2;
}
y=y+(SIZE)-1;
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++
void LCD_WRITE_ICONE16(int Xi , int Yi , int COLOR,int BACKLIGHT,char SIZE ,const char *pik){
int i,T=0;
int i2;
long x,y;
char data;
int s,c;
y=Yi;
for(i2=0 ; i2<32 ; i2+=2){
data=pik[i2+1];
x=Xi;
for(i=0 ; i<16 ; i++){
if(i==8)data=pik[i2];
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if((data & 1)==0 ){
for(c=0 ; c<SIZE; c++)
{
for(s=0 ; s<SIZE ; s++)lcd_write_pixel(x+s+i,y+c,BACKLIGHT);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
else {
for(c=0 ; c<SIZE; c++){
for(s=0 ; s<SIZE ; s++)lcd_write_pixel(x+s+i,y+c,COLOR);
}
}
data>>=1;
x=(x+SIZE)-2;
}
y=y+(SIZE)-1;
}
}
void Command_Write(unsigned char command,unsigned char data1)
{
#define Write_Command LCD_WR_REG
#define Write_Data LCD_WR_REG
Write_Command(command);
Write_Data(data1);
}