stm32 系列ili9341lcd屏驱动程序,应该没问题我自己能够使用
C文件
#define _LCD_ODEV_C_ #include "LCD_odev.h" #include "fonts.h" //ASCII×Ö·ûÐÍ×Ö¿â void LCD_Delay(unsigned short int i) { while(i--); } void LCD_wt8bitData(unsigned char da) //·¢ËÍÊý¾Ý-8λ²ÎÊý { LCD_CS_en(); LCD_DC_data(); SPI1_ReadWriteByte(da); LCD_CS_dis(); } void LCD_wt16bitData(unsigned short int da) { LCD_CS_en(); LCD_DC_data(); SPI1_ReadWriteByte(da>>8); SPI1_ReadWriteByte(da&0xFF); LCD_CS_dis(); } void LCD_wtREG(unsigned char cmd) { LCD_CS_en(); LCD_DC_reg(); SPI1_ReadWriteByte(cmd); LCD_CS_dis(); } void LCD_wtREG_DATA(unsigned char reg,unsigned short int da) { LCD_wtREG(reg); LCD_wt16bitData(da); } unsigned char LCD_Read_Data(void) { LCD_CS_en(); LCD_DC_data(); //´Ë´¦½ûÖ¹disbaleµôCS½Å£¬CS½Å±ØÐëһֱʹÄÜ£¬·ñÔò¶ÁÈ¡µÄÊý¾ÝÈ«ÊÇ0xff return SPI1_ReadWriteByte(0xFF); } void ILI9341_io_Init() // ÆäËûÒý½Å³õʼ»¯ { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB , ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_Init(GPIOB, &GPIO_InitStructure); } // ------------------------------- void LCD_odev_init(void) { ILI9341_io_Init(); lcddev.width = LCD_Wide; lcddev.height = LCD_High; LCD_RST_Clr(); delay_ms(20); LCD_RST_Set(); delay_ms(20); //LCD_BLK_Set(); //************* Start Initial Sequence **********// LCD_wtREG(0xCF); LCD_wt8bitData(0x00); LCD_wt8bitData(0xD9); LCD_wt8bitData(0X30); LCD_wtREG(0xED); LCD_wt8bitData(0x64); LCD_wt8bitData(0x03); LCD_wt8bitData(0X12); LCD_wt8bitData(0X81); LCD_wtREG(0xE8); LCD_wt8bitData(0x85); LCD_wt8bitData(0x10); LCD_wt8bitData(0x78); LCD_wtREG(0xCB); LCD_wt8bitData(0x39); LCD_wt8bitData(0x2C); LCD_wt8bitData(0x00); LCD_wt8bitData(0x34); LCD_wt8bitData(0x02); LCD_wtREG(0xF7); LCD_wt8bitData(0x20); LCD_wtREG(0xEA); LCD_wt8bitData(0x00); LCD_wt8bitData(0x00); LCD_wtREG(0xC0); //Power control LCD_wt8bitData(0x21); //VRH[5:0] LCD_wtREG(0xC1); //Power control LCD_wt8bitData(0x12); //SAP[2:0];BT[3:0] LCD_wtREG(0xC5); //VCM control LCD_wt8bitData(0x32); LCD_wt8bitData(0x3C); LCD_wtREG(0xC7); //VCM control2 LCD_wt8bitData(0XC1); LCD_wtREG(0x36); // Memory Access Control LCD_wt8bitData(0x68); LCD_wtREG(0x2A); //ÐеØÖ·ÉèÖà LCD_wt8bitData(0x00); LCD_wt8bitData(0x00); LCD_wt8bitData(0x01); LCD_wt8bitData(0x3f); LCD_wtREG(0x2B); //ÁеØÖ·ÉèÖà LCD_wt8bitData(0x00); LCD_wt8bitData(0x00); LCD_wt8bitData(0x00); LCD_wt8bitData(0xef); LCD_wtREG(0x3A); LCD_wt8bitData(0x55); LCD_wtREG(0xB1); LCD_wt8bitData(0x00); LCD_wt8bitData(0x18); LCD_wtREG(0xB6); // Display Function Control LCD_wt8bitData(0x0A); LCD_wt8bitData(0xA2); LCD_wtREG(0xF2); // 3Gamma Function Disable LCD_wt8bitData(0x00); LCD_wtREG(0x26); //Gamma curve selected LCD_wt8bitData(0x01); LCD_wtREG(0xE0); //Set Gamma LCD_wt8bitData(0x0F); LCD_wt8bitData(0x20); LCD_wt8bitData(0x1E); LCD_wt8bitData(0x09); LCD_wt8bitData(0x12); LCD_wt8bitData(0x0B); LCD_wt8bitData(0x50); LCD_wt8bitData(0XBA); LCD_wt8bitData(0x44); LCD_wt8bitData(0x09); LCD_wt8bitData(0x14); LCD_wt8bitData(0x05); LCD_wt8bitData(0x23); LCD_wt8bitData(0x21); LCD_wt8bitData(0x00); LCD_wtREG(0XE1); //Set Gamma LCD_wt8bitData(0x00); LCD_wt8bitData(0x19); LCD_wt8bitData(0x19); LCD_wt8bitData(0x00); LCD_wt8bitData(0x12); LCD_wt8bitData(0x07); LCD_wt8bitData(0x2D); LCD_wt8bitData(0x28); LCD_wt8bitData(0x3F); LCD_wt8bitData(0x02); LCD_wt8bitData(0x0A); LCD_wt8bitData(0x08); LCD_wt8bitData(0x25); LCD_wt8bitData(0x2D); LCD_wt8bitData(0x0F); LCD_wtREG(0x11); //Exit Sleep delay_ms(120); LCD_wtREG(0x29); //Display on lcddev.bled = BLEDoff; } unsigned short int LCD_Read_Point(unsigned short int cx,unsigned short int cy) { unsigned char r=0,g=0,b=0; LCD_set_windows(cx,cy,cx,cy); LCD_wtREG(0x2E); LCD_Read_Data(); //Ö»ÐèÒªÖ´ÐÐÒ»´Î¿Õ¶ÁÈ¡ r = LCD_Read_Data(); g = LCD_Read_Data(); b = LCD_Read_Data(); LCD_wtREG(0x2C); //¹Ø¼ü²½Ö裬±ØÐëÒªÓÐ return (((r>>3)<<11)|((g>>2)<<5)|(b>>3)); } void LCD_restar(void) //Èí¼þ¸´Î»Ö¸Áî²»ÄÜÔÚÍ˳ö˯ÃßÐòÁÐʱ·¢ËÍ { LCD_wtREG(0x01); delay_ms(250); } void LCD_inSleep(void) { LCD_wtREG(0x28); //display TURNOFF delay_ms(50); LCD_wtREG(0x10); //sleep ENABLE LCD_BLK_Clr(); } void LCD_outSleep(void) { LCD_wtREG(0x11); //sleep DISABLE delay_ms(50); LCD_wtREG(0x29); //display TURNON LCD_BLK_Set(); } unsigned char LCD_onDisp(void) { LCD_wtREG(0x29); //display TURNON return BLEDon; } unsigned char LCD_offDisp(void) { LCD_wtREG(0x28); //display TURNOFF return BLEDoff; } /**************************************************** *** º¯Êý¹¦ÄÜ£ºÇóÏÔʾµÄµãÕóÃæ»ý *** Èë¿Ú²ÎÊý£ºm:ºá×ø±ê *** n:×Ý×ø±ê ****************************************************/ //m^nº¯Êý //·µ»ØÖµ:m^n´Î·½. unsigned long LCD_Pow(unsigned char m,unsigned char n) { unsigned long result=1; while(n--)result*=m; return result; } /**************************************************** *** º¯Êý¹¦ÄÜ£ºÉèÖùâ±êλÖ㬼´ÉèÖÃÏÔʾµÄÆðʼ×ø±ê *** Èë¿Ú²ÎÊý£ºXpos:ºá×ø±ê *** Ypos:×Ý×ø±ê ****************************************************/ void LCD_SetCursor(unsigned short int Xpos, unsigned short int Ypos) { LCD_wtREG_DATA(Xreg ,Xpos); LCD_wtREG_DATA(Yreg ,Ypos); } /**************************************************** *** º¯Êý¹¦ÄÜ£ºÉèÖÃÏÔʾ´°¿Ú£¬¼´´´½¨Ò»¸öÏÔʾ´°¿Ú *** Èë¿Ú²ÎÊý£ºx1,y1-->Æðʼ×ø±ê *** x2,y2-->ÖÕµã×ø±ê ****************************************************/ void LCD_set_windows(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2) { LCD_wtREG(0x2a); LCD_wt16bitData(x1); LCD_wt16bitData(x2); LCD_wtREG(0x2b); LCD_wt16bitData(y1); LCD_wt16bitData(y2); LCD_wtREG(0x2C); } //ÇåÆÁº¯Êý //Color:ÒªÇåÆÁµÄÌî³äÉ« void LCD_Clear(unsigned short int color) { unsigned short int i,j; LCD_set_windows(0,0,lcddev.width-1,lcddev.height-1); for(i=0;i<lcddev.width;i++) { for (j=0;j<lcddev.height;j++) { LCD_wt16bitData(color); } } } /********************************************************** * º¯Êý¹¦ÄÜ ---> LCD»µãº¯Êý * Èë¿Ú²ÎÊý ---> (x,y)¹â±ê×ø±êÊýÖµ * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> µãµÄÑÕÉ«ÔÚÇ°ÃæµÄ»±ÊÑÕÉ«ÉèÖà **********************************************************/ void LCD_DrawPoint(unsigned short int x,unsigned short int y) { LCD_set_windows(x,y,x,y); //É趨¹â±ê×ø±ê LCD_wtREG_DATA(LCD_wtgram,lcddev.brushcl); //дÈëµãµÄÑÕÉ«Öµ,¼´ÉèÖû±ÊµÄĬÈÏÑÕÉ« } /********************************************************** * º¯Êý¹¦ÄÜ ---> LCD»µãº¯Êý£¬ÑÕÉ«ÖµËæÉ趨дÈ루¿ìËÙ»µã£© * Èë¿Ú²ÎÊý ---> (x,y)¹â±ê×ø±êÊýÖµ * cl£ºÒªÐ´ÈëµÄÑÕÉ«Öµ * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> none **********************************************************/ void LCD_DrawPoint_Color(unsigned short int x,unsigned short int y,unsigned short int cl) { LCD_set_windows(x,y,x,y); //É趨¹â±ê×ø±ê LCD_wtREG_DATA(LCD_wtgram,cl); //дÈëµãµÄÑÕÉ«Öµ,¼´ÉèÖû±ÊµÄĬÈÏÑÕÉ« } /********************************************************** * º¯Êý¹¦ÄÜ ---> LCD»Ïߺ¯Êý * Èë¿Ú²ÎÊý ---> (x1,y1)Æðµã×ø±êÊýÖµ * (x2,y2)ÖÕµã×ø±êÊýÖµ * cl-»±ÊÑÕÉ« * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> **********************************************************/ void LCD_Draw_Line(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2, unsigned short int cl) { unsigned short int 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_Color(uRow,uCol,cl);//»µã xerr+=delta_x ; yerr+=delta_y ; if(xerr>distance) { xerr-=distance; uRow+=incx; } if(yerr>distance) { yerr-=distance; uCol+=incy; } } } /********************************************************** * º¯Êý¹¦ÄÜ ---> LCDÖе㷨»Ô²º¯Êý * Èë¿Ú²ÎÊý ---> (x,y)Æð½Ç×ø±êÊýÖµ * r£ºÔ²°ë¾¶ * * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> Ô²µÄÑÕÉ«ÔÚÇ°ÃæµÄ»±ÊÑÕÉ«ÉèÖà **********************************************************/ void LCD_Draw_Circle(unsigned short int x0,unsigned short int y0,unsigned char r , unsigned short int cl) { unsigned char x,y; //Öá·½Ïò±äÁ¿ float d; x = 0; y = r; d = 5.0/4 - r; //ÄæʱÕë»Ô² while(x <= y) { LCD_DrawPoint_Color(x0 + x,y0 + y,cl); //270¡ã LCD_DrawPoint_Color(x0 + x,y0 - y,cl); //90¡ã LCD_DrawPoint_Color(x0 - x,y0 + y,cl); LCD_DrawPoint_Color(x0 - x,y0 - y,cl); LCD_DrawPoint_Color(x0 + y,y0 + x,cl); //0¡ã LCD_DrawPoint_Color(x0 + y,y0 - x,cl); LCD_DrawPoint_Color(x0 - y,y0 + x,cl); //180¡ã LCD_DrawPoint_Color(x0 - y,y0 - x,cl); if(d < 0) //yÖáË¥¼õÂý { d += x * 2.0 + 3; } else //xÖáË¥¼õÂý { d += 2.0 * (x - y) + 5; y--; } x++; } } /********************************************************** * º¯Êý¹¦ÄÜ ---> LCD»¾ØÐκ¯Êý * Èë¿Ú²ÎÊý ---> (x1,y1)Æð½Ç×ø±êÊýÖµ * (x2,y2)¶Ô½Ç×ø±êÊýÖµ ,¾ØÐεĶԽÇ×ø±ê * cl-»±ÊÑÕÉ« * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> ÏßµÄÑÕÉ«ÔÚÇ°ÃæµÄ»±ÊÑÕÉ«ÉèÖà **********************************************************/ void LCD_Draw_Quad(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2 , unsigned short int cl) { LCD_Draw_Line(x1,y1,x2,y1,cl); //ÒÔy1ΪÖá»Ïß LCD_Draw_Line(x2,y1,x2,y2,cl); //ÒÔx2ΪÖá»Ïß LCD_Draw_Line(x2,y2,x1,y2,cl); //ÒÔy2ΪÖá»Ïß LCD_Draw_Line(x1,y2,x1,y1,cl); //ÒÔx1ΪÖá»Ïß } /********************************************************** * º¯Êý¹¦ÄÜ ---> LCDÖ¸¶¨ÇøÓòÌî³äÑÕÉ«º¯Êý * Èë¿Ú²ÎÊý ---> (x1,y1)Æð½Ç×ø±êÊýÖµ * (x2,y2)¶Ô½Ç×ø±êÊýÖµ * cl£ºÌî³äÑÕÉ«Öµ * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> ÔÚÆÁÄ»Éϻһ¸öËıßÐβ¢Ìî³äÏàÓ¦µÄÑÕÉ« * ¿éÇøÓò´óС£¨Ãæ»ý£© = (x2 - x1) * (y2 - y1) **********************************************************/ void LCD_Area_Color(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2,unsigned short int cl) { unsigned short int i,j; LCD_set_windows(x1,y1,x2,y2); //ÉèÖùâ±êλÖà for(i=y1;i<=y2;i++) { for(j=x1;j<=x2;j++) LCD_wt16bitData(cl);//ÉèÖùâ±êλÖà } } /********************************************************** * º¯Êý¹¦ÄÜ ---> LCDÖ¸¶¨Î»ÖÃÏÔʾһ¸ö×Ö·ûº¯Êý * Èë¿Ú²ÎÊý ---> (x,y)×ø±êÊýÖµ * ch£ºÒªÏÔʾµÄ×Ö·û * size£º×ÖÌå´óС * mode£º0£º·Çµþ¼Ó·½Ê½ÏÔʾ¡£1£ºµþ¼Ó·½Ê½ÏÔʾ * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> Ö÷ÒªÏÔʾһЩÐèÒª±ä»¯Ö®ÀàµÄÊý×ÖÏÔʾ **********************************************************/ void LCD_ShowChar(unsigned short int x,unsigned short int y,unsigned char ch,unsigned char csize,unsigned char mode) { unsigned char temp,t1,t; unsigned short int y0=y; unsigned char sz=(csize/8+((csize%8)?1:0))*(csize/2); //µÃµ½×ÖÌåÒ»¸ö×Ö·û¶ÔÓ¦µãÕó¼¯ËùÕ¼µÄ×Ö½ÚÊý ch=ch-' ';//µÃµ½Æ«ÒƺóµÄÖµ£¨ASCII×Ö¿âÊÇ´Ó¿Õ¸ñ¿ªÊ¼È¡Ä££¬ËùÒÔ-' '¾ÍÊǶÔÓ¦×Ö·ûµÄ×ֿ⣩ for(t=0;t<sz;t++) { if(csize==12)temp=ascii_1206[ch][t]; //µ÷ÓÃ1206×ÖÌå else if(csize==16)temp=ascii_1608[ch][t]; //µ÷ÓÃ1608×ÖÌå else if(csize==24)temp=ascii_2412[ch][t]; //µ÷ÓÃ2412×ÖÌå else return; //ûÓеÄ×Ö¿â for(t1=0;t1<8;t1++) { if(temp&0x80) { LCD_DrawPoint_Color(x,y,lcddev.cur_brushcl); } else if(mode==0) { LCD_DrawPoint_Color(x,y,lcddev.cur_backcl); } temp<<=1; y++; if(y>=lcddev.height)return; //³¬ÇøÓòÁË if((y-y0)==csize) { y=y0; x++; if(x>=lcddev.width)return; //³¬ÇøÓòÁË break; } } } } /************************************************************* *** º¯Êý¹¦ÄÜ ---> LCDÖ¸¶¨Î»ÖÿªÊ¼ÏÔʾ×Ö·û´®, *** Èë¿Ú²ÎÊý ---> x,y:Æðµã×ø±ê *** width,height:ÇøÓò´óС *** size:×ÖÌå´óС *** p:×Ö·û´®ÆðʼµØÖ· *** mode:0,Õý³£ÏÔʾ,1,µþ¼ÓÏÔʾ **************************************************************/ void LCD_ShowString(unsigned short int x,unsigned short int y,char *p ,unsigned char csize,unsigned char mode) { unsigned short int w,h; switch (csize) { case Ch12_6: { w = 6; h =12; break; } case Ch16_8: { w = 8; h =16; break; } case Ch24_12: { w = 12; h =24; break; } } while(*p!='\0')//ÅжÏÊDz»ÊÇ·Ç·¨×Ö·û! { if(x>lcddev.width-w) { x=0;y+=h; } if(y>lcddev.height-h) { //x=y=0; return;//Í˳ö } LCD_ShowChar(x,y,*p,csize,mode); x+= w; p++; } } /***************************************************************************************** * º¯Êý¹¦ÄÜ ---> ÏÔʾN¸öÊý×Ö,¸ßλΪ0,Ôò²»ÏÔʾ * Èë¿Ú²ÎÊý ---> (x,y)×ø±êÊýÖµ * len :Êý×ÖµÄλÊý * size:×ÖÌå´óС * //cl:ÑÕÉ«,´Ëº¯ÊýûÓÐÑÕÉ«ÉèÖ㬰´ÕÕĬÈÏÑÕÉ« * num:ÊýÖµ(0~4294967295); * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> *****************************************************************************************/ void LCD_ShowNum(unsigned short int x,unsigned short int y,unsigned long num,unsigned char len,unsigned char size) { unsigned char t,temp; unsigned char 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); } } /***************************************************************************************** * º¯Êý¹¦ÄÜ ---> ÏÔʾN¸öÊý×Ö,¸ßλΪ0,Ò²ÏÔʾ * Èë¿Ú²ÎÊý ---> (x,y)×ø±êÊýÖµ * len :Êý×ÖµÄλÊý * size:×ÖÌå´óС * num:ÊýÖµ(0~999999999) * mode: * [7]:0,²»Ìî³ä;1,Ìî³ä0. * [6:1]:±£Áô * [0]:0,·Çµþ¼ÓÏÔʾ;1,µþ¼ÓÏÔʾ. * ·µ»ØÊýÖµ ---> none * ¹¦ÄÜ˵Ã÷ ---> *****************************************************************************************/ void LCD_ShowNum_mode(unsigned short int x,unsigned short int y,unsigned long num,unsigned char len,unsigned char size,unsigned char mode) { unsigned char t,temp; unsigned char 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); } } /*********************************************************************************************** * Ãû ³Æ£ºvoid LCD_Showflt_2dcm_mode(unsigned short int x,unsigned short int y,unsigned short int fnum, unsigned char size,unsigned char mode) * ¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±ê·¶Î§ÄÚÏÔʾһ¸öº¬Á½Î»Ð¡ÊýµÄ,СÓÚ100µÄ¸¡µãÊý * Èë¿Ú²ÎÊý£ºX-->ÆðʼX×ù±ê * Y-->ÆðʼY×ù±ê * fnum--> Á½×Ö½ÚµÄÕûÊý * size-->×ÖÌå´óС£¨±ØÐëÊdzɱÈÀýµÄ£©£¬ÏÖÖ§³Ö24,16,12 * mode--> 1£ºµþ¼ÓÏÔʾ£¬¼´Ê¹ÓÃbc¸²¸ÇĬÈϱ³¾°ÑÕÉ«£» 0£º²»µþ¼Ó¡£ * * ³ö¿Ú²ÎÊý£ºÎÞ * ˵ Ã÷£º * µ÷Ó÷½·¨£º ************************************************************************************************/ void LCD_Showflt_2dcm_mode(unsigned short int x,unsigned short int y,unsigned short int fnum, unsigned char size,unsigned char mode) { unsigned short int f_dcm =0, f_inte =0; //unsigned short int dx,dy; unsigned char md =0; md = mode&0x01; f_inte = fnum/100; f_dcm = fnum%100; if(f_inte==0) { LCD_ShowString(x,y,"0.",size,md); if(f_dcm == 0) LCD_ShowString((x + size),y,"00",size,0); else LCD_ShowNum_mode((x + size),y,f_dcm,2,size,mode); } else if(f_inte>0) { if((f_inte>=1)&&(f_inte<10)) { LCD_ShowNum_mode(x,y,f_inte,1,size,mode); LCD_ShowChar((x + size/2),y,'.',size,md); if(f_dcm == 0) LCD_ShowString((x + size),y,"00",size,0); else LCD_ShowNum_mode((x + size),y,f_dcm,2,size,mode); } else if((f_inte>=10)&&(f_inte<99)) { LCD_ShowNum_mode(x,y,f_inte,2,size,mode); LCD_ShowChar((x + size),y,'.',size,md); if(f_dcm == 0) LCD_ShowString((x + size),y,"00",size,0); else LCD_ShowNum_mode((x + size),y,f_dcm,2,size,mode); } } } /*********************************************************************************************** * Ãû ³Æ£ºvoid LCD_ShowFont(unsigned short int x,unsigned short int y, unsigned char size, unsigned short int pc , unsigned short int bc , unsigned char mode ,const unsigned char *font) * ¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±ê·¶Î§ÄÚÏÔʾһ¸öºº×Ö * Èë¿Ú²ÎÊý£ºX-->ÆðʼX×ù±ê * Y-->ÆðʼY×ù±ê * size-->×ÖÌå´óС£¨±ØÐëÊǵȱÈÀýµÄ£©£¬ÏÖÖ§³Ö32£¬26£¬24£¬16£¬12 * pc-->»±ÊÑÕÉ«£¨×ÖÌåÑÕÉ«£© * bc-->±³¾°ÑÕÉ« * mode--> 1£ºµþ¼ÓÏÔʾ£¬¼´Ê¹ÓÃbc¸²¸Çµ±Ç°±³¾°ÑÕÉ« ¡£ 0£º²»µþ¼Ó * *font-->×ÖÄ£Êý×é * ³ö¿Ú²ÎÊý£ºÎÞ * ˵ Ã÷£ºÖ§³Ö32,26,24,20,18,16,12´óСµÄºº×Ö£¬È¡×Öģʱºº×Ö±ØÐë°´µÈ±ÈÀýÈ¡ * µ÷Ó÷½·¨£º ************************************************************************************************/ void LCD_ShowFont(unsigned short int x,unsigned short int y, unsigned char fsize, unsigned short int pc , unsigned short int bc , unsigned char mode ,const unsigned char *font) { unsigned char i,j,dx,dy; unsigned char b; unsigned char *temp=(unsigned char *)font; switch(fsize) { case Font32: { dx=dy=32;b=Font32; break; } case Font26: { dx=32;dy=26;b=Font26; break; } case Font24: { dx=dy=24;b=Font24; break; } case Font20: { dx=24;dy=20;b=Font20; break; } case Font16: { dx=dy=16;b=Font16; break; } case Font12: { dx=16;dy=12;b=Font12; break; } } LCD_set_windows(x,y,x+dx-1,y+dy-1); //ÉèÖÃÇøÓò for(j=0;j<b;j++) { for(i=0;i<8;i++) { if((*temp&(1<<i))!=0) { LCD_wt16bitData(pc); } else { if(mode) LCD_wt16bitData(bc); else LCD_wt16bitData(lcddev.cur_backcl); } } temp++; } } /*************************************************************************************************************** * Ãû ³Æ£ºvoid LCD_DrawPicture(unsigned short int StartX,unsigned short int StartY,unsigned short int PicXend,unsigned short int PicYend,const unsigned char *pic) * ¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±ê·¶Î§ÏÔʾһ¸±Í¼Æ¬ * Èë¿Ú²ÎÊý£ºStartX ÐÐÆðʼ×ù±ê * StartY ÁÐÆðʼ×ù±ê * PicXend ͼƬµÄXÏñËØ * PicYend ͼƬµÄYÏñËØ pic ͼƬͷָÕë * ³ö¿Ú²ÎÊý£ºÎÞ * ˵ Ã÷£ºÍ¼Æ¬È¡Ä£¸ñʽΪˮƽɨÃ裬16λÑÕɫģʽ * µ÷Ó÷½·¨£ºLCD_DrawPicture(0,0,100,100,(unsigned short int*)demo); ****************************************************************************************************************/ void LCD_DrawPicture(unsigned short int StartX,unsigned short int StartY,unsigned short int PicXend,unsigned short int PicYend,const unsigned char *pic) { unsigned long j=0; unsigned char *pdata = (unsigned char *)pic; LCD_set_windows(StartX,StartY,StartX+PicXend-1,StartY+PicYend-1); //ÉèÖÃÏÔʾ´°¿Ú for(j=0;j<PicXend*PicYend;j++) //Ïò´°¿ÚÖÐÌîÈëÄÚÈÝ£¬¼´Í¼Æ¬µÄÄ£Öµ { LCD_wt8bitData(pdata[j*2+1]); LCD_wt8bitData(pdata[j*2]); } } /*************************************************************************************************************** * Ãû ³Æ: LCD_Draw_monochrome_Picture * ¹¦ ÄÜ: ÔÚÖ¸¶¨×ù±ê·¶Î§ÏÔʾһ¸±×Ô¶¨ÒåÑÕÉ«µÄͼƬ£¬ * µ«ÊǸÃͼƬµÄ³¤ºÍ¿íÖ»ÄÜÊÇ8µÄÕûÊý±¶ * Èë¿Ú²ÎÊý£º StartX ÐÐÆðʼ×ù±ê * StartY ÁÐÆðʼ×ù±ê * PicXend ͼƬµÄXÏñËØ * PicYend ͼƬµÄYÏñËØ pc-->»±ÊÑÕÉ«£¨×ÖÌåÑÕÉ«£© bc-->±³¾°ÑÕÉ« mode--> 1£ºµþ¼ÓÏÔʾ£¬¼´Ê¹ÓÃbc¸²¸ÇĬÈϱ³¾°ÑÕÉ« ¡£ 0£º²»µþ¼Ó pic--> ͼƬÊý×éÖ¸Õë sz--> ͼƬÊý×éµÄ´óС * ³ö¿Ú²ÎÊý£ºÎÞ * ˵ Ã÷£ºÍ¼Æ¬È¡Ä£¸ñʽΪˮƽɨÃ裬µ¥É«Ä£Ê½ ****************************************************************************************************************/ void LCD_Draw_monochrome_Picture(uint16_t StartX,uint16_t StartY,uint16_t PicXend,uint16_t PicYend,uint16_t pc , uint16_t bc , uint8_t mode ,const uint8_t *pic, uint16_t sz) { uint32_t j; uint8_t i; uint8_t *pdata = (uint8_t *)pic; LCD_set_windows(StartX,StartY,StartX+PicXend-1,StartY+PicYend-1); //ÉèÖÃÏÔʾ´°¿Ú for(j=0;j<sz;j++) //Ïò´°¿ÚÖÐÌîÈëÄÚÈÝ£¬¼´BMPͼƬµÄÄ£Öµ { for(i=0;i<8;i++) { if((*pdata&(0x80>>i))!=0) { LCD_wt16bitData(pc); } else { if(mode) LCD_wt16bitData(bc); else LCD_wt16bitData(lcddev.cur_backcl); } } pdata++; } } // Öض¨Ïòc¿âº¯Êýprintf µ½lcdÏÔʾÆÁ£¬Öض¨Ïòºó¿ÉÒÔʹÓÃprintfº¯Êý int fputc(int ch, FILE *f) { static uint16_t x = 0, y = 0; uint8_t i,cn; static char string[16] ; if(ch == '\n') // »»ÐÐ { x = 0; y += 30; return ch; } if( y > 260) { LCD_Clear(WHITE); x = 0; y = 0; } if(x > 320 - 8) { x = 0; y += 25; } if(y > 320 - 16) { return ch; } // ILI9488_Putchar18x32(x, y, ch , TFT_STRING_MODE_BACKGROUND); LCD_ShowChar(x, y, ch ,24,1); x += 16; return ch; }
H文件
#ifndef _LCD_ODEV_H_ #define _LCD_ODEV_H_ #include "stm32f0xx.h" #include "delay.h" #include "spi_idev.h" #include "stdlib.h" #include "stdio.h" //#define uchar unsigned char //#define uint unsigned short int //#define ulong unsigned long #ifdef _LCD_ODEV_C_ #define LCD_ODEV_EXT #else #define LCD_ODEV_EXT extern #endif /**********ºº×ÖµãÕó´óС************/ #define Font32 (32/8+((32%8)?1:0))*(32) #define Font26 (26/8+((26%8)?1:0))*(26) #define Font24 (24/8+((24%8)?1:0))*(24) #define Font20 (20/8+((20%8)?1:0))*(20) #define Font16 (16/8+((16%8)?1:0))*(16) #define Font12 (12/8+((12%8)?1:0))*(12) /***********×Ö·ûµãÕó´óС*****************/ #define Ch12_6 12 #define Ch16_8 16 #define Ch24_12 24 /*************LCD´óС******************/ #define LCD_Wide 320 #define LCD_High 240 //ɨÃè·½Ïò¶¨Òå #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 L2R_U2D //LCDÇý¶¯ÃüÁî #define Xreg 0x2A #define Yreg 0x2B #define LCD_wtgram 0x2C //»±ÊÑÕÉ« #define WHITE 0xFFFF #define BLACK 0x0000 #define BLUE 0x001F #define BRED 0XF81F #define GRED 0XFFE0 #define GBLUE 0X07FF #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x7FFF #define YELLOW 0xFFE0 #define BROWN 0XBC40 //×ØÉ« #define BRRED 0XFC07 //×غìÉ« #define GRAY 0X8430 //»ÒÉ« #define DARKBLUE 0X01CF //ÉîÀ¶É« #define LIGHTBLUE 0X7D7C //dzÀ¶É« #define GRAYBLUE 0X5458 //»ÒÀ¶É« #define LIGHTGREEN 0X841F //dzÂÌÉ« #define LIGHTGRAY 0XEF5B //dz»ÒÉ«(PANNEL) #define LGRAY 0XC618 //dz»ÒÉ«(PANNEL),´°Ìå±³¾°É« #define LGRAYBLUE 0XA651 //dz»ÒÀ¶É«(Öмä²ãÑÕÉ«) #define LBBLUE 0X2B12 //dz×ØÀ¶É«(Ñ¡ÔñÌõÄ¿µÄ·´É«) #define cblock1 0XEBE6 #define cblock2 0X4398 #define cblock3 0X5742 #define cblock4 0XFE00 #define cblock5 0X2EB4 #define cblock6 0XC7C2 #define cblock7 0X922F #define cblock8 0XF4D4 #define cblock9 0XBD9A #define cblock10 0XD923 #define cblock11 0X806C #define cblock12 0XE9CE #define cblock13 0XC716 #define cblock14 0X28AD #define cblock15 0X066C #define cblock16 0XA004 #define cblock17 0XFFF3 #define cblock18 0X730B #define cblock19 0X3619 #define cblock20 0X046E //ĬÈÏÑÕÉ«ÉèÖà #define DFT_brhcl BLACK //ĬÈÏ»±ÊÑÕÉ« #define DFT_bckcl WHITE //ĬÈϱ³¾°ÑÕÉ« #define BLEDon 1 #define BLEDoff !BLEDon //LCDÖØÒª²ÎÊý¼¯ typedef struct { unsigned short int width; //LCD ¿í¶È unsigned short int height; //LCD ¸ß¶È unsigned short int id; //LCD ID unsigned char dir; //ºáÆÁ»¹ÊÇÊúÆÁ¿ØÖÆ£º0£¬ÊúÆÁ£»1£¬ºáÆÁ¡£ unsigned short int brushcl; //ĬÈÏ»±ÊÑÕÉ« unsigned short int backcl; //ĬÈϱ³¾°ÑÕÉ« unsigned short int cur_brushcl; //µ±Ç°»±ÊÑÕÉ« unsigned short int cur_backcl; //µ±Ç°±³¾°ÑÕÉ« unsigned char bled; //¿ª¹Ø±ÕÏÔʾÆÁ }lcd_odev_struct; LCD_ODEV_EXT lcd_odev_struct lcddev; #define LCD_RST_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_15)//RES #define LCD_RST_Set() GPIO_SetBits(GPIOA,GPIO_Pin_15) #define LCD_DC_reg() GPIO_ResetBits(GPIOB,GPIO_Pin_7)//DC #define LCD_DC_data() GPIO_SetBits(GPIOB,GPIO_Pin_7) #define LCD_CS_en() GPIO_ResetBits(GPIOB,GPIO_Pin_6)//CS #define LCD_CS_dis() GPIO_SetBits(GPIOB,GPIO_Pin_6) #define LCD_BLK_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_9)//BLK #define LCD_BLK_Set() GPIO_SetBits(GPIOB,GPIO_Pin_9) void LCD_Delay(unsigned short int i); //LCDÑÓʱ void LCD_wt8bitData(unsigned char data); void LCD_wt16bitData(unsigned short int data); void LCD_wtREG(unsigned char cmd); void LCD_wtREG_DATA(unsigned char reg,unsigned short int da); unsigned char LCD_Read_Data(void); //¶ÁÊý¾Ý²Ù×÷ unsigned short int LCD_Read_Point(unsigned short int cx,unsigned short int cy);//¶ÁÖ¸¶¨µãµÄÑÕÉ« void LCD_restar(void); //LCDÈí¼þ¸´Î» unsigned char LCD_onDisp(void); //¿ªÏÔʾ unsigned char LCD_offDisp(void); //¹ØÏÔʾ void LCD_inSleep(void); //ÐÝÃß void LCD_outSleep(void); //»½ÐÑ unsigned long LCD_Pow(unsigned char m,unsigned char n); void LCD_SetCursor(unsigned short int Xpos, unsigned short int Ypos); void LCD_set_windows(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2); void LCD_Clear(unsigned short int color); void LCD_DrawPoint(unsigned short int x,unsigned short int y); void LCD_DrawPoint_Color(unsigned short int x,unsigned short int y,unsigned short int cl); void LCD_Draw_Line(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2, unsigned short int cl); void LCD_Draw_Circle(unsigned short int x0,unsigned short int y0,unsigned char r , unsigned short int cl); void LCD_Draw_Quad(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2 , unsigned short int cl); void LCD_Area_Color(unsigned short int x1,unsigned short int y1,unsigned short int x2,unsigned short int y2,unsigned short int cl); void LCD_ShowChar(unsigned short int x,unsigned short int y,unsigned char ch,unsigned char csize,unsigned char mode); void LCD_ShowString(unsigned short int x,unsigned short int y,char *p ,unsigned char csize, unsigned char mode); void LCD_ShowNum(unsigned short int x,unsigned short int y,unsigned long num,unsigned char len,unsigned char size); void LCD_ShowNum_mode(unsigned short int x,unsigned short int y,unsigned long num,unsigned char len,unsigned char size,unsigned char mode); void LCD_Showflt_2dcm_mode(unsigned short int x,unsigned short int y,unsigned short int fnum, unsigned char size,unsigned char mode); void LCD_ShowFont(unsigned short int x,unsigned short int y, unsigned char fsize, unsigned short int pc , unsigned short int bc , unsigned char mode ,const unsigned char *font); void LCD_DrawPicture(unsigned short int StartX,unsigned short int StartY,unsigned short int PicXend,unsigned short int PicYend,const unsigned char *pic); void LCD_Draw_monochrome_Picture(uint16_t StartX,uint16_t StartY,uint16_t PicXend,uint16_t PicYend,uint16_t pc , uint16_t bc , uint8_t mode ,const uint8_t *pic, uint16_t sz); //unsigned short int LCD_ReadPoint(unsigned short int x,unsigned short int y); //¶Áµã void LCD_odev_set(void); void LCD_odev_init(void); void LCD_odev_tick(void); void LCD_odev_exc(void); int fputc(int ch, FILE *f); #endif