- #include "LM13232A.h"
- #include "LMFONT.h"
- #define _CS2 PCout(2)
- #define _CS1 PCout(0)
- #define _RST PCout(1)
- #define RS PCout(11)
- #define SCLK PCout(10)
- #define SID PCout(9)
- extern unsigned char LIG1[2];
- extern unsigned char LIG2[2];
- uchar ContrastLevel;
- extern unsigned char LM_CS;
- void lm13232_GPIO_ITN(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- }
- void SdCmd(uchar Command)
- {
- uchar j;
- SCLK = 1;
- RS = 0;
- if(LM_CS==0)
- _CS1 = 0;
- else
- _CS2 = 0;
- for(j=0;j<8;j++)
- {
- if(Command&0x80) SID=1;
- else SID=0;
- SCLK=0;
- SCLK=1;
- Command=Command<<1;
- }
- _CS1=1;
- _CS2=1;
- }
- void SdData(uchar DData)
- {
- uchar j;
- SCLK = 1;
- RS = 1;
- if(LM_CS==0)
- _CS1 = 0;
- else
- _CS2 = 0;
- for(j=0;j<8;j++)
- {
- if(DData&0x80) SID=1;
- else SID=0;
- SCLK=0;
- SCLK=1;
- DData=DData<<1;
- }
- _CS1=1;
- _CS2=1;
- }
- //void WriteScreen(uchar *DisplayData)
- //{
- // uchar TempData;
- // uchar i, j;
- // for(i=0;i<4;i++)
- // {
- // SdCmd(0xb0 | i); // select page
- // SdCmd(0x10); // start form column 0¿aê¼
- // SdCmd(0x00); // (2byte command)
- // for(j=0;j<132;j++)
- // {
- // TempData=(*(DisplayData+(i*132)+j));
- // SdData(TempData);
- // }
- // }
- //}
- void LM_Pos(uchar x,uchar y)
- {
- SdCmd(0xb0+y);
- SdCmd(((x&0xf0)>>4)|0x10);
- SdCmd((x&0x0f)|0x01);
- }
- void LM_Cler(void)
- {
- uchar i,n;
- for(i=0;i<8;i++)
- {
- SdCmd(0xb0+i);
- SdCmd(0x00);
- SdCmd(0x10);
- for(n=0;n<132;n++)SdData(0x00);
- }
- }
- void LM_ShowChar(uchar x,uchar y,uchar chr)
- {
- uchar c=0,i=0;
- c=chr-' ';
- if(x>Max_Column-1){x=0;y=y+2;}
- if(SIZE ==16)
- {
- LM_Pos(x,y);
- for(i=0;i<8;i++)
- SdData(F8X16[c*16+i]);
- LM_Pos(x,y+1);
- for(i=0;i<8;i++)
- SdData(F8X16[c*16+i+8]);
- }
- else
- {
- LM_Pos(x,y+1);
- for(i=0;i<6;i++)
- SdData(F6x8[c][i]);
- }
- }
- int LM_pow(uchar m,uchar n)
- {
- int result=1;
- while(n--)result*=m;
- return result;
- }
-
- void LM_ShowNum(uchar x,uchar y,int num,uchar len,uchar size)
- {
- uchar t,temp;
- uchar enshow=0;
- for(t=0;t<len;t++)
- {
- temp=(num/LM_pow(10,len-t-1))%10;
- if(enshow==0&&t<(len-1))
- {
- if(temp==0)
- {
- LM_ShowChar(x+(size/2)*t,y,' ');
- continue;
- }else enshow=1;
-
- }
- LM_ShowChar(x+(size/2)*t,y,temp+'0');
- }
- }
- //ÏÔê¾ò»¸ö×Ö·ûoÅ′®
- void LM_ShowString(uchar x,uchar y,uchar *chr)
- {
- unsigned char j=0;
- while (chr[j]!='\0')
- { LM_ShowChar(x,y,chr[j]);
- x+=8;
- if(x>120){x=0;y+=2;}
- j++;
- }
- }
- void LM_ShowCHinese(uchar x,uchar y,uchar no)
- {
- u8 t,adder=0;
- LM_Pos(x,y);
- for(t=0;t<16;t++)
- {
- SdData(Hzk[2*no][t]);
- adder+=1;
- }
- LM_Pos(x,y+1);
- for(t=0;t<16;t++)
- {
- SdData(Hzk[2*no+1][t]);
- adder+=1;
- }
- }
- void LM_ShowCHinese_32(uchar x,uchar y,uchar no)
- {
- u8 t,adder=0;
- LM_Pos(x,y);
- for(t=0;t<32;t++)
- {
- SdData(Hzk[8*no][t]);
- adder+=1;
- }
- LM_Pos(x,y+1);
- for(t=0;t<32;t++)
- {
- SdData(Hzk[8*no+1][t]);
- adder+=1;
- }
- }
- void LM_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
- {
- unsigned int j=0;
- unsigned char x,y;
- if(y1%8==0) y=y1/8;
- else y=y1/8+1;
- for(y=y0;y<y1;y++)
- {
- LM_Pos(x0,y);
- for(x=x0;x<x1;x++)
- {
- SdData(BMP[j++]);
- }
- }
- }
- void initLCDM(void)
- {
- lm13232_GPIO_ITN();
- _CS1 = 1;
- _CS2 = 1;
- _RST = 1;
- RS = 1;
- SCLK = 1;
- SID = 1;
- // _RST=1;
- _RST=0;
- delay_ms(1);
- _RST=1;
- delay_ms(100);
- ContrastLevel=0x0f;
- SdCmd(0xaf);
-
- SdCmd(0x40);
- SdCmd(0xa0);
- SdCmd(0xa6);
- SdCmd(0xa4);
- SdCmd(0xa2);
- SdCmd(0xc8);
- SdCmd(0x2f);
- SdCmd(0x23);
- SdCmd(0xf8);SdCmd(0x00);// Booster Ratio Set= 2x,3x,4x (2byte command)
- SdCmd(0x81); // E-Vol setting
- SdCmd(ContrastLevel); // (2byte command)
- }
- //-----------------------------------
- // Main Program
- //-----------------------------------
- //void LM13232A(void)
- //{
- // unsigned char UU[]="LIHUAAN";
- // int aa = 1106495953;
- // initLCDM();
- // LM_Cler();
- // while(1)
- // {
- // LM_ShowChar(90,0,':');
- // LM_ShowString(1,2, UU);
- // LM_ShowNum(0,0,aa,10,16);
- // LM_ShowCHinese(60,2,0);
- // delay_ms(500);//Ñóê±300ms
- // LM_Cler();
- // LM_DrawBMP(0,0,*bmp1);
- // delay_ms(500);//Ñóê±300ms
- //// }
- //}
复制代码 |