/***************************************************************************** * lcd.c: main C entry file for bascol v4 prject * * History * 2014.012.08 ver 1.00 Prelimnary version, first Release * ******************************************************************************/ #include #include "lpc17xx_gpio.h" #include "lpc_types.h" #include "lcd.h" #include "delay.h" #include "memory.h" #include "data.h" #include "menu.h" #include "manager.h" #include "loadcell.h" #include "pc.h" #include //#include #include #include #include "lpc17xx_rtc.h" #include "PE & EN font1.h" #include "FAmap.h" //uint8_t Read_Buf[3000]; uint8_t Read_Buf[1000][3]; uint8_t buf[10]; extern FunctionalState sd_memory_access; extern POWER_SIGNAL_type power; extern general_data_struct general_data; extern loadcell_data_type loadcell; extern RTC_TIME_Type rtc_time; extern FunctionalState Toolsbar_State; int font_color = COLOR_WHITE,x_font = 0,y_font=50; char highlight = 1,fa_num = 1; int effect = 0 , italic = 0 , font_size =25;; unsigned int highlight_color = COLOR_BLUE; /* Global Variables */ int x_text=0,y_text=0; TOOLSBAR_DATA_type last_data; /******************************************************************************* * Send 2 byte over GPIO 120ns in Cclk 100MHz * *******************************************************************************/ void SSD_Send (uint16_t data) { //tmp= (data << 24) & 0xFF000000; //LPC_GPIO0->FIOPIN &= 0x00FFFFFF; //LPC_GPIO0->FIOPIN |= tmp; //Write D1..D8 //LPC_GPIO0->FIOPIN3 = data & 0xff; LPC_GPIO0->FIOCLR = ( 0xff << 23 ); LPC_GPIO0->FIOSET = ( data << 23 ); // tmp= (data >> 8) & 0x000000FF; // LPC_GPIO2->FIOPIN &= 0xFFFFFF00; // LPC_GPIO2->FIOPIN |= tmp; //Write D8..D15 LPC_GPIO2->FIOCLR0 = 0xff; LPC_GPIO2->FIOSET0= (data >> 8); } /******************************************************************************* * Write Comand to lcd * *******************************************************************************/ void SSD_Wr_Cmd( uint8_t c ) { // //LPC_GPIO0->FIOPIN3= c & 0xff; //LPC_GPIO2->FIOPIN0= (c >> 8)& 0xff; SSD_Send (c); LCD_RD(1); LCD_RS(0); LCD_WR(0); LCD_CS(0); __asm("NOP");__asm("nop");__asm("nop");__asm("nop");__asm("nop"); __asm("nop");__asm("nop");__asm("nop");__asm("nop");__asm("nop"); __asm("nop");__asm("nop");__asm("nop"); //delay_us(1); //#pragma asm NOP #pragma endasm; LCD_CS(1); LCD_RS(1); LCD_WR(1); } /******************************************************************************* * Read data string[1byte length] From lcd * *******************************************************************************/ void SSD_Rd_Data(uint8_t cnt) { uint8_t i; uint32_t tmp; LPC_GPIO0->FIODIR &= ~( 0XFF << 23 ); for (i=0; iFIOPIN >> 23 ) & 0xff; buf[i]= tmp; LCD_CS(1); LCD_RD(1); } LPC_GPIO0->FIODIR |= ( 0XFF << 23 ); } /******************************************************************************* * Write data to lcd 300ns in Cclk 100MHz * *******************************************************************************/ void SSD_Wr_Data(uint16_t c) { LPC_GPIO0->FIOCLR = ( 0xff << 23 ); LPC_GPIO0->FIOSET = ( c << 23 ); LPC_GPIO2->FIOCLR0 = 0xff; LPC_GPIO2->FIOSET0= (c >> 8); __asm("nop");__asm("nop");__asm("nop");__asm("nop");__asm("nop");__asm("nop"); LCD_RD(1); LCD_RS(1); LCD_WR(0);LCD_CS(0); __asm("nop");__asm("nop");__asm("nop");__asm("nop");__asm("nop"); __asm("nop");__asm("nop");__asm("nop"); LCD_CS(1); LCD_WR(1); } /******************************************************************************* * Read data from lcd * *******************************************************************************/ void SSD_Rd_Data1(uint16_t *c) { LPC_GPIO0->FIODIR &= ~( 0XFF << 23 ); LPC_GPIO2->FIODIR0 = 0x00; LCD_WR(1); LCD_RS(1); LCD_RD(0);LCD_CS(0); //#pragma asm NOP #pragma endasm; __asm("nop");__asm("nop");__asm("nop");__asm("nop"); *c = ((LPC_GPIO0->FIOPIN >> 23 ) & 0xff )|(LPC_GPIO2->FIOPIN0 << 8); LCD_CS(1); LCD_RD(1); LPC_GPIO0->FIODIR |= ( 0XFF << 23 ); LPC_GPIO2->FIODIR0 = 0xff; } /***************************************************************************** ** Function name: lcd_init ** ** Descriptions: config lcd TFT ** ** parameters: void ** ** Returned value: None ** *****************************************************************************/ void lcd_init(void){ LPC_PINCON->PINSEL1 &= ~( 0xffC00000 ); LPC_PINCON->PINSEL2 = 0; LPC_GPIO1->FIODIRL = 0xffff; LPC_GPIO0->FIODIR |= ( 0XFF << 23 ); LPC_GPIO2->FIODIR0 |= 0xff; LCD_LEDA(1); //LPC_GPIO0->FIODIR &= ~( 0XFF << 23 ); //LPC_PINCON->PINMODE1 = 0; // while(1){ // // LPC_GPIO2->FIOPIN0 = LPC_GPIO0->FIOPIN >> 23 ; // // } // while(1); // while(1){ // // LPC_GPIO0->FIOCLR = ( 0XFF << 23 ); // LPC_GPIO2->FIOCLR0 = 0XFF; // LPC_GPIO1->FIOCLRL = 0XFFFF; // delay_us(1) ; // LPC_GPIO2->FIOSET0 = 0XFF; // LPC_GPIO0->FIOSET = ( 0XFF << 23 ); // LPC_GPIO1->FIOSETL = 0XFFFF; // delay_us(1); // }; LCD_RES(1); LCD_CS(1); LCD_WR(1); LCD_RD(1); delay_ms(5); LCD_RES(0); delay_ms(5); LCD_RES(1); SSD_Wr_Cmd( SSD_SOFT_RESET ); delay_ms( 100 ); // REFclk = crystal = 10MHz -- VCO = REFclk * N -- PLL = VCO / M SSD_Wr_Cmd(SSD_SET_PLL_MN); // 0x00E2 SSD_Wr_Data(0x23); // VCO = REFclk * 34 SSD_Wr_Data(0x02); // SYSclk = PLLclk / 2 (113.33MHz) (PLL Frequency) SSD_Wr_Data(0x04); // dummy SSD_Wr_Cmd(SSD_SET_PLL); // 0x00E0 SSD_Wr_Data(0x01); // Enable PLL delay_ms(10); // SSD_Wr_Cmd( 0xe3 ); // SSD_Rd_Data( 1 ); // SSD_Send( buf[2] ); //// while(1); //// if ( buf[2] == 0x00 ){ //// while(1); //// } SSD_Wr_Cmd(SSD_SET_PLL); // 0x00E0 SSD_Wr_Data(0x03); // PLL output as system clock & Enable PLL delay_ms(1); SSD_Wr_Cmd(SSD_SOFT_RESET); // Software Reset 0x0001 delay_ms(100); //Set LSHIFT freq, i.e. the DCLK with PLL freq 100MHz set previously //Typical DCLK for AT070TN92 is 33.3MHz(datasheet) //33.264MHz = 100MHz*(LCDC_FPR+1)/2^20 //LCDC_FPR = 348797 (0x5527D) LCD_FPR= (33.3 * 2^20) / 100 //Time per line = (TFT_HOR_RESOLUTION+DISP_HOR_PULSE_WIDTH+DISP_HOR_BACK_PORCH+DISP_HOR_FRONT_PORCH)/30 us = 1056/30 = 35.2us SSD_Wr_Cmd(SSD_SET_LSHIFT_FREQ);// 0x00E6 SSD_Wr_Data(0x03);//0X04 // SSD_Wr_Data(0xff);//0X93 SSD_Wr_Data(0xff);//0XE0 //Set panel mode, varies from individual manufacturer SSD_Wr_Cmd(SSD_SET_LCD_MODE); // 0x00B0 SSD_Wr_Data(0x10); // set 18-bit for 7" panel TY700TFT800480 SSD_Wr_Data(0x80); // set TTL mode SSD_Wr_Data((TFT_HOR_RESOLUTION-1)>>8); SSD_Wr_Data(TFT_HOR_RESOLUTION-1); SSD_Wr_Data((TFT_VER_RESOLUTION-1)>>8); SSD_Wr_Data(TFT_VER_RESOLUTION-1); SSD_Wr_Data(0x00); delay_ms(1); //Set horizontal period SSD_Wr_Cmd(SSD_SET_HORI_PERIOD); // 0x00B4 SSD_Wr_Data(((HT-1)>>8) & 0X0000FF); SSD_Wr_Data(HT-1 & 0x0000FF); SSD_Wr_Data(((HPS-1) >>8) & 0xFF ); SSD_Wr_Data(HPS-1 & 0xFF); SSD_Wr_Data(TFT_HOR_PULSE_WIDTH-1); SSD_Wr_Data(0x00); SSD_Wr_Data(0x00); SSD_Wr_Data(0x00); //Set vertical period SSD_Wr_Cmd(SSD_SET_VERT_PERIOD); // 0x00B6 SSD_Wr_Data(((VT-1)>>8) & 0x0000FF); SSD_Wr_Data(VT-1 & 0x0000FF); SSD_Wr_Data(((VSP-1) >>8) & 0x0000FF); // 51 SSD_Wr_Data(VSP-1 & 0x0000FF); SSD_Wr_Data(TFT_VER_PULSE_WIDTH-1); SSD_Wr_Data(0x00); SSD_Wr_Data(0x00); // SET GPIO0 0,1,2,3 SSD_Wr_Cmd(SSD_SET_GPIO_VALUE); SSD_Wr_Data(0x05); // GPIO0,1,2,3 is output SSD_Wr_Cmd(SSD_SET_GPIO_CONF); // 0xB8 SSD_Wr_Data(0x07); SSD_Wr_Data(0x01); // set address mode SSD_Wr_Cmd(SSD_SET_ADDRESS_MODE); //0x36 SSD_Wr_Data(0x08); SSD_Wr_Cmd(SSD_SET_PIXEL_DATA_INTERFACE); // 0x00F0 SSD_Wr_Data(SSD_PDI_16BIT565); //Set pixel data interface SSD_Wr_Cmd(SSD_SET_PIXEL_FORMAT); // 0x3A SSD_Wr_Data(0x50); //set 16bit/pixel //SSD_Wr_Cmd(SSD_ENTER_INVERT_MODE); SSD_Wr_Cmd(SSD_SET_POST_PROC); //0xBC SSD_Wr_Data(0x40); //brightness SSD_Wr_Data(0x40); // contrast SSD_Wr_Data(0x40); //saturation SSD_Wr_Data(0x01); // // Set column address //// SSD_Wr_Cmd(SSD_SET_COLUMN_ADDRESS); //0x002A //// SSD_Wr_Data(0x00); //// SSD_Wr_Data(0x00); //// SSD_Wr_Data(0x03); //// SSD_Wr_Data(0x1F); //// // Set page address //// SSD_Wr_Cmd(SSD_SET_PAGE_ADDRESS); //0x002B //// SSD_Wr_Data(0x00); //// SSD_Wr_Data(0x00); //// SSD_Wr_Data(0x01); //// SSD_Wr_Data(0xDF); // setting PWM for LED backlight if ( general_data.system_state.display_backlight < 10 ) general_data.system_state.display_backlight =10 ; else if ( general_data.system_state.display_backlight > 255 ) general_data.system_state.display_backlight = 255 ; LCD_Backlight( general_data.system_state.display_backlight*0.1); delay_ms(50); LCD_Backlight( general_data.system_state.display_backlight*0.2 ); //SET display on SSD_Wr_Cmd(SSD_SET_DISPLAY_ON); // 0x29 SSD_Wr_Cmd( 0Xd0 ); SSD_Wr_Data( 0X0D ); LCD_Fill( 0 , 0 , 799 , 443 , main_background_color ); LCD_Fill( 0 , 443 , 799 , 480 , TRANSLATE24BIT_TO_BGR565( 0x9398a2 ) ); } /***************************************************************************** ** Function name: SSD_SetArea ** ** Descriptions: set display area ** ** parameters: start x,y and end x,y ** ** Returned value: None ** *****************************************************************************/ void SSD_SetArea(unsigned int sx, unsigned int ex, unsigned int sy, unsigned int ey) { SSD_Wr_Cmd(SSD_SET_COLUMN_ADDRESS); SSD_Wr_Data(sx >> 8); SSD_Wr_Data(sx); SSD_Wr_Data(ex >> 8); SSD_Wr_Data(ex); SSD_Wr_Cmd(SSD_SET_PAGE_ADDRESS); SSD_Wr_Data(sy >> 8); SSD_Wr_Data(sy); SSD_Wr_Data(ey >> 8); SSD_Wr_Data(ey); } /***************************************************************************** ** Function name: LCD_ClearScreen ** ** Descriptions: dis. ** ** parameters: color ** ** Returned value: None ** *****************************************************************************/ void LCD_ClearScreen(unsigned long color) { unsigned int x,y; SSD_SetArea(0, TFT_HOR_RESOLUTION-1 , 0, TFT_VER_RESOLUTION-1); SSD_Wr_Cmd(0x2c); for(x=0;x fabs(xend-xsta) ) { if(ysta>yend) { t=ysta; ysta=yend; yend=t; t=xsta; xsta=xend; xend=t; } for(y=ysta;yxend) { t=ysta; ysta=yend; yend=t; t=xsta; xsta=xend; xend=t; } for(x=xsta;x<=xend;x++) { y =(uint32_t)(x-xsta)*(yend-ysta)/(xend-xsta)+ysta; LCD_SetPixel(x, y, color); } } } } /***************************************************************************** ** Function name: Draw_Circle ** ** Descriptions: Draw_Circle. ** ** parameters: center x,y and radius and color ** ** Returned value: None ** *****************************************************************************/ void LCD_DrawCircle(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_SetPixel(x0-b, y0-a, color); //3 LCD_SetPixel(x0+b, y0-a, color); //0 LCD_SetPixel(x0-a, y0+b, color); //1 LCD_SetPixel(x0-b, y0-a, color); //7 LCD_SetPixel(x0-a, y0-b, color); //2 LCD_SetPixel(x0+b, y0+a, color); //4 LCD_SetPixel(x0+a, y0-b, color); //5 LCD_SetPixel(x0+a, y0+b, color); //6 LCD_SetPixel(x0-b, y0+a, color); a++; if(di<0)di +=4*a+6; else { di+=10+4*(a-b); b--; } LCD_SetPixel(x0+a, y0+b, color); } } /***************************************************************************** ** Function name: LCD_Fill ** ** Descriptions: LCD_Fill. ** ** parameters: start x,y and width and height and color ** ** Returned value: None ** *****************************************************************************/ void LCD_Fill(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint16_t color) { register uint32_t size; uint16_t x_start , x_end , y_start , y_end ,a , b ; if ( xs < xe ){ x_start = xs; x_end = xe ; if ( ys < ye ){ y_start = ys ; y_end = ye ; } else{ y_start = ye ; y_end = ys ; } } else{ x_start = xe; x_end = xs ; if ( ys < ye ){ y_start = ys ; y_end = ye ; } else{ y_start = ye ; y_end = ys ; } } SSD_SetArea(x_start, x_end, y_start, y_end); SSD_Wr_Cmd(0x2C); x_start = x_end - x_start ; y_start = y_end - y_start ; for ( a=0 ; a < y_start ; a++ ){ for ( b=0 ; b <= x_start ; b++ ) SSD_Wr_Data(color); } // size= (x_end - x_start) * ( y_end - y_start ); // while(size--) } /***************************************************************************** ** Function name: LCD_DrawRectangle ** ** Descriptions: LCD_DrawRectangle. ** ** parameters: start x,y and width and height and color ** ** Returned value: None ** *****************************************************************************/ void LCD_DrawRectangle(uint16_t x11, uint16_t y11,uint16_t x22, uint16_t y22, uint16_t color111 ) { LCD_DrawLine(x11 ,y11 ,x22 ,y11 ,color111); // - LCD_DrawLine(x11 ,y11 ,x11 ,y22 ,color111); // | LCD_DrawLine(x11 ,y22 ,x22 ,y22 ,color111); // _ LCD_DrawLine(x22 ,y11 ,x22 ,y22 ,color111); // | } /***************************************************************************** ** Function name: LCD_Backlight ** ** Descriptions: LCD_Backlight. ** ** parameters: intensity ** ** Returned value: None ** *****************************************************************************/ void LCD_Backlight( uint8_t intensity) { // setting PWM for LED backlight SSD_Wr_Cmd(SSD_SET_PWM_CONF); SSD_Wr_Data(8); SSD_Wr_Data(intensity); // Set 0xFF for full and 0x00 for off SSD_Wr_Data(0x01); SSD_Wr_Data(0xFF);//f0 SSD_Wr_Data(0x00); SSD_Wr_Data(0x0F); } /***************************************************************************** ** Function name: LCD_Backlight_read ** ** Descriptions: LCD_Backlight. ** ** parameters: intensity ** ** Returned value: None ** *****************************************************************************/ uint8_t LCD_Backlight_read( void) { // setting PWM for LED backlight SSD_Wr_Cmd(SSD_GET_PWM_CONF); SSD_Rd_Data(7); return buf[1]; } /***************************************************************************** ** Function name: lcd_read_block ** ** Descriptions: . ** ** parameters: ** ** Returned value: ** *****************************************************************************/ void lcd_read_block ( uint16_t x , uint16_t y , uint16_t width , uint16_t height , uint8_t *filse_name ) { FILE *file3; uint16_t x33,y33 , data; file3 = fopen( filse_name , "w" ); ///"M1:\\keypad\\saved_data.txt" //put width fputc( width & 0xff , file3); fputc( (width >> 8) & 0xff , file3); //put height fputc( height & 0xff , file3); fputc( (height >> 8) & 0xff , file3); SSD_SetArea( x , x+width-1 , y , y +height-1 ); SSD_Wr_Cmd( 0x3e ); data=0; fseek(file3 , 4 , SEEK_SET ); for ( y33=0 ; y33 < height ; y33++ ){ for ( x33=0 ; x33 < width ; x33++ ){ SSD_Rd_Data1( &data ); fputc( data & 0xff , file3); fputc( (data >> 8)& 0xff , file3); } } fclose( file3 ); } /***************************************************************************** ** Function name: lcd_write_block ** ** Descriptions: ** ** parameters: ** ** Returned value: ** *****************************************************************************/ void lcd_write_block ( uint16_t x , uint16_t y , uint8_t *filse_name ) { FILE *file3; uint16_t width,height,x33,y33 , data , c ; uint8_t str[6] , b; file3 = fopen( filse_name , "r" ); ///"M1:\\keypad\\saved_data.txt" fread( &str[0] , 1 , 4 , file3 ); //put width width = str[0] | ( str[1]<<8 ); //put height height = str [2] | ( str[3]<<8 ); SSD_SetArea( x , x+width-1 , y , y +height-1 ); SSD_Wr_Cmd( 0x2c ); fseek( file3 , 4 , SEEK_SET ); // for ( y33=0 ; y33 < height ; y33++ ){ // fread( &Read_Buf[0] , 1 , width*2 , file3 ); // for ( x33=0 ; x33 < width ; x33++ ){ // // data=0; //// data = fgetc(file3) ; //// data |= (fgetc(file3) << 8 ); // data = Read_Buf[(x33*2)]; // data |= Read_Buf[(x33*2)+1]<<8; //// b= data & 0x1f; //// c= data & 0xf800; //// data &= 0x07e0; //// data |= ( b<<11|c>>11); // SSD_Wr_Data(data); // // } // // } // fclose( file3 ); //fdelete( filse_name ); } /***************************************************************************** ** Function name: LCD_Pic_Put ** ** Descriptions: put a BMP file to lcd. ** ** parameters: start x,y and name or address of file ** ** Returned value: ERROR or SUCCESS ** *****************************************************************************/ Status LCD_Pic_Put (uint16_t x0, uint16_t y0,char *name) { unsigned int x,y; uint32_t pixel; FILE *file1; uint8_t count[55] , str2[100] , padding; uint32_t width , height ,size, s; // , start ; FunctionalState Tools_St; if ( general_data.system_state.standby_now_state != 0 ) return ERROR ; Tools_St = Toolsbar_State; Toolsbar_State = DISABLE ; file1 = fopen( name , "r" ); /* con not found files */ if( file1 == NULL ) { fclose( file1 ); sd_memory_access = DISABLE ; return ERROR;} /* reading header of file */ if( fread (&count[0], sizeof ( uint8_t ), 53, file1) < 52 ) { fclose( file1 );Toolsbar_State=Tools_St; return ERROR;} /* check for BMP file */ if ( !(count[0] == BMP_Identify0 && count[1] == BMP_Identify1) ) { fclose( file1 );Toolsbar_State=Tools_St ; return ERROR;} /* get width , geight and start location of pictuer's data */ //start = ( count[BMP_Start_Data] | ( count[BMP_Start_Data+1] << 8 ) | ( count[BMP_Start_Data+2] << 16 ) | ( count[BMP_Start_Data+3] << 24 ) ); height = ( count[BMP_Height] | ( count[BMP_Height+1] << 8 ) | ( count[BMP_Height+2] << 16 ) | ( count[BMP_Height+3] << 24 ) ); width = ( count[BMP_Width] | ( count[BMP_Width+1] << 8 ) | ( count[BMP_Width+2] << 16 ) | ( count[BMP_Width+3] << 24 ) ); size = ( count[BMP_Size] | ( count[BMP_Size+1] << 8 ) | ( count[BMP_Size+2] << 16 ) | ( count[BMP_Size+3] << 24 ) ); padding = 0; if ( ( height * width * 3 ) < size ) padding = ( size - ( height * width * 3 ) ) / height ; // sprintf( str2 , "w=%i - h= %i - size=%li - pad=%u" , width , height ,size , padding); // tftlcd_putsf_mix( str2 , 10 , 400 , 1 , COLOR_YELLOW , COLOR_GREY ); SSD_SetArea(x0, x0+width-1, y0, y0+height-1); SSD_Wr_Cmd(SSD_SET_ADDRESS_MODE); //0x36 SSD_Wr_Data(0x88); SSD_Wr_Cmd(0x2C); fseek (file1, count[BMP_Start_Data], SEEK_SET); s=width*3; for (y=0; y POWER_VIN_MIN ) battry_state = charge ; else if ( power.battry_voltag < POWER_VBAT_EMPTY ) battry_state = empty ; else if ( power.battry_voltag > POWER_VBAT_FULL ) battry_state = fulled ; else battry_state = normal ; if ( battry_state == empty && last_data.battry.type != empty ){ last_data.battry.type = empty; LCD_pic_put_local( PIC_battry_empty , 0 , 0 , COLOR_RED , Toolsbar_BackGrounf_color ); } else if ( battry_state == fulled && last_data.battry.type != fulled ){ last_data.battry.type = fulled; LCD_pic_put_local( PIC_battry_basic , 0 , 0 , TRANSLATE24BIT_TO_BGR565( 0x80ff00 ) , Toolsbar_BackGrounf_color ); LCD_Fill ( 7 , 6 , 55 , 22 , COLOR_GREEN ); } else if ( battry_state == charge ){ if ( last_data.battry.type != charge ) LCD_pic_put_local( PIC_battry_basic , 0 , 0 , TRANSLATE24BIT_TO_BGR565( 0x80ff00 ) , Toolsbar_BackGrounf_color ); last_data.battry.type = charge ; battry_cun++; if ( battry_cun >=6) battry_cun=0; LCD_Fill ( 8 , 7, ( battry_cun * 8 )+15 , 22 , COLOR_WHITE ); if( battry_cun < 5 ) LCD_Fill ( ( battry_cun * 8 )+16 , 7 , 56 , 22 , Toolsbar_BackGrounf_color ); } else if ( battry_state == normal ){ if ( last_data.battry.type != normal ){ LCD_pic_put_local( PIC_battry_basic , 0 , 0 , COLOR_WHITE , Toolsbar_BackGrounf_color ); last_data.battry.type = normal ; last_data.battry.per = 200; } if ( last_data.battry.per != power.battry_pre ){ last_data.battry.per = power.battry_pre ; a=power.battry_pre * 0.46 ; LCD_Fill ( 8 , 7 ,a+7 , 22 , COLOR_WHITE ); LCD_Fill ( a+8 , 7 , 54 , 22 , Toolsbar_BackGrounf_color ); } } /************************ ANTENNA ICON UPDATE ********************/ if ( last_data.antenna != general_data.connection.Antenna_power ){ last_data.antenna = general_data.connection.Antenna_power; if ( general_data.connection.Antenna_power == 0 ) LCD_pic_put_local( PIC_antenna_loss , 80 , 0 , COLOR_RED , Toolsbar_BackGrounf_color ); else{ if (general_data.connection.Antenna_power == 5 ){ LCD_pic_put_local( PIC_antenna_basic , 80 , 0 , COLOR_GREEN , Toolsbar_BackGrounf_color ); color = COLOR_GREEN ; } else{ LCD_pic_put_local( PIC_antenna_basic , 80 , 0 , COLOR_WHITE , Toolsbar_BackGrounf_color ); color = COLOR_WHITE ; } switch( general_data.connection.Antenna_power ){ case 5: LCD_Fill( 114, 7 , 115 , 27, color ); case 4: LCD_Fill( 110 , 11 , 111 , 27, color ); case 3: LCD_Fill( 106 , 15 , 107 , 27, color ); case 2: LCD_Fill( 102 , 19 , 103 , 27, color ); case 1: LCD_Fill( 98 , 23 , 99 , 27, color ); break; } } } /************************ CONNECTION ICON UPDATE ********************/ if ( last_data.connection != general_data.connection.status ){ last_data.connection = general_data.connection.status; switch( general_data.connection.status ){ case connection_busy: LCD_pic_put_local( PIC_connection , 130 , 0 , COLOR_WHITE , Toolsbar_BackGrounf_color ); break; case connection_down: LCD_pic_put_local( PIC_connection , 130 , 0 , COLOR_RED , Toolsbar_BackGrounf_color ); break; case connection_ready: LCD_pic_put_local( PIC_connection , 130 , 0 , TRANSLATE24BIT_TO_BGR565( 0x80ff00 ) , Toolsbar_BackGrounf_color ); break; } } /************************ STABLE ICON UPDATE ********************/ if ( last_data.stable != loadcell.stable ){ last_data.stable = loadcell.stable; if ( loadcell.stable == ENABLE ) LCD_pic_put_local( PIC_stable , 180 , 0 , COLOR_WHITE , Toolsbar_BackGrounf_color ); else LCD_Fill(180 , 0 , 255 , 30 , Toolsbar_BackGrounf_color ); } /************************ HOLDING ICON UPDATE ********************/ if ( last_data.hold != loadcell.hold ){ last_data.hold = loadcell.hold; if ( loadcell.hold == ENABLE ) LCD_pic_put_local( PIC_holding , 276 , 0 , COLOR_WHITE , Toolsbar_BackGrounf_color ); else LCD_Fill(276 , 0 , 370 , 30 , Toolsbar_BackGrounf_color ); } /************************ TARA ICON UPDATE ********************/ if ( last_data.tara != loadcell.tara ){ last_data.tara = loadcell.tara; if ( loadcell.tara == ENABLE ) LCD_pic_put_local( PIC_tara , 391 , 0 , COLOR_WHITE , Toolsbar_BackGrounf_color ); else LCD_Fill(391 , 0 , 484 , 30 , Toolsbar_BackGrounf_color ); } /************************ ZERO ICON UPDATE ********************/ if ( last_data.zero != loadcell.zero_w ){ last_data.zero = loadcell.zero_w; if ( loadcell.zero_w == ENABLE ) LCD_pic_put_local( PIC_zero , 505 , 0 , COLOR_WHITE , Toolsbar_BackGrounf_color ); else LCD_Fill( 505 , 0 , 580 , 30 , Toolsbar_BackGrounf_color ); } /************************ CLOCK ICON UPDATE ********************/ if ( last_data.minute != LPC_RTC->MIN ){ last_data.minute = LPC_RTC->MIN ; sprintf( str ,"%i:%i" , RTC_GetTime(LPC_RTC , RTC_TIMETYPE_HOUR ), RTC_GetTime(LPC_RTC , RTC_TIMETYPE_MINUTE )); LCD_PUT_NUM( Num_font35 , 799,1, str , COLOR_WHITE , COLOR_BLUE , right , 105 ); LCD_DrawLine( 695 , 0 , 799 , 0 , COLOR_BLUE ); } /************************ power saving mode *********************/ if ( general_data.system_state.powersaving_state == 1 && general_data.system_state.standby_now_state == 0 ){ if ( power_saving_last_BL != general_data.system_state.powersaving_backlight ){ power_saving_last_BL = general_data.system_state.powersaving_backlight; LCD_Backlight( power_saving_last_BL ); } } else if (general_data.system_state.powersaving_state == 200 && general_data.system_state.standby_now_state == 0) { LCD_Backlight( general_data.system_state.display_backlight ); general_data.system_state.powersaving_state = 0; } // if ( tools_bar_first_time == 0 ) { // // tools_bar_first_time=1; // } } /***************************************************************************** ** Function name: LCD_pic_put_local ** ** Descriptions: put a pictuer from flash memory on the lcd. ** ** parameters: void ** ** Returned value: None ** ** Executive time: 2.5 us in Cclk 100MHz *****************************************************************************/ void LCD_pic_put_local ( const unsigned char *pic , uint16_t x , uint16_t y , uint32_t img_color , uint32_t BG_color ) { uint16_t ch_w_b , r_cun , c_cun , pixel_cun ; uint8_t ch_w_B; ch_w_b = pic[ IMG_WIDTH ]; SSD_SetArea ( x , ch_w_b + x -1, y , y+ pic[ IMG_HIGHT ] -1); SSD_Wr_Cmd(0x2C); if ( ch_w_b % 8 ) ch_w_B = (ch_w_b / 8 )+1; else ch_w_B = (ch_w_b / 8 ); for ( r_cun= 0 ; r_cun < pic[ IMG_HIGHT ] ; r_cun++ ){ for ( c_cun = 0 ; c_cun < ch_w_b ; c_cun++ ){ //delay_ms(1); if ( pic[ ((r_cun*ch_w_B )+( c_cun /8 )+ IMG_START ) ] & ( 1 << ( 7-c_cun % 8 ) ) ) SSD_Wr_Data( img_color ); else SSD_Wr_Data( BG_color ); } } } /***************************************************************************** ** Function name: name ** ** Descriptions: dis. ** ** parameters: void ** ** Returned value: None ** ** Executive time: - us in Cclk -MHz *****************************************************************************/ void tftlcd_put_char(char character) { //x_text int counter_x,counter_y; 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>(counter_x); flag_p = flag_p&0x01; if(flag_p) LCD_SetPixel( TFT_HOR_RESOLUTION - 3 -(x_font+(counter_x)) , y_font+counter_y , COLOR_RED ); else //if(highlight) LCD_SetPixel( TFT_HOR_RESOLUTION - 3 -(x_font+(counter_x)) , y_font+counter_y , COLOR_GREEN ); } x_font += letter_length; if(x_font > TFT_HOR_RESOLUTION - 1) { x_font = 0; y_font += 16; if(y_font > TFT_VER_RESOLUTION-0) y_font = 0; } } /***************************************************************************** ** Function name: name ** ** Descriptions: Puts a Farsi Character On The LCD Screen with scaling ** size : Scale factor size:1,2,3,... ** ** parameters: void ** ** Returned value: None ** ** Executive time: - us in Cclk -MHz *****************************************************************************/ void tftlcd_put_bold_char(char character , char size, int text_color , int BG_color) { 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>(counter_x); flag_p = flag_p&0x01; if(flag_p) { if(effect == 0) for(i=0;i TFT_HOR_RESOLUTION - 1) { x_font = 0; y_font += size*16; if(y_font > TFT_VER_RESOLUTION-0) y_font = 0; } } /***************************************************************************** ** Function name: name ** ** Descriptions: dis. ** ** parameters: void ** ** Returned value: None ** ** Executive time: - us in Cclk -MHz *****************************************************************************/ void tftlcd_putsf_mix(const char *string , int x , int y , char size, int text_color , int BG_color) { unsigned char letter,nt_letter,pr_letter; unsigned char CN=0,CP=0,pr_CN=0,nt_CP=0,place=0,flag1=0; unsigned char letter_counter=0,letter_count=0,length=0,enter=0; unsigned char text_buffer[32]; char en_end=0; if ( general_data.system_state.standby_now_state != 0 ) return ; x_font=x; y_font=y; flag1 = 0; while(*string) { if(*string > 0x80) { while((*string > 0x80) && (*string != 0)) { if (flag1 == 0) pr_letter = 0x20; else if(*(string - 1) > 0x80) pr_letter = *(string - 1); else pr_letter = 0x20; letter = *string++; if(*string > 0x80) if (*string == 0) nt_letter = 0x20; else nt_letter = *string; else nt_letter = 0x20; 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 < TFT_HOR_RESOLUTION - x_font - 3) for(letter_count=0;letter_count TFT_VER_RESOLUTION - size*16) y_font = 0; for(letter_count=0;letter_count TFT_VER_RESOLUTION - size*16) y_font = 0; string += 2; goto p1; } while((*string < 0x81) && (*string != 0)) { if(fa_num) { if((*string > 0x2F)&&(*string < 0x3A)) { letter = (*string) - 0x20; text_buffer[letter_counter++] = letter; string++; goto P2; } } text_buffer[letter_counter++] = *string++; P2: if(((*string == 0x20) && ((letter_counter * size*8) < (TFT_HOR_RESOLUTION - x_font - 3))) || (*string > 0x80)) flag1 = letter_counter; if((letter_counter * size*8) > (TFT_HOR_RESOLUTION - x_font - 3)) { string -= (letter_counter - flag1); letter_counter = flag1; enter = 1; break; } if((*string == 0x20) && (*(string+1) > 0x80)) //farsi after Space detect break; } if(((letter_counter * size*8) < (TFT_HOR_RESOLUTION - x_font - 1)) || (*string > 0x80)) { for(letter_count=(letter_counter);letter_count>0;letter_count--) tftlcd_put_bold_char(text_buffer[letter_count - 1],size , text_color , BG_color ); if(enter) { enter = 0; x_font = 0; y_font += size*16; if(y_font > TFT_VER_RESOLUTION - size*16) y_font = 0; } } p1: letter_counter = 0; flag1 = 0; } } flag1 = 0; } /***************************************************************************** ** Function name: name ** ** Descriptions: dis. ** ** parameters: void ** ** Returned value: None ** ** Executive time: - us in Cclk -MHz *****************************************************************************/ //---------------------------------------------------------------------------------------------------- //************************************* ECA 2.8 inch LCD Module ************************************** //---------------------------------------------------------------------------------------------------- // 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; *(ascii_str + counter - 1) = NULL; } //---------------------------------------------------------------------------------------------------- //************************************* ECA 2.8 inch LCD Module ************************************** //---------------------------------------------------------------------------------------------------- // Make an ascii string from an utf_8 string //---------------------------------------------------------------------------------------------------- void utf8_2_ascii(char *utf_str , char *ascii_str) { int counter = 0; int Uch = 0; char chl,chh; while(*utf_str) { if( *utf_str == 32 ) { *(ascii_str + counter) = ' '; counter++; utf_str++; } else if ( *utf_str >= 0x30 && *utf_str <= 0x39 ){ *(ascii_str + counter) = *utf_str; counter++; utf_str++; } else{ chh = *utf_str++; chl= *utf_str++; Uch = 0; Uch = ((Uch | chh) << 8) | chl; if(Uch >= 0xd8a1 && Uch <= 0xd8b6 ) *(ascii_str + counter) = (char)(Uch - 0xD7E0); else if(Uch >= 0xd8b7 && Uch <= 0xd8ba ) *(ascii_str + counter) = (char)(Uch - 0xD7DF); else if(Uch >= 0xd981 && Uch <= 0xd983) *(ascii_str + counter) = (char)(Uch -0xD8A4); else if(Uch >= 0xd985 && Uch <= 0xd988) *(ascii_str + counter) = (char)(Uch -0xD8A2); else if(Uch >= 0xd989 && Uch <= 0xd98a) *(ascii_str + counter) = (char)(Uch -0xD89D); else if(Uch >= 0xd9a0 && Uch <= 0xd9a9) *(ascii_str + counter) = (char)(Uch - 0xD970); else if(Uch == 0xdaaf) *(ascii_str + counter) = (char)(Uch - 0xDA1F); else if(Uch == 0xda98) *(ascii_str + counter) = (char)(Uch - 0xDA0A); // else if(Uch > 1604 && Uch < 1609) // *(ascii_str + counter) = (char)(Uch - 1378); else if(Uch == 0xda84) *(ascii_str + counter) = (char)(Uch - 0xD9A3); else if(Uch == 0xd9be) *(ascii_str + counter) = (char)(Uch - 0xD93D); else if(Uch == 0xdaa9) *(ascii_str + counter) = (char)(Uch - 0xDA11); else if(Uch == 0xd984) *(ascii_str + counter) = (char)(Uch - 0xD8A3); // 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) '*'; counter++; } } *(ascii_str + counter) = NULL; // *(ascii_str + counter - 1) = NULL; } //---------------------------------------------------------------------------------------------------- //************************************* ECA 2.8 inch LCD Module ************************************** //---------------------------------------------------------------------------------------------------- // Make an ascii string from an server string //---------------------------------------------------------------------------------------------------- void server2ascii(char *server_str , char *ascii_str ){ char *s_str , *a_str; s_str = server_str ; a_str = ascii_str ; while( *s_str ){ if ( *s_str == 32 ) *a_str = 32 ; else if ( *s_str > 150 && *s_str < 186 ) *a_str = font_server_char[ *s_str - 150 ]; else *a_str = '*' ; *a_str ++; *s_str ++; }; *a_str = NULL; }