STM32C0单片机的主频为48Mhz,内核为cortexM0+,与架构与G0一样。ROM/RAM根据型号不同从16k-32k/6k-12k不等,不同封装的芯片引脚数量从8个到48个。非常适合低功耗小巧的设计。用起来感觉和G0 L0系列差不多。
驱动手表1.28寸屏,原理图:
驱动PIN
// VCC 3.3V
// SCL PA0
// SDA PA1
// RES PA2
// DC PA3
// CS PA4
// BLK PA5
GPIO初始化:
void LCD_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5,GPIO_PIN_SET); }
void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { Error_Handler(); } }
配置代码:
#include "lcd_init.h" #include "delay.h" void LCD_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; __HAL_RCC_GPIOA_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5,GPIO_PIN_SET); } void LCD_Writ_Bus(u8 dat) { u8 i; LCD_CS_Clr(); for(i=0;i<8;i++) { LCD_SCLK_Clr(); if(dat&0x80) { LCD_MOSI_Set(); } else { LCD_MOSI_Clr(); } LCD_SCLK_Set(); dat<<=1; } LCD_CS_Set(); } void LCD_WR_DATA8(u8 dat) { LCD_Writ_Bus(dat); } /****************************************************************************** ******************************************************************************/ void LCD_WR_DATA(u16 dat) { LCD_Writ_Bus(dat>>8); LCD_Writ_Bus(dat); } /****************************************************************************** ******************************************************************************/ void LCD_WR_REG(u8 dat) { LCD_DC_Clr();//дÃüÁî LCD_Writ_Bus(dat); LCD_DC_Set();//дÊý¾Ý } /****************************************************************************** ******************************************************************************/ void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2) { LCD_WR_REG(0x2a);//ÁеØÖ·ÉèÖà LCD_WR_DATA(x1); LCD_WR_DATA(x2); LCD_WR_REG(0x2b);//ÐеØÖ·ÉèÖà LCD_WR_DATA(y1); LCD_WR_DATA(y2); LCD_WR_REG(0x2c);//´¢´æÆ÷д } void LCD_Init(void) { LCD_GPIO_Init();//³õʼ»¯GPIO LCD_RES_Clr();//¸´Î» delay_ms(100); LCD_RES_Set(); delay_ms(100); LCD_BLK_Set();//´ò¿ª±³¹â delay_ms(100); LCD_WR_REG(0xEF); LCD_WR_REG(0xEB); LCD_WR_DATA8(0x14); LCD_WR_REG(0xFE); LCD_WR_REG(0xEF); LCD_WR_REG(0xEB); LCD_WR_DATA8(0x14); LCD_WR_REG(0x84); LCD_WR_DATA8(0x40); LCD_WR_REG(0x85); LCD_WR_DATA8(0xFF); LCD_WR_REG(0x86); LCD_WR_DATA8(0xFF); LCD_WR_REG(0x87); LCD_WR_DATA8(0xFF); LCD_WR_REG(0x88); LCD_WR_DATA8(0x0A); LCD_WR_REG(0x89); LCD_WR_DATA8(0x21); LCD_WR_REG(0x8A); LCD_WR_DATA8(0x00); LCD_WR_REG(0x8B); LCD_WR_DATA8(0x80); LCD_WR_REG(0x8C); LCD_WR_DATA8(0x01); LCD_WR_REG(0x8D); LCD_WR_DATA8(0x01); LCD_WR_REG(0x8E); LCD_WR_DATA8(0xFF); LCD_WR_REG(0x8F); LCD_WR_DATA8(0xFF); LCD_WR_REG(0xB6); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x20); LCD_WR_REG(0x36); if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x08); else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC8); else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x68); else LCD_WR_DATA8(0xA8); LCD_WR_REG(0x3A); LCD_WR_DATA8(0x05); LCD_WR_REG(0x90); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_REG(0xBD); LCD_WR_DATA8(0x06); LCD_WR_REG(0xBC); LCD_WR_DATA8(0x00); LCD_WR_REG(0xFF); LCD_WR_DATA8(0x60); LCD_WR_DATA8(0x01); LCD_WR_DATA8(0x04); LCD_WR_REG(0xC3); LCD_WR_DATA8(0x13); LCD_WR_REG(0xC4); LCD_WR_DATA8(0x13); LCD_WR_REG(0xC9); LCD_WR_DATA8(0x22); LCD_WR_REG(0xBE); LCD_WR_DATA8(0x11); LCD_WR_REG(0xE1); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x0E); LCD_WR_REG(0xDF); LCD_WR_DATA8(0x21); LCD_WR_DATA8(0x0c); LCD_WR_DATA8(0x02); LCD_WR_REG(0xF0); LCD_WR_DATA8(0x45); LCD_WR_DATA8(0x09); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x26); LCD_WR_DATA8(0x2A); LCD_WR_REG(0xF1); LCD_WR_DATA8(0x43); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x72); LCD_WR_DATA8(0x36); LCD_WR_DATA8(0x37); LCD_WR_DATA8(0x6F); LCD_WR_REG(0xF2); LCD_WR_DATA8(0x45); LCD_WR_DATA8(0x09); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x26); LCD_WR_DATA8(0x2A); LCD_WR_REG(0xF3); LCD_WR_DATA8(0x43); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x72); LCD_WR_DATA8(0x36); LCD_WR_DATA8(0x37); LCD_WR_DATA8(0x6F); LCD_WR_REG(0xED); LCD_WR_DATA8(0x1B); LCD_WR_DATA8(0x0B); LCD_WR_REG(0xAE); LCD_WR_DATA8(0x77); LCD_WR_REG(0xCD); LCD_WR_DATA8(0x63); LCD_WR_REG(0x70); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x04); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x0F); LCD_WR_DATA8(0x09); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x03); LCD_WR_REG(0xE8); LCD_WR_DATA8(0x34); LCD_WR_REG(0x62); LCD_WR_DATA8(0x18); LCD_WR_DATA8(0x0D); LCD_WR_DATA8(0x71); LCD_WR_DATA8(0xED); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x18); LCD_WR_DATA8(0x0F); LCD_WR_DATA8(0x71); LCD_WR_DATA8(0xEF); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70); LCD_WR_REG(0x63); LCD_WR_DATA8(0x18); LCD_WR_DATA8(0x11); LCD_WR_DATA8(0x71); LCD_WR_DATA8(0xF1); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x18); LCD_WR_DATA8(0x13); LCD_WR_DATA8(0x71); LCD_WR_DATA8(0xF3); LCD_WR_DATA8(0x70); LCD_WR_DATA8(0x70); LCD_WR_REG(0x64); LCD_WR_DATA8(0x28); LCD_WR_DATA8(0x29); LCD_WR_DATA8(0xF1); LCD_WR_DATA8(0x01); LCD_WR_DATA8(0xF1); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x07); LCD_WR_REG(0x66); LCD_WR_DATA8(0x3C); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0xCD); LCD_WR_DATA8(0x67); LCD_WR_DATA8(0x45); LCD_WR_DATA8(0x45); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_REG(0x67); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x3C); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x01); LCD_WR_DATA8(0x54); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x32); LCD_WR_DATA8(0x98); LCD_WR_REG(0x74); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x85); LCD_WR_DATA8(0x80); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x4E); LCD_WR_DATA8(0x00); LCD_WR_REG(0x98); LCD_WR_DATA8(0x3e); LCD_WR_DATA8(0x07); LCD_WR_REG(0x35); LCD_WR_REG(0x21); LCD_WR_REG(0x11); delay_ms(120); LCD_WR_REG(0x29); delay_ms(20); }
功能代码
#include "lcd.h" #include "lcd_init.h" #include "lcdfont.h" #include "delay.h" /****************************************************************************** ******************************************************************************/ void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color) { u16 i,j; LCD_Address_Set(xsta,ysta,xend-1,yend-1);//ÉèÖÃÏÔʾ·¶Î§ for(i=ysta;i<yend;i++) { for(j=xsta;j<xend;j++) { LCD_WR_DATA(color); } } } /****************************************************************************** ******************************************************************************/ void LCD_DrawPoint(u16 x,u16 y,u16 color) { LCD_Address_Set(x,y,x,y);//ÉèÖùâ±êλÖà LCD_WR_DATA(color); } /****************************************************************************** º¯Êý˵Ã÷£º»Ïß Èë¿ÚÊý¾Ý£ºx1,y1 Æðʼ×ø±ê x2,y2 ÖÕÖ¹×ø±ê color ÏßµÄÑÕÉ« ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color) { u16 t; int xerr=0,yerr=0,delta_x,delta_y,distance; int incx,incy,uRow,uCol; delta_x=x2-x1; //¼ÆËã×ø±êÔöÁ¿ delta_y=y2-y1; uRow=x1;//»ÏßÆðµã×ø±ê uCol=y1; if(delta_x>0)incx=1; //ÉèÖõ¥²½·½Ïò else if (delta_x==0)incx=0;//´¹Ö±Ïß else {incx=-1;delta_x=-delta_x;} if(delta_y>0)incy=1; else if (delta_y==0)incy=0;//ˮƽÏß else {incy=-1;delta_y=-delta_y;} if(delta_x>delta_y)distance=delta_x; //Ñ¡È¡»ù±¾ÔöÁ¿×ø±êÖá else distance=delta_y; for(t=0;t<distance+1;t++) { LCD_DrawPoint(uRow,uCol,color);//»µã xerr+=delta_x; yerr+=delta_y; if(xerr>distance) { xerr-=distance; uRow+=incx; } if(yerr>distance) { yerr-=distance; uCol+=incy; } } } /****************************************************************************** º¯Êý˵Ã÷£º»¾ØÐÎ Èë¿ÚÊý¾Ý£ºx1,y1 Æðʼ×ø±ê x2,y2 ÖÕÖ¹×ø±ê color ¾ØÐεÄÑÕÉ« ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color) { LCD_DrawLine(x1,y1,x2,y1,color); LCD_DrawLine(x1,y1,x1,y2,color); LCD_DrawLine(x1,y2,x2,y2,color); LCD_DrawLine(x2,y1,x2,y2,color); } /****************************************************************************** º¯Êý˵Ã÷£º»Ô² Èë¿ÚÊý¾Ý£ºx0,y0 Ô²ÐÄ×ø±ê r °ë¾¶ color Ô²µÄÑÕÉ« ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color) { int a,b; a=0;b=r; while(a<=b) { LCD_DrawPoint(x0-b,y0-a,color); //3 LCD_DrawPoint(x0+b,y0-a,color); //0 LCD_DrawPoint(x0-a,y0+b,color); //1 LCD_DrawPoint(x0-a,y0-b,color); //2 LCD_DrawPoint(x0+b,y0+a,color); //4 LCD_DrawPoint(x0+a,y0-b,color); //5 LCD_DrawPoint(x0+a,y0+b,color); //6 LCD_DrawPoint(x0-b,y0+a,color); //7 a++; if((a*a+b*b)>(r*r))//ÅжÏÒª»µÄµãÊÇ·ñ¹ýÔ¶ { b--; } } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾºº×Ö´® Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê *s ÒªÏÔʾµÄºº×Ö´® fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠ¿ÉÑ¡ 16 24 32 mode: 0·Çµþ¼Óģʽ 1µþ¼Óģʽ ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowChinese(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode) { while(*s!=0) { if(sizey==12) LCD_ShowChinese12x12(x,y,s,fc,bc,sizey,mode); else if(sizey==16) LCD_ShowChinese16x16(x,y,s,fc,bc,sizey,mode); else if(sizey==24) LCD_ShowChinese24x24(x,y,s,fc,bc,sizey,mode); else if(sizey==32) LCD_ShowChinese32x32(x,y,s,fc,bc,sizey,mode); else return; s+=2; x+=sizey; } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾµ¥¸ö12x12ºº×Ö Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê *s ÒªÏÔʾµÄºº×Ö fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠmode: 0·Çµþ¼Óģʽ 1µþ¼Óģʽ ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowChinese12x12(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode) { u8 i,j,m=0; u16 k; u16 HZnum;//ºº×ÖÊýÄ¿ u16 TypefaceNum;//Ò»¸ö×Ö·ûËùÕ¼×Ö½Ú´óС u16 x0=x; TypefaceNum=(sizey/8+((sizey%8)?1:0))*sizey; HZnum=sizeof(tfont12)/sizeof(typFNT_GB12); //ͳ¼Æºº×ÖÊýÄ¿ for(k=0;k<HZnum;k++) { if((tfont12[k].Index[0]==*(s))&&(tfont12[k].Index[1]==*(s+1))) { LCD_Address_Set(x,y,x+sizey-1,y+sizey-1); for(i=0;i<TypefaceNum;i++) { for(j=0;j<8;j++) { if(!mode)//·Çµþ¼Ó·½Ê½ { if(tfont12[k].Msk[i]&(0x01<<j))LCD_WR_DATA(fc); else LCD_WR_DATA(bc); m++; if(m%sizey==0) { m=0; break; } } else//µþ¼Ó·½Ê½ { if(tfont12[k].Msk[i]&(0x01<<j)) LCD_DrawPoint(x,y,fc);//»Ò»¸öµã x++; if((x-x0)==sizey) { x=x0; y++; break; } } } } } continue; //²éÕÒµ½¶ÔÓ¦µãÕó×Ö¿âÁ¢¼´Í˳ö£¬·ÀÖ¹¶à¸öºº×ÖÖظ´È¡Ä£´øÀ´Ó°Ïì } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾµ¥¸ö16x16ºº×Ö Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê *s ÒªÏÔʾµÄºº×Ö fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠmode: 0·Çµþ¼Óģʽ 1µþ¼Óģʽ ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowChinese16x16(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode) { u8 i,j,m=0; u16 k; u16 HZnum;//ºº×ÖÊýÄ¿ u16 TypefaceNum;//Ò»¸ö×Ö·ûËùÕ¼×Ö½Ú´óС u16 x0=x; TypefaceNum=(sizey/8+((sizey%8)?1:0))*sizey; HZnum=sizeof(tfont16)/sizeof(typFNT_GB16); //ͳ¼Æºº×ÖÊýÄ¿ for(k=0;k<HZnum;k++) { if ((tfont16[k].Index[0]==*(s))&&(tfont16[k].Index[1]==*(s+1))) { LCD_Address_Set(x,y,x+sizey-1,y+sizey-1); for(i=0;i<TypefaceNum;i++) { for(j=0;j<8;j++) { if(!mode)//·Çµþ¼Ó·½Ê½ { if(tfont16[k].Msk[i]&(0x01<<j))LCD_WR_DATA(fc); else LCD_WR_DATA(bc); m++; if(m%sizey==0) { m=0; break; } } else//µþ¼Ó·½Ê½ { if(tfont16[k].Msk[i]&(0x01<<j)) LCD_DrawPoint(x,y,fc);//»Ò»¸öµã x++; if((x-x0)==sizey) { x=x0; y++; break; } } } } } continue; //²éÕÒµ½¶ÔÓ¦µãÕó×Ö¿âÁ¢¼´Í˳ö£¬·ÀÖ¹¶à¸öºº×ÖÖظ´È¡Ä£´øÀ´Ó°Ïì } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾµ¥¸ö24x24ºº×Ö Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê *s ÒªÏÔʾµÄºº×Ö fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠmode: 0·Çµþ¼Óģʽ 1µþ¼Óģʽ ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowChinese24x24(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode) { u8 i,j,m=0; u16 k; u16 HZnum;//ºº×ÖÊýÄ¿ u16 TypefaceNum;//Ò»¸ö×Ö·ûËùÕ¼×Ö½Ú´óС u16 x0=x; TypefaceNum=(sizey/8+((sizey%8)?1:0))*sizey; HZnum=sizeof(tfont24)/sizeof(typFNT_GB24); //ͳ¼Æºº×ÖÊýÄ¿ for(k=0;k<HZnum;k++) { if ((tfont24[k].Index[0]==*(s))&&(tfont24[k].Index[1]==*(s+1))) { LCD_Address_Set(x,y,x+sizey-1,y+sizey-1); for(i=0;i<TypefaceNum;i++) { for(j=0;j<8;j++) { if(!mode)//·Çµþ¼Ó·½Ê½ { if(tfont24[k].Msk[i]&(0x01<<j))LCD_WR_DATA(fc); else LCD_WR_DATA(bc); m++; if(m%sizey==0) { m=0; break; } } else//µþ¼Ó·½Ê½ { if(tfont24[k].Msk[i]&(0x01<<j)) LCD_DrawPoint(x,y,fc);//»Ò»¸öµã x++; if((x-x0)==sizey) { x=x0; y++; break; } } } } } continue; //²éÕÒµ½¶ÔÓ¦µãÕó×Ö¿âÁ¢¼´Í˳ö£¬·ÀÖ¹¶à¸öºº×ÖÖظ´È¡Ä£´øÀ´Ó°Ïì } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾµ¥¸ö32x32ºº×Ö Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê *s ÒªÏÔʾµÄºº×Ö fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠmode: 0·Çµþ¼Óģʽ 1µþ¼Óģʽ ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowChinese32x32(u16 x,u16 y,u8 *s,u16 fc,u16 bc,u8 sizey,u8 mode) { u8 i,j,m=0; u16 k; u16 HZnum;//ºº×ÖÊýÄ¿ u16 TypefaceNum;//Ò»¸ö×Ö·ûËùÕ¼×Ö½Ú´óС u16 x0=x; TypefaceNum=(sizey/8+((sizey%8)?1:0))*sizey; HZnum=sizeof(tfont32)/sizeof(typFNT_GB32); //ͳ¼Æºº×ÖÊýÄ¿ for(k=0;k<HZnum;k++) { if ((tfont32[k].Index[0]==*(s))&&(tfont32[k].Index[1]==*(s+1))) { LCD_Address_Set(x,y,x+sizey-1,y+sizey-1); for(i=0;i<TypefaceNum;i++) { for(j=0;j<8;j++) { if(!mode)//·Çµþ¼Ó·½Ê½ { if(tfont32[k].Msk[i]&(0x01<<j))LCD_WR_DATA(fc); else LCD_WR_DATA(bc); m++; if(m%sizey==0) { m=0; break; } } else//µþ¼Ó·½Ê½ { if(tfont32[k].Msk[i]&(0x01<<j)) LCD_DrawPoint(x,y,fc);//»Ò»¸öµã x++; if((x-x0)==sizey) { x=x0; y++; break; } } } } } continue; //²éÕÒµ½¶ÔÓ¦µãÕó×Ö¿âÁ¢¼´Í˳ö£¬·ÀÖ¹¶à¸öºº×ÖÖظ´È¡Ä£´øÀ´Ó°Ïì } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾµ¥¸ö×Ö·û Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê num ÒªÏÔʾµÄ×Ö·û fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠmode: 0·Çµþ¼Óģʽ 1µþ¼Óģʽ ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowChar(u16 x,u16 y,u8 num,u16 fc,u16 bc,u8 sizey,u8 mode) { u8 temp,sizex,t,m=0; u16 i,TypefaceNum;//Ò»¸ö×Ö·ûËùÕ¼×Ö½Ú´óС u16 x0=x; sizex=sizey/2; TypefaceNum=(sizex/8+((sizex%8)?1:0))*sizey; num=num-' '; //µÃµ½Æ«ÒƺóµÄÖµ LCD_Address_Set(x,y,x+sizex-1,y+sizey-1); //ÉèÖùâ±êλÖà for(i=0;i<TypefaceNum;i++) { if(sizey==12)temp=ascii_1206[num][i]; //µ÷ÓÃ6x12×ÖÌå else if(sizey==16)temp=ascii_1608[num][i]; //µ÷ÓÃ8x16×ÖÌå else if(sizey==24)temp=ascii_2412[num][i]; //µ÷ÓÃ12x24×ÖÌå else if(sizey==32)temp=ascii_3216[num][i]; //µ÷ÓÃ16x32×ÖÌå else return; for(t=0;t<8;t++) { if(!mode)//·Çµþ¼Óģʽ { if(temp&(0x01<<t))LCD_WR_DATA(fc); else LCD_WR_DATA(bc); m++; if(m%sizex==0) { m=0; break; } } else//µþ¼Óģʽ { if(temp&(0x01<<t))LCD_DrawPoint(x,y,fc);//»Ò»¸öµã x++; if((x-x0)==sizex) { x=x0; y++; break; } } } } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾ×Ö·û´® Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê *p ÒªÏÔʾµÄ×Ö·û´® fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠmode: 0·Çµþ¼Óģʽ 1µþ¼Óģʽ ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 fc,u16 bc,u8 sizey,u8 mode) { while(*p!='\0') { LCD_ShowChar(x,y,*p,fc,bc,sizey,mode); x+=sizey/2; p++; } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾÊý×Ö Èë¿ÚÊý¾Ý£ºmµ×Êý£¬nÖ¸Êý ·µ»ØÖµ£º ÎÞ ******************************************************************************/ u32 mypow(u8 m,u8 n) { u32 result=1; while(n--)result*=m; return result; } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾÕûÊý±äÁ¿ Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê num ÒªÏÔʾÕûÊý±äÁ¿ len ÒªÏÔʾµÄλÊý fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowIntNum(u16 x,u16 y,u16 num,u8 len,u16 fc,u16 bc,u8 sizey) { u8 t,temp; u8 enshow=0; u8 sizex=sizey/2; for(t=0;t<len;t++) { temp=(num/mypow(10,len-t-1))%10; if(enshow==0&&t<(len-1)) { if(temp==0) { LCD_ShowChar(x+t*sizex,y,' ',fc,bc,sizey,0); continue; }else enshow=1; } LCD_ShowChar(x+t*sizex,y,temp+48,fc,bc,sizey,0); } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾÁ½Î»Ð¡Êý±äÁ¿ Èë¿ÚÊý¾Ý£ºx,yÏÔʾ×ø±ê num ÒªÏÔʾСÊý±äÁ¿ len ÒªÏÔʾµÄλÊý fc ×ÖµÄÑÕÉ« bc ×ֵı³¾°É« sizey ×ֺŠ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowFloatNum1(u16 x,u16 y,float num,u8 len,u16 fc,u16 bc,u8 sizey) { u8 t,temp,sizex; u16 num1; sizex=sizey/2; num1=num*100; for(t=0;t<len;t++) { temp=(num1/mypow(10,len-t-1))%10; if(t==(len-2)) { LCD_ShowChar(x+(len-2)*sizex,y,'.',fc,bc,sizey,0); t++; len+=1; } LCD_ShowChar(x+t*sizex,y,temp+48,fc,bc,sizey,0); } } /****************************************************************************** º¯Êý˵Ã÷£ºÏÔʾͼƬ Èë¿ÚÊý¾Ý£ºx,yÆðµã×ø±ê length ͼƬ³¤¶È width ͼƬ¿í¶È pic[] ͼƬÊý×é ·µ»ØÖµ£º ÎÞ ******************************************************************************/ void LCD_ShowPicture(u16 x,u16 y,u16 length,u16 width,const u8 pic[]) { u16 i,j; u32 k=0; LCD_Address_Set(x,y,x+length-1,y+width-1); for(i=0;i<length;i++) { for(j=0;j<width;j++) { LCD_WR_DATA8(pic[k*2]); LCD_WR_DATA8(pic[k*2+1]); k++; } } }