توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : مشکل با ssd1963
saeid_k67
22-11-2013, 00:39
با سلام
تصویر با کد مربوطه پیوست شد
مشکل بعد از مخصات 250 ایکس خطا داده و به اول ال سی دی اضافه میکند
در ضمن اگر نوشته ای هم نوشته شود باز هم نصف میاره یعنی 4و5 تا کاراکتر رو مینویسه بعدش بقیه رو از اول مینویسه
You can see links before reply
You can see links before reply
کد نوشته شده در ال سی دی :
/************************************************** ************
** Mini Stm32f103
** Eshop:
** You can see links before reply
** Support Team:
** You can see links before reply
** 03527730313
************************************************** *************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "hardware.h"
#include "ili932x.h"
#include "font.h"
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;
uint32_t POINT_COLOR = BLUE,BACK_COLOR = WHITE; /* ·Ö±ðÉèÖõãµÄÑÕÉ«ºÍµ×É« */
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_Write_Reg
** ¹¦ÄÜÃèÊö: дָÁî¼°Êý¾Ý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void LCD_WriteReg(uint16_t LCD_Reg,uint16_t LCD_Dat)
{
Write_Cmd(LCD_Reg);
Write_Dat(LCD_Dat);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: Write_Cmd
** ¹¦ÄÜÃèÊö: дָÁî
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void Write_Cmd(uint16_t LCD_Reg)
{
LCD_CS = 0;
LCD_RS = 0;
GPIOC->ODR = (GPIOC->ODR&0xff00)|(LCD_Reg&0x00ff);
GPIOB->ODR = (GPIOB->ODR&0x00ff)|(LCD_Reg&0xff00);
LCD_WR = 0;
LCD_WR = 1;
LCD_CS = 1;
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: Write_Dat
** ¹¦ÄÜÃèÊö: дÊý¾Ý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void Write_Dat(uint16_t LCD_Dat)
{
LCD_CS = 0;
LCD_RS = 1;
GPIOC->ODR = (GPIOC->ODR&0xff00)|(LCD_Dat&0x00ff);
GPIOB->ODR = (GPIOB->ODR&0x00ff)|(LCD_Dat&0xff00);
LCD_WR = 0;
LCD_WR = 1;
LCD_CS = 1;
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_ReadReg
** ¹¦ÄÜÃèÊö: ¶ÁÖ¸Áî
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
uint16_t LCD_ReadReg(uint16_t LCD_Reg)
{
uint16_t temp;
Write_Cmd(LCD_Reg); //дÈëÒª¶ÁµÄ¼Ä´æÆ÷ºÅ
GPIOB->CRH = (GPIOB->CRH & 0x00000000) | 0x44444444; //½«¶Ë¿Ú¸ß8λÅäÖóÉÊäÈë
GPIOC->CRL = (GPIOC->CRL & 0x00000000) | 0x44444444; //½«¶Ë¿ÚµÍ8λÅäÖóÉÊäÈë
LCD_CS = 0;
LCD_RS = 1;
LCD_RD = 0;
temp = ((GPIOB->IDR&0xff00)|(GPIOC->IDR&0x00ff)); //¶ÁÈ¡Êý¾Ý(¶Á¼Ä´æÆ÷ʱ,²¢²»Ðè Òª¶Á2´Î)
LCD_RD = 1;
LCD_CS = 1;
GPIOB->CRH = (GPIOB->CRH & 0x00000000) | 0x33333333; //ÊͷŶ˿ڸß8λΪÊä³ö
GPIOC->CRL = (GPIOC->CRL & 0x00000000) | 0x33333333; //ÊͷŶ˿ڵÍ8λΪÊä³ö
return temp;
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_ReadDat
** ¹¦ÄÜÃèÊö: ¶ÁÊý¾Ý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
uint16_t LCD_ReadDat()
{
uint16_t temp;
GPIOE->CRH = (GPIOE->CRH & 0x00000000) | 0x44444444; //½«¶Ë¿Ú¸ß8λÅäÖóÉÊäÈë
GPIOE->CRL = (GPIOE->CRL & 0x00000000) | 0x44444444; //½«¶Ë¿ÚµÍ8λÅäÖóÉÊäÈë
LCD_CS = 0;
LCD_RS = 1;
LCD_RD = 0;
temp = ((GPIOB->IDR&0xff00)|(GPIOC->IDR&0x00ff)); //¶ÁÈ¡Êý¾Ý(¶Á¼Ä´æÆ÷ʱ,²¢²»Ðè Òª¶Á2´Î)
LCD_RD = 1;
LCD_CS = 1;
GPIOE->CRH = (GPIOE->CRH & 0x00000000) | 0x33333333; //ÊͷŶ˿ڸß8λΪÊä³ö
GPIOE->CRL = (GPIOE->CRL & 0x00000000) | 0x33333333; //ÊͷŶ˿ڵÍ8λΪÊä³ö
return temp;
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_Configuration
** ¹¦ÄÜÃèÊö: LCD_IO¿ÚÅäÖÃ
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void LCD_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC,ENABLE);
/* ÅäÖÃÊý¾ÝIO Á¬½Óµ½GPIOB *********************/
GPIO_InitStructure.GPIO_Pin = 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_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // ÍÆÍìÊä³ö·½Ê½
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Êä³öIO¿Ú×î´ó×îËÙΪ50MHZ
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* ÅäÖÿØÖÆIO Á¬½Óµ½PD12.PD13.PD14.PD15 *********************/
GPIO_InitStructure.GPIO_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_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // ÍÆÍìÊä³ö·½Ê½
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Êä³öIO¿Ú×î´ó×îËÙΪ50MHZ
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_Init
** ¹¦ÄÜÃèÊö: LCD³õʼ»¯
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void LCD_Init(void)
{
static uint16_t DeviceCode;
LCD_Configuration();
LCD_WriteReg(0x0000,0x0001);
LCD_Delay(5); // LCD_Delay 50 ms
DeviceCode = LCD_ReadReg(0x0000);
printf(" ID=0x%x\n",DeviceCode);
///////////////////////////////////
LCD_Delay(5); // delay 50 ms
Write_Cmd(0x00E2); //PLL multiplier, set PLL clock to 120M
Write_Dat(0x0023); //N=0x36 for 6.5M, 0x23 for 10M crystal
Write_Dat(0x0002);
Write_Dat(0x0004);
Write_Cmd(0x00E0); // PLL enable
Write_Dat(0x0001);
LCD_Delay(1);
Write_Cmd(0x00E0);
Write_Dat(0x0003);
LCD_Delay(5);
Write_Cmd(0x0001); // software reset
LCD_Delay(5);
Write_Cmd(0x00E6); //PLL setting for PCLK, depends on resolution
Write_Dat(0x0001);
Write_Dat(0x0033);
Write_Dat(0x0032);
Write_Cmd(0x00B0); //LCD SPECIFICATION
Write_Dat(0x0020);
Write_Dat(0x0000);
Write_Dat((HDP>>8)&0X00FF); //Set HDP
Write_Dat(HDP&0X00FF);
Write_Dat((VDP>>8)&0X00FF); //Set VDP
Write_Dat(VDP&0X00FF);
Write_Dat(0x0000);
Write_Cmd(0x00B4); //HSYNC
Write_Dat((HT>>8)&0X00FF); //Set HT
Write_Dat(HT&0X00FF);
Write_Dat((HPS>>8)&0X00FF); //Set HPS
Write_Dat(HPS&0X00FF);
Write_Dat(HPW); //Set HPW
Write_Dat((LPS>>8)&0X00FF); //Set HPS
Write_Dat(LPS&0X00FF);
Write_Dat(0x0000);
Write_Cmd(0x00B6); //VSYNC
Write_Dat((VT>>8)&0X00FF); //Set VT
Write_Dat(VT&0X00FF);
Write_Dat((VPS>>8)&0X00FF); //Set VPS
Write_Dat(VPS&0X00FF);
Write_Dat(VPW); //Set VPW
Write_Dat((FPS>>8)&0X00FF); //Set FPS
Write_Dat(FPS&0X00FF);
Write_Cmd(0x00F0); //pixel data interface
Write_Dat(0x0003); /*16λ565¸ñʽ*/
Write_Cmd(0x0021); //½øÈëͼÐÎÑÕÉ«·×ªÄ£Ê½
Write_Cmd(0x00BC);//ÖØÒª
Write_Dat(0x0080);//¶Ô±È¶È
Write_Dat(0x0080);//ÁÁ¶È
Write_Dat(0x0080);//±¥ºÍ¶ÈÖµ //
Write_Dat(0x0001);//´¦Àí»úÔÊÐí
Write_Cmd(0x0029); //display on
LCD_Clear(WHITE);
}
void WR_DATA_Prepare(void)
{
Write_Cmd(0x002c);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_DrawPoint
** ¹¦ÄÜÃèÊö: дһ¸öµã
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color)
{
LCD_SetCursor(x,y); //ÉèÖùâ±êλÖÃ
LCD_WriteRAM_Prepare();
//¿ªÊ¼Ð´ÈëGRAM
Write_Dat(color);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_WriteRAM_Prepare
** ¹¦ÄÜÃèÊö: Щ׼±¸
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void LCD_WriteRAM_Prepare()
{
Write_Cmd(0x002c);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_SetCursor
** ¹¦ÄÜÃèÊö: ÉèÖùâ±êº¯Êý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void LCD_SetCursor(uint8_t Xpos,uint16_t Ypos)
{
Write_Cmd(0x002A);
Write_Dat(Xpos>>8);
Write_Dat(Xpos&0x00ff);
Write_Dat(479>>8);
Write_Dat(479&0x00ff);
Write_Cmd(0x002b);
Write_Dat(Ypos>>8);
Write_Dat(Ypos&0x00ff);
Write_Dat(271>>8);
Write_Dat(271&0x00ff);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_Clear
** ¹¦ÄÜÃèÊö: ÇåÆÁÄ»º¯Êý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
//ÇåÆÁº¯Êý
//Color:ÒªÇåÆÁµÄÌî³äÉ«
void LCD_Clear(u32 color)
{
unsigned int l=480,w;
Write_Cmd(0x002a);
Write_Dat(0);
Write_Dat(0);
Write_Dat(HDP>>8);
Write_Dat(HDP&0x00ff);
Write_Cmd(0x002b);
Write_Dat(0);
Write_Dat(0);
Write_Dat(VDP>>8);
Write_Dat(VDP&0x00ff);
Write_Cmd(0x002c);
while(l--)
{
for(w=0;w<272;w++)
{
Write_Dat(color);
}
}
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: LCD_Delay
** ¹¦ÄÜÃèÊö: ÓÃÓÚLCDÇý¶¯ÑÓʱ
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ06ÈÕ
************************************************** ***************************/
void LCD_Delay (uint32_t nCount)
{
__IO uint16_t i;
for (i=0;i<nCount*100;i++);
}
/**
*Ãû³Æ£ºvoid LCD_WindowMax()
*²ÎÊý£º
*·µ»Ø£ºÎÞ
*¹¦ÄÜ£ºÉèÖô°¿Ú
*±¸×¢£º
**/
void LCD_WindowMax (unsigned int xsta,unsigned int ysta,unsigned int xend,unsigned int yend)
{
Write_Cmd(0X002A);
Write_Dat(xsta>>8);
Write_Dat(xsta&0X00FF);
Write_Dat(xend>>8);
Write_Dat(xend&0X00FF);
Write_Cmd(0X002B);
Write_Dat(ysta>>8);
Write_Dat(ysta&0X00FF);
Write_Dat(yend>>8);
Write_Dat(yend&0X00FF);
}
/**
*Ãû³Æ£ºvoid LCD_Fill(uint8_t xsta, uint16_t ysta, uint8_t xend, uint16_t yend, uint16_t colour)
*²ÎÊý£ºxsta ÆðʼX×ø±ê
ysta ÆðʼY×ø±ê
xend ½áÊøX×ø±ê
yend ½áÊøY×ø±ê
color ´ýÌî³äÑÕÉ«
*·µ»Ø£ºÎÞ
*¹¦ÄÜ£ºÔÚÖ¸¶¨¾ØÐÎÇøÓòÌî³ä ¸¶¨ÑÕÉ«£¬ÇøÓò´óС(xend-xsta)*(yend-ysta)
*±¸×¢£º²¿·ÖÇøÓòÉÙÒ»ÐÐÏñËØ ã
**/
void LCD_Fill(uint8_t xsta, uint16_t ysta, uint8_t xend, uint16_t yend, uint16_t colour)
{
u32 n;
/*ÉèÖô°¿Ú */
LCD_WindowMax (xsta, ysta, xend, yend);
LCD_WriteRAM_Prepare(); /*¿ªÊ¼Ð´ÈëGRAM*/
n=(u32)(yend-ysta+1)*(xend-xsta+1);
while(n--){Write_Dat(colour);} /*ÏÔʾËùÌî³äµÄÑÕÉ«*/
}
/**
*Ãû³Æ£ºvoid LCD_DrawLine(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend)
*²ÎÊý£ºxsta XÆðʼ×ø±ê
ysta YÆðʼ×ø±ê
xend XÖÕµã×ø±ê
yend YÖÕµã×ø±ê
*·µ»Ø£ºÎÞ
*¹¦ÄÜ£ºÖ¸¶¨×ø±í(Á½µã)£¬»Ï
*±¸×¢£ºÐèÒªÌí¼ÓÑÕÉ«²ÎÊý
**/
void LCD_DrawLine(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color)
{
u16 x, y, t;
if((xsta==xend)&&(ysta==yend))
LCD_DrawPoint(xsta, ysta, color);
else
if(abs(yend-ysta)>abs(xend-xsta))/*бÂÊ´óÓÚ1 */
{
if(ysta>yend)
{
t=ysta;
ysta=yend;
yend=t;
t=xsta;
xsta=xend;
xend=t;
}
for(y=ysta;y<yend;y++) /*ÒÔyÖáΪ»ù×¼*/
{
x=(u32)(y-ysta)*(xend-xsta)/(yend-ysta)+xsta;
LCD_DrawPoint(x, y, color);
}
}
else /*бÂÊСÓÚµÈÓÚ1 */
{
if(xsta>xend)
{
t=ysta;
ysta=yend;
yend=t;
t=xsta;
xsta=xend;
xend=t;
}
for(x=xsta;x<=xend;x++) /*ÒÔxÖáΪ»ù×¼*/
{
y =(u32)(x-xsta)*(yend-ysta)/(xend-xsta)+ysta;
LCD_DrawPoint(x, y, color);
}
}
}
/**
*Ãû³Æ£ºvoid Draw_Circle(uint16_t x0, uint16_t y0, uint8_t r)
*²ÎÊý£ºx0 ÖÐÐĵãºá×ø±ê
y0 ÖÐÐĵã×Ý×ø±ê
r °ë¾¶
*·µ»Ø£ºÎÞ
*¹¦ÄÜ£ºÔÚÖ¸¶¨Î»Öûһ¸öÖ¸ ¨´óСµÄÔ²
*±¸×¢£º¼ÓÈëÑÕÉ«²ÎÊý£¬ÊÇ·ñ î³äµÈ
**/
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_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-b, y0-a, color); //7
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);
a++;
/*ʹÓÃBresenhamËã·¨»Ô²*/
if(di<0)di +=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
LCD_DrawPoint(x0+a, y0+b, color);
}
}
/**
*Ãû³Æ£ºvoid LCD_DrawRectangle(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend)
*²ÎÊý£ºxsta XÆðʼ×ø±ê
ysta YÆðʼ×ø±ê
xend X½áÊø×ø±ê
yend Y½áÊø×ø±ê
*·µ»Ø£ºÎÞ
*¹¦ÄÜ£ºÔÚÖ¸¶¨ÇøÓò»¾ØÐÎ
*±¸×¢£º
**/
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);
}
/**
*Ãû³Æ£ºvoid LCD_ShowChar(u8 x, u16 y, u8 num, u8 size, u16 PenColor, u16 BackColor)
*²ÎÊý£ºx£¬y Æðʼ×ø±ê£¨x:0~234 y:0~308£©
num ×Ö·ûASCIIÂëÖµ
size ×Ö·û´óС£¬Ê¹ÓÃĬÈÏ8*16
PenColor ×ÖÌåÑÕÉ«
BackColor ×ÖÌå±³¾°ÑÕÉ«
*¹¦ÄÜ£º
*±¸×¢£º×¢ÒâÆÁÄ»´óС
**/
void LCD_ShowChar(u8 x, u16 y, u8 num, u8 size, u16 PenColor, u16 BackColor)
{
#define MAX_CHAR_POSX 480
#define MAX_CHAR_POSY 272
u8 temp;
u8 pos,t;
if(x>MAX_CHAR_POSX||y>MAX_CHAR_POSY)return;
num=num-' ';
/*µÃµ½Æ«ÒƺóµÄÖµ */
for(pos=0;pos<size;pos++)
{
temp=asc2_1608[num][pos]; /*µ÷ÓÃ1608×ÖÌå */
for(t=0;t<size/2;t++)
{
if(temp&0x01) /*´ÓµÍλ¿ªÊ¼*/
{
LCD_DrawPoint(x+t, y+pos, PenColor); /*»×ÖÌåÑÕÉ« Ò»¸öµã*/
}
else
LCD_DrawPoint(x+t, y+pos, BackColor); /*»±³¾°ÑÕÉ« Ò»¸öµã*/
temp>>=1;
}
}
}
//m^nº¯Êý
u32 mypow(u8 m,u8 n)
{
u32 result=1;
while(n--)result*=m;
return result;
}
//ÏÔʾ2¸öÊý×Ö
//x,y :Æðµã×ø±ê
//len :Êý×ÖµÄλÊý
//size:×ÖÌå´óС
//color:ÑÕÉ«
//num:ÊýÖµ(0~4294967295);
void LCD_ShowNum(u8 x,u8 y,u32 num,u8 len, u16 PenColor, u16 BackColor)
{
u8 size = 16; /* ÕâÀïʹÓÃĬÈϵÄ16*8 */
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)
{
LCD_ShowChar(x+(size/2)*t,y,' ',size, PenColor, BackColor);
continue;
}else enshow=1;
}
LCD_ShowChar(x+(size/2)*t,y,temp+'0',size, PenColor, BackColor);
}
}
/**
Ãû³Æ£ºvoid LCD_ShowCharString(uint16_t x, uint16_t y, const uint8_t *p, uint16_t PenColor, uint16_t BackColor)
²ÎÊý£ºx£¬y Æðʼ×ø±ê
p Ö¸Ïò×Ö·û´®ÆðʼµØÖ·
PenColor ×Ö·ûÑÕÉ«
BackColor ±³¾°ÑÕÉ«
¹¦ÄÜ£º
±¸×¢£ºÓÃ16×ÖÌ壬¿ÉÒÔµ÷½Ú ´Ëº¯Êý²»Äܵ¥¶Àµ÷ÓÃ
**/
void LCD_ShowCharString(uint16_t x, uint16_t y, const uint8_t *p, uint16_t PenColor, uint16_t BackColor)
{
uint8_t size = 16; /*---×Ö·û´óСĬÈÏ16*8---*/
if(x>MAX_CHAR_POSX){x=0;y+=size;} /*³¬³öXÖá×ÖÌå×îСµ¥Î»£¬»»ÐÐ */
if(y>MAX_CHAR_POSY){y=x=0;LCD_Clear(WHITE);} /*³¬³öYÖá×ÖÌå×îСµ¥Î»£¬»Øµ½ Ե㣬²¢ÇÒÇåÆÁ*/
LCD_ShowChar(x, y, *p, size, PenColor, BackColor); /*0±íʾ·Çµþ¼Ó·½Ê½*/
}
/**
*Ãû³Æ: u16 findHzIndex(u8 *hz)
*²ÎÊý£ºhz
*¹¦ÄÜ£ºË÷Òýºº×Ö´æ´¢µÄÄÚ´æ ØÖ·
*±¸×¢£º
**/
u16 findHzIndex(u8 *hz) /* ÔÚ×Ô¶¨Ò庺×Ö¿âÔÚ²éÕÒËùÒªÏ Ôʾ */
/* µÄºº×ÖµÄλÖà */
{
u16 i=0;
FNT_GB16 *ptGb16 = (FNT_GB16 *)GBHZ_16; /*ptGb16Ö¸ÏòGBHZ_16*/
while(ptGb16[i].Index[0] > 0x90)
{
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;
}
/**
*Ãû³Æ£ºvoid WriteOneHz(uint16_t x0, uint16_t y0, uint8_t *pucMsk, uint16_t PenColor, uint16_t BackColor)
*²ÎÊý£ºx0,y0 Æðʼ×ø±ê
*pucMsk Ö¸Ïò
PenColor ×Ö·ûÑÕÉ«
BackColor ±³¾°ÑÕÉ«
*¹¦ÄÜ£º
*±¸×¢£º´Ëº¯Êý²»Äܵ¥¶À×÷Ϊ º×Ö×Ö·ûÏÔʾ
**/
void WriteOneHz(u16 x0, u16 y0, u8 *pucMsk, u16 PenColor, u16 BackColor)
{
u16 i,j;
u16 mod[16]; /* µ±Ç°×ÖÄ£ 16*16 */
u16 *pusMsk; /* µ±Ç°×Ö¿âµØÖ· */
u16 y;
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++) /* 16ÐÐ */
{
for(j=0; j<16; j++) /* 16ÁÐ */
{
if((mod[i] << j) & 0x8000) /* ÏÔʾµÚiÐÐ ¹²16¸öµã */
{
LCD_DrawPoint(x0+j, y0+i, PenColor);
}
else
{
LCD_DrawPoint(x0+j, y0+i, BackColor);
}
}
y++;
}
}
/**
*Ãû³Æ£ºvoid LCD_ShowHzString(u16 x0, u16 y0, u8 *pcStr, u16 PenColor, u16 BackColor)
*²ÎÊý£ºx0£¬y0 Æðʼ×ø±ê
pcStr Ö¸Ïò
PenColor ×ÖÌåÑÕÉ«
BackColor ×ÖÌå±³¾°
*¹¦ÄÜ£ºÏÔʾºº×Ö×Ö·û´®
*±¸×¢£ºÕâ¸öº¯Êý²»Äܵ¥¶Àµ÷ Ã
**/
void LCD_ShowHzString(u16 x0, u16 y0, u8 *pcStr, u16 PenColor, u16 BackColor)
{
#define MAX_HZ_POSX 479
#define MAX_HZ_POSY 271
u16 usIndex;
u8 size = 16;
FNT_GB16 *ptGb16 = 0;
ptGb16 = (FNT_GB16 *)GBHZ_16;
if(x0>MAX_HZ_POSX){x0=0;y0+=size;} /*³¬³öXÖá×ÖÌå×îСµ¥Î»£¬»»ÐÐ */
if(y0>MAX_HZ_POSY){y0=x0=0;LCD_Clear(WHITE);} /*³¬³öYÖá×ÖÌå×îСµ¥Î»£¬»Øµ½ Ե㣬²¢ÇÒÇåÆÁ*/
usIndex = findHzIndex(pcStr);
WriteOneHz(x0, y0, (u8 *)&(ptGb16[usIndex].Msk[0]), PenColor, BackColor); /* ÏÔʾ×Ö·û */
}
/**
*Ãû³Æ£ºvoid LCD_ShowString(u16 x0, u16 y0, u8 *pcstr, u16 PenColor, u16 BackColor)
*²ÎÊý£ºx0 y0 Æðʼ×ø±ê
pcstr ×Ö·û´®Ö¸Õë
PenColor ×ÖÌåÑÕÉ«
BackColor ×ÖÌå±³¾°É«
*¹¦ÄÜ£ºµ÷ÓÃ×Ö·ûºÍºº×ÖÏÔʾ ¯Êý£¬ÊµÏÖ×Ö·û´®ÏÔʾ
*±¸×¢£º
**/
void LCD_ShowString(u16 x0, u16 y0, u8 *pcStr, u16 PenColor, u16 BackColor)
{
while(*pcStr!='\0')
{
if(*pcStr>0x80) /*ÏÔʾºº×Ö*/
{
LCD_ShowHzString(x0, y0, pcStr, PenColor, BackColor);
pcStr += 2;
x0 += 19;
}
else /*ÏÔʾ×Ö·û*/
{
LCD_ShowCharString(x0, y0, pcStr, PenColor, BackColor);
pcStr +=1;
x0+= 8;
}
}
}
/************************************************** **************************
* Ãû ³Æ£ºu16 ili9320_BGRtoRGB(u16 Color)
* ¹¦ ÄÜ£ºRRRRRGGGGGGBBBBB ¸ÄΪ BBBBBGGGGGGRRRRR ¸ñʽ
* Èë¿Ú²ÎÊý£ºColor BRG ÑÕÉ«Öµ
* ³ö¿Ú²ÎÊý£ºRGB ÑÕÉ«Öµ
* ˵ Ã÷£ºÄÚ²¿º¯Êýµ÷ÓÃ
* µ÷Ó÷½·¨£º
************************************************** **************************/
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 EndX,u16 EndY,u16 *pic)
* ¹¦ ÄÜ£ºÔÚÖ¸¶¨×ù±ê·¶Î§ÏÔʾһ¸ ±Í¼Æ¬
* Èë¿Ú²ÎÊý£ºStartX ÐÐÆðʼ×ù±ê
* StartY ÁÐÆðʼ×ù±ê
* EndX ÐнáÊø×ù±ê
* EndY ÁнáÊø×ù±ê
pic ͼƬͷָÕë
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£ºÍ¼Æ¬È¡Ä£¸ñʽΪˮƽɨà 裬16λÑÕɫģʽ
* µ÷Ó÷½·¨£ºLCD_DrawPicture(0,0,100,100,(u 16*)demo);
************************************************** **************************/
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_DrawPoint(StartX+i, StartY+j, *bitmap++);
}
}
کد نوشته در main برنامه :
/************************************************** ************
** Mini Stm32f103
** Eshop:
** You can see links before reply
** Support Team:
** You can see links before reply
** 03527730313
************************************************** *************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "hardware.h"
#include "usart.h"
#include "ili932x.h"
#include <stdio.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
extern uint8_t gImage_fg[];
static __IO uint32_t TimingDelay;
/* Private function prototypes -----------------------------------------------*/
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void TIM_Configuration(void);
uint8_t KEY_Scan(void);
void Delay(__IO uint32_t nTime);
char FirstSwitchWHILE=0,FINALTESTWILE=0,FINALTEST=0,STA RT=0,UPWHILE=0,DOWNWHILE=0,AOUTUUPWHILE=0,AOUTUDOW NWHILE=0,IFAOUTUUPWHILE=0,IFAOUTUDOWNWHILE=0,TEMPU P=0,TEMPDOWN=0;
int TESTINGOK=0;
/* Private functions ---------------------------------------------------------*/
/************************************************** ***************************
** º¯ÊýÃû³Æ: main
** ¹¦ÄÜÃèÊö: Ö÷º¯ÊýÈë¿Ú
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
int main(void)
{
SystemInit(); //ÅäÖÃϵͳʱÖÓ72M(°üÀ¨clock, PLL and Flash configuration)
while(SysTick_Config(SystemFrequency / 1000)); //Systick ÅäÖÃÑÓʱn*ms
GPIO_Configuration(); // Òý½ÅÅäÖÃ
NVIC_Configuration(); //ϵͳÖжÏÅäÖÃ
TIM_Configuration(); //¶¨Ê±Æ÷2³õʼ»¯
USART_Configuration(); //Ò첽ͨÐųõʼ»¯
LCD_Init(); // LCD³õʼ»¯
while (1)
{
LCD_DrawRectangle(10,10,290,260,BLACK);
}
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: GPIO_Configuration
** ¹¦ÄÜÃèÊö: ÅäÖÃIO¿Ú
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOC| RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOB
, ENABLE); // ʹÄܶ˿ÚʱÖÓ£¬ÖØÒª£¡£¡£¡
/* ÅäÖà LED1¡¢LED2Òý½ÅµÄ¹¦ÄÜ *********************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3|GPIO_Pin_8|GPIO_Pin_11|GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ͨÓÃÍÆÍìÊä³öģʽ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Êä³ö×î´óƵÂÊΪ50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //³õʼ»¯PA2¡¢PA3
/* ÅäÖà LED1¡¢LED2Òý½ÅµÄ¹¦ÄÜ *********************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ͨÓÃÍÆÍìÊä³öģʽ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Êä³ö×î´óƵÂÊΪ50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14| GPIO_Pin_12| GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //ÉÏÀÊäÈëģʽ
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* ÅäÖà KEY1¡¢KEY2Òý½ÅµÄ¹¦ÄÜ *********************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //ÉÏÀÊäÈëģʽ
GPIO_Init(GPIOA, &GPIO_InitStructure); //³õʼ»¯PA0¡¢PA1
/* ÅäÖÃ USART1 Tx (PA9) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÿªÂ©Êä³öģʽ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Êä³ö×î´óƵÂÊΪ50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* ÅäÖÃ USART1 Rx (PA10) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈëģʽ
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: TIM_Configuration
** ¹¦ÄÜÃèÊö: ¶¨Ê±Æ÷ÅäÖÃ
1usÒ»¸ö¼ÆÊý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_BaseInitStructure;
TIM_DeInit( TIM2); //¸´Î»TIM2¶¨Ê±Æ÷
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //ʹÄܶ¨Ê±Æ÷2
//TIM2 ʹÓÃÄÚ²¿Ê±ÖÓ
//TIM_InternalClockConfig(TIM1);
//TIM2»ù±¾ÉèÖÃ
//ÉèÖÃÔ¤·ÖƵÆ÷·ÖƵϵÊý71£¬¼´ APB2=72M, TIM1_CLK=72/72=1MHz
//TIM_Period£¨TIM1_ARR£©=1000£¬¼ÆÊýÆ÷Ï ÉϼÆÊýµ½1000ºó²úÉú¸üÐÂʼþ ¬¼ÆÊýÖµ¹éÁã
//ÏòÉϼÆÊýģʽ
//TIM_RepetitionCounter(TIM1_RCR)=0£¬Ã¿´ÎÏò ÏÒç³ö¶¼²úÉú¸üÐÂʼþ
TIM_BaseInitStructure.TIM_Period = 1000; //ÉèÖÃ×Ô¶¯ÖØÔؼĴæÆ÷ֵΪ×î´ óÖµ
TIM_BaseInitStructure.TIM_Prescaler = 71; //×Ô¶¨ÒåÔ¤·ÖƵ
TIM_BaseInitStructure.TIM_ClockDivision = 0;
TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòÉϼÆÊýģʽ
TIM_BaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &TIM_BaseInitStructure);
//ÇåÖжϣ¬ÒÔÃâÒ»ÆôÓÃÖжϺóÁ ¢¼´²úÉúÖжÏ
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
//ʹÄÜTIM2ÖжÏÔ´
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
//TIM2×Ü¿ª¹Ø£º¿ªÆô
TIM_Cmd(TIM2, ENABLE);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: TIM2_IRQHandler
** ¹¦ÄÜÃèÊö: ¶¨Ê±Æ÷2Öжϴ¦Àíº¯Êý
1usÒ»¸ö¼ÆÊý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
uint16_t tick ; // tick counter
uint8_t count;
void TIM2_IRQHandler(void)
{
static uint8_t count=0;
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
tick++;
count++;
// if(count==30)
//{
// LED2 =!LED2;
//}
}
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: KEY_Scan
** ¹¦ÄÜÃèÊö: °´¼ü´¦Àíº¯Êý
0£¬Ã»ÓÐÈκΰ´¼ü°´Ï 1£¬KEY1°´ÏÂ
2£¬KEY2°´ÏÂ
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
uint8_t KEY_Scan(void)
{
static uint8_t KEY_UP=1; //°´¼ü°´ËÉ¿ª±êÖ¾
if(KEY_UP&&(KEY1==0||KEY2==0))
{
Delay(10); //È¥¶¶¶¯
KEY_UP=0;
if(KEY1==0)return 1;
else if(KEY2==0)return 2;
}else if(KEY1==1&&KEY2==1)KEY_UP=1;
return 0; //ÎÞ°´¼ü°´ÏÂ
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: Delay
** ¹¦ÄÜÃèÊö: ÓÃSystickÑÓʱ
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: TimingDelay_Decrement
** ¹¦ÄÜÃèÊö: SystickÖжϽøÈ뺯Êý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: NVIC_Configuration
** ¹¦ÄÜÃèÊö: ϵͳÖжϹÜÀí
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //ÉèÖÃÖжÏ×éΪ0
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //¸üÐÂʼþ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriori ty = 0; //ÇÀÕ¼ÓÅÏȼ¶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //ÏìÓ¦ÓÅÏȼ¶1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ÔÊÐíÖжÏ
NVIC_Init(&NVIC_InitStructure); //дÈëÉèÖÃ
}
/************************************************** ***************************
** º¯ÊýÃû³Æ: EXTI0_IRQHandler
** ¹¦ÄÜÃèÊö: ÍⲿÖжÏ0½øÈë¿Ú
´¦ÀíÖжϺ¯Êý
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
************************************************** ***************************/
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_IMR_MR0) != RESET)
{
Delay(50); //ÑÓʱȡÏû¶¶
EXTI_ClearITPendingBit(EXTI_IMR_MR0); //Çå³ýLINE13ÉϵÄÖжϱê־λ
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/************************************************** *****************************
** End of File
************************************************** ******************************/
باتشکر
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.