打印

【我的DIY设计】+基于stm32f3的TFT的汉字显示

[复制链接]
4365|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
kkzz|  楼主 | 2013-1-5 23:19 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
这个是用的一个240*320的彩屏,
采用的是并口数据接入。
下面的是刷屏的程序 分别显示三种不同的颜色




下面开始进入整体 显示一个 感谢21ic 感谢st 的字符

void init_Gpio()//初始化 GPIO口 使用的是AE 两个口
{
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);
  
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOE, &GPIO_InitStructure);
   
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 |GPIO_Pin_4 |GPIO_Pin_3 |GPIO_Pin_2 |GPIO_Pin_1 |GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
        
}


#define uint unsigned int
#define    uchar unsigned char

采用的宏定义 的方法 来实现程序函数的
#define LCD_RD0 GPIO_ResetBits(GPIOA,GPIO_Pin_0)
#define LCD_WR0 GPIO_ResetBits(GPIOA,GPIO_Pin_1)
#define LCD_RS0 GPIO_ResetBits(GPIOA,GPIO_Pin_2)
#define LCD_CS0 GPIO_ResetBits(GPIOA,GPIO_Pin_3)
#define LCD_REST0 GPIO_ResetBits(GPIOA,GPIO_Pin_4)

#define LCD_RD1 GPIO_SetBits(GPIOA,GPIO_Pin_0)
#define LCD_WR1 GPIO_SetBits(GPIOA,GPIO_Pin_1)
#define LCD_RS1 GPIO_SetBits(GPIOA,GPIO_Pin_2)
#define LCD_CS1 GPIO_SetBits(GPIOA,GPIO_Pin_3)
#define LCD_REST1 GPIO_SetBits(GPIOA,GPIO_Pin_4)


void delayms(int count)  // /* X1ms */
{
        int i,j;
        for(i=0;i<count;i++)
          for(j=0;j<100;j++);
}


void LCD_Writ_Bus(char VH,char VL)   //????????
{   
    int temp;
    temp=0;
    GPIO_Write(GPIOE,temp |( VH<<8));   
  LCD_WR0;
    LCD_WR1;
    temp=0;   
    GPIO_Write(GPIOE,temp |( VL<<8) );        
    LCD_WR0;
    LCD_WR1;
}


void LCD_Write_COM(char VH,char VL)     //????
{   
  LCD_RS0;
    LCD_Writ_Bus(VH,VL);
}


