打印
[菜农助学交流]

菜鸟学习第六贴:彩屏的刷图(修改篇)

[复制链接]
2835|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 gaochy1126 于 2011-9-22 18:57 编辑

根据投票贴中的建议,我想说明下:我把这个程序修改的跟单片机程序一致了,在网上可以搜到很多的例程,而且例程里面函数可以直接拿过来调用个,不需要修改,这样可以方便大家。如果有什么建议,大家可以提出意见和建议
#include <stdio.h>
#include "NUC1xx.h"
#include "DrvGPIO.h"
#include "DrvSYS.h"


#define          LCD_WR0  DrvGPIO_ClrBit(E_GPB, 1) ;         //写控制
#define          LCD_WR1  DrvGPIO_SetBit(E_GPB, 1);
#define     LCD_RS0  DrvGPIO_ClrBit(E_GPB, 2) ; //数据/命令切换
#define     LCD_RS1  DrvGPIO_SetBit(E_GPB, 2) ;
#define     LCD_REST0  DrvGPIO_ClrBit(E_GPB, 3);  //复位   
#define     LCD_REST1  DrvGPIO_SetBit(E_GPB, 3);
#define     LCD_CS0  DrvGPIO_ClrBit(E_GPB, 4) ;                //片选       
#define     LCD_CS1  DrvGPIO_SetBit(E_GPB, 4) ;
#define          LCD_RD1  DrvGPIO_SetBit(E_GPB, 1); //读控制


unsigned char image[3200]={ /*

//图片代码省略,在例程中附件中
};

void delayms(int count)  // /* X1ms */
{
   DrvSYS_Delay(1000);
}


#ifdef  Bus_16    //条件编译-16位数据模式   
void LCD_Writ_Bus(char VH,char VL)   //并行数据写入函数
{
        unsigned int temp;
        temp= (temp&VH)<<8 + VL;
    DrvGPIO_SetPortBits(E_GPA,temp);       
        LCD_WR0;
        LCD_WR1;
}
#else                        //条件编译-8位数据模式
void LCD_Writ_Bus(char VH,char VL)   //并行数据写入函数
{       
    DrvGPIO_SetPortBits(E_GPA,DrvGPIO_GetPortBits(E_GPA)&VH);       
           LCD_WR0;
        LCD_WR1;
        DrvGPIO_SetPortBits(E_GPA,DrvGPIO_GetPortBits(E_GPA)&VL);               
        LCD_WR0;
        LCD_WR1;
}
#endif






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);                                                         
}

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;  //关闭片选使能
}

main()
{
        int i,j,k;

        UNLOCKREG();                                                                                                                 
    SYSCLK->PWRCON.XTL12M_EN = 1;                                                                               
    DrvSYS_Delay(5000);       


        DrvGPIO_Open(E_GPB, 10, E_IO_OUTPUT);                                                       
        DrvGPIO_ClrBit(E_GPB, 10);                                                                                       
        while(1)
        {
        LCD_Init();          //TFT初始化
        Pant(0xff,0xff);         //TFT清屏                                                                       
          
        LCD_CS0;  //打开片选使能
        for(k=0;k<8;k++)     //刷图片
        {
                   for(j=0;j<6;j++)
                {       
                        Address_set(40*j,40*k,40*j+39,40*k+39);
                    for(i=0;i<1600;i++)
                         {
                          LCD_Write_DATA(image[i*2+1],image[i*2]);
               
                          }
                 }
        }
        LCD_CS1;  //关闭片选使能
        delayms(3000);

    }



}

企鹅.jpg (37.83 KB )

企鹅.jpg

第三个例程--彩屏.zip

2.5 MB

相关帖子

沙发
circuit1234| | 2011-9-21 11:03 | 只看该作者
坐一次沙发。

使用特权

评论回复
板凳
gdmgb520| | 2011-9-21 13:15 | 只看该作者
我也要试试,等我学LOOK先

使用特权

评论回复
地板
老鱼探戈| | 2011-9-23 16:26 | 只看该作者
顶!
俺没有屏

使用特权

评论回复
评分
参与人数 1威望 +1 收起 理由
gaochy1126 + 1
5
gaochy1126|  楼主 | 2011-9-23 17:34 | 只看该作者
呵呵,我的彩屏是以前做项目剩下的,就拿过来试试了! 4# 老鱼探戈

使用特权

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

本版积分规则

1061

主题

11320

帖子

26

粉丝