void LCD_Write_DATA(char VH,char VL)    //????
{
  LCD_RS1;
    LCD_Writ_Bus(VH,VL);
}
这里是用来设置一个写入方框的
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
    LCD_Write_COM(0x00,0x20);LCD_Write_DATA(x1>>8,x1);      //??X????
  LCD_Write_COM(0x00,0x21);LCD_Write_DATA(y1>>8,y1);   //??Y????
  LCD_Write_COM(0x00,0x50);LCD_Write_DATA(x1>>8,x1);   //??X
    LCD_Write_COM(0x00,0x52);LCD_Write_DATA(y1>>8,y1);      //??Y
  LCD_Write_COM(0x00,0x51);LCD_Write_DATA(x2>>8,x2);   //??X
    LCD_Write_COM(0x00,0x53);LCD_Write_DATA(y2>>8,y2);   //??Y
  LCD_Write_COM(0x00,0x22);                             
}
LCD的初始化 移植的函数 自己写比较麻烦的
void LCD_Init(void)
{                 
  LCD_REST1;
  delayms(5);   
    LCD_REST0;
    delayms(5);
    LCD_REST1;
    LCD_CS1;
    LCD_RD1;
    LCD_WR1;
    delayms(5);

    LCD_CS0;  //??????
    //************* Start Initial Sequence **********//
    LCD_Write_COM(0x00,0xE5); LCD_Write_DATA(0x78,0xF0); // set SRAM internal timing
    LCD_Write_COM(0x00,0x01); LCD_Write_DATA(0x01,0x00); // set SS and SM bit
    LCD_Write_COM(0x00,0x02); LCD_Write_DATA(0x07,0x00); // set 1 line inversion
    LCD_Write_COM(0x00,0x03); LCD_Write_DATA(0x10,0x30); // set GRAM write direction and BGR=1.
    LCD_Write_COM(0x00,0x04); LCD_Write_DATA(0x00,0x00); // Resize register
    LCD_Write_COM(0x00,0x08); LCD_Write_DATA(0x02,0x07); // set the back porch and front porch
    LCD_Write_COM(0x00,0x09); LCD_Write_DATA(0x00,0x00); // set non-display area refresh cycle ISC[3:0]
    LCD_Write_COM(0x00,0x0A); LCD_Write_DATA(0x00,0x00); // FMARK function
    LCD_Write_COM(0x00,0x0C); LCD_Write_DATA(0x00,0x00); // RGB interface setting
    LCD_Write_COM(0x00,0x0D); LCD_Write_DATA(0x00,0x00); // Frame marker Position
    LCD_Write_COM(0x00,0x0F); LCD_Write_DATA(0x00,0x00); // RGB interface polarity
    //*************Power On sequence ****************//
    LCD_Write_COM(0x00,0x10); LCD_Write_DATA(0x00,0x00); // SAP, BT[3:0], AP, DSTB, SLP, STB
    LCD_Write_COM(0x00,0x11); LCD_Write_DATA(0x00,0x07); // DC1[2:0], DC0[2:0], VC[2:0]
    LCD_Write_COM(0x00,0x12); LCD_Write_DATA(0x00,0x00); // VREG1OUT voltage
    LCD_Write_COM(0x00,0x13); LCD_Write_DATA(0x00,0x00); // VDV[4:0] for VCOM amplitude
    LCD_Write_COM(0x00,0x07); LCD_Write_DATA(0x00,0x01);
    delayms(50); // Dis-charge capacitor power voltage
    LCD_Write_COM(0x00,0x10); LCD_Write_DATA(0x10,0x90); // 1490//SAP, BT[3:0], AP, DSTB, SLP, STB
    LCD_Write_COM(0x00,0x11); LCD_Write_DATA(0x02,0x27); // DC1[2:0], DC0[2:0], VC[2:0]
    delayms(50); // Delay 50ms
    LCD_Write_COM(0x00,0x12); LCD_Write_DATA(0x00,0x1F); //001C// Internal reference voltage= Vci;
    delayms(50); // Delay 50ms
    LCD_Write_COM(0x00,0x13); LCD_Write_DATA(0x15,0x00); //0x1000//1400   Set VDV[4:0] for VCOM amplitude  1A00
    LCD_Write_COM(0x00,0x29); LCD_Write_DATA(0x00,0x27); //0x0012 //001a  Set VCM[5:0] for VCOMH  //0x0025  0034
    LCD_Write_COM(0x00,0x2B); LCD_Write_DATA(0x00,0x0D); // Set Frame Rate   000C
    delayms(50); // Delay 50ms
    LCD_Write_COM(0x00,0x20); LCD_Write_DATA(0x00,0x00); // GRAM horizontal Address
    LCD_Write_COM(0x00,0x21); LCD_Write_DATA(0x00,0x00); // GRAM Vertical Address
    // ----------- Adjust the Gamma Curve ----------//
    LCD_Write_COM(0x00,0x30); LCD_Write_DATA(0x00,0x00);
    LCD_Write_COM(0x00,0x31); LCD_Write_DATA(0x07,0x07);
    LCD_Write_COM(0x00,0x32); LCD_Write_DATA(0x03,0x07);
    LCD_Write_COM(0x00,0x35); LCD_Write_DATA(0x02,0x00);
    LCD_Write_COM(0x00,0x36); LCD_Write_DATA(0x00,0x08);//0207
    LCD_Write_COM(0x00,0x37); LCD_Write_DATA(0x00,0x04);//0306
    LCD_Write_COM(0x00,0x38); LCD_Write_DATA(0x00,0x00);//0102
    LCD_Write_COM(0x00,0x39); LCD_Write_DATA(0x07,0x07);//0707
    LCD_Write_COM(0x00,0x3C); LCD_Write_DATA(0x00,0x02);//0702
    LCD_Write_COM(0x00,0x3D); LCD_Write_DATA(0x1D,0x04);//1604
   
    //------------------ Set GRAM area ---------------//
    LCD_Write_COM(0x00,0x50); LCD_Write_DATA(0x00,0x00); // Horizontal GRAM Start Address
    LCD_Write_COM(0x00,0x51); LCD_Write_DATA(0x00,0xEF); // Horizontal GRAM End Address
    LCD_Write_COM(0x00,0x52); LCD_Write_DATA(0x00,0x00); // Vertical GRAM Start Address
    LCD_Write_COM(0x00,0x53); LCD_Write_DATA(0x01,0x3F); // Vertical GRAM Start Address
    LCD_Write_COM(0x00,0x60); LCD_Write_DATA(0xA7,0x00); // Gate Scan Line
    LCD_Write_COM(0x00,0x61); LCD_Write_DATA(0x00,0x01); // NDL,VLE, REV
    LCD_Write_COM(0x00,0x6A); LCD_Write_DATA(0x00,0x00); // set scrolling line
    //-------------- Partial Display Control ---------//
    LCD_Write_COM(0x00,0x80); LCD_Write_DATA(0x00,0x00);
    LCD_Write_COM(0x00,0x81); LCD_Write_DATA(0x00,0x00);
    LCD_Write_COM(0x00,0x82); LCD_Write_DATA(0x00,0x00);
    LCD_Write_COM(0x00,0x83); LCD_Write_DATA(0x00,0x00);
    LCD_Write_COM(0x00,0x84); LCD_Write_DATA(0x00,0x00);
    LCD_Write_COM(0x00,0x85); LCD_Write_DATA(0x00,0x00);
    //-------------- Panel Control -------------------//
    LCD_Write_COM(0x00,0x90); LCD_Write_DATA(0x00,0x10);
    LCD_Write_COM(0x00,0x92); LCD_Write_DATA(0x06,0x00);
    LCD_Write_COM(0x00,0x07); LCD_Write_DATA(0x01,0x33); // 262K color and display ON
    LCD_CS1;  //??????

}
刷屏使用的函数
void Pant(char VH,char VL)
{
    int i,j;
    LCD_CS0;  //??????
    Address_set(0,0,240,320);
    for(i=0;i<320;i++)
     {
      for (j=0;j<240;j++)
           {
             LCD_Write_DATA(VH,VL);
        }
      }
     LCD_CS1;  //??????
}
void printf_char(uchar x, uint y,uchar c, uint color,uint b_color)
{  
    uchar  s_x ,s_y, temp ;
      uint j;
      c -= 32;
      for( s_y=0 ; s_y < 16 ; s_y++ )
   {
        if(s_y+y<320)
       {
            j=c;
           j=j*16+s_y;
           temp=font16x8[j];
             for( s_x=0 ; s_x<8 ; s_x++ )
          {
                if(x+s_x<240)
              {
                     if((temp&(0x80>>(s_x))) == (0x80>>(s_x))  )
                  {
                           dot(x+s_x, y+s_y,color) ;
                  }
                     else
                  {
                         dot(x+s_x, y+s_y,b_color) ;
                   }
               }
           }
       }
    }
}
void printf_string(uchar y, uint x,char  *s, uint color,uint b_color)
{  
    for(;*s!='\0';s++)
    {
        printf_char(x, y,*s, color,b_color);
        x=x+8;
    }
   
}
  用来写汉字的 不过需要自己建立汉字库的 因为有限所以汉字数组略去

void hanzi32_32(uint y,uint x,uchar *value,uint dcolor,uint bgcolor)   
{  
    uint i,j;
  Address_set(x,y,x+31,y+31); //????      
    for(j=0;j<128;j++)
    {
        for(i=0;i<8;i++)
        {              
             if((*value&(1<<i))!=0)
            {
                LCD_Write_DATA(dcolor>>8,dcolor); //?????
            }
            else
            {
                LCD_Write_DATA(bgcolor>>8,bgcolor);    //?????
            }   
        }
        value++;
     }
}

void zf32_32(uint y,uint x,uchar *value,uint dcolor,uint bgcolor)   
{  
    uint i,j;
  Address_set(x,y,x+15,y+31); //????      
    for(j=0;j<64;j++)
    {
        for(i=0;i<8;i++)
        {              
             if((*value&(1<<i))!=0)
            {
                LCD_Write_DATA(dcolor>>8,dcolor); //?????
            }
            else
            {
                LCD_Write_DATA(bgcolor>>8,bgcolor);    //?????
            }   
        }
        value++;
     }
}
这是主函数了
int main()
{

    init_Gpio();
    LCD_Init();          //TFT???
     Pant(0xff,0xff);     //TFT??   
    LCD_CS0;     
   
    hanzi32_32(40,10,gan,0x00,0xffff);   
    hanzi32_32(40,50,xie,0x00,0xffff);        
    zf32_32(40,90,m1,0x00,0xffff);   
    zf32_32(40,110,m2,0x00,0xffff);
    zf32_32(40,130,m3,0x00,0xffff);
    zf32_32(40,150,m4,0x00,0xffff);
        
    hanzi32_32(80,10,gan,0x00,0xffff);   
    hanzi32_32(80,50,xie,0x00,0xffff);        
    zf32_32(80,90,m5,0x00,0xffff);   
    zf32_32(80,110,m6,0x00,0xffff);   
    printf_string(150,10,"Welcome to our BBS of 21IC",0x00,0xffff);   
    printf_string(180,30,"Welcome to use STMCU",0x00,0xffff);   
    while(1);
}


沙发
13249207512| | 2013-1-6 11:34 | 只看该作者

使用特权

评论回复
板凳
gaochy1126| | 2013-1-6 13:42 | 只看该作者
牛 还不错 以后需要整改一下了

使用特权

评论回复
地板
jomosiron| | 2013-1-6 15:44 | 只看该作者
看到ZF 我想到 战复 了。。。

使用特权

评论回复
5
MsZhang| | 2013-1-6 20:13 | 只看该作者
不错~

使用特权

评论回复
6
logger| | 2013-1-6 20:34 | 只看该作者
不错,值得学习借鉴的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

317

主题

10940

帖子

13

粉丝