这些研讨会中,有你的菜吗? >>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 320x240真彩TFT屏51单片机驱动刷屏程序

共8条 1/1 1 跳转至

320x240真彩TFT屏51单片机驱动刷屏程序

助工
2012-02-19 22:02:46     打赏

#include <reg52.h>

sfr16 DPTR=0x82;

sbit A0 = P1^1;   //数据/命令切换
sbit RES = P1^4;       //复位
sbit WRB = P1^2;    //写控制
sbit RDB =P1^3;    //读控制
sbit CS_MAIN=P1^0; 
sbit led = P0^0;    
 
void delayms(int count)  //10ms
{
        int i,j;
        for(i=0;i<count;i++)
                for(j=0;j<100;j++);
}
 

void main_Write_COM( int  CH)  //8位数据接口发送命令 

    A0=0;
 CS_MAIN =0; 
    DPTR=CH;    
 P2=DPH; 
    WRB=0;
 WRB=1;
 P2=DPL;  
 WRB=0;
 WRB=1;
 CS_MAIN =1; 
}


void main_Write_DATA(int DH) //8位数据接口发送数据  
{
    A0=1;
 CS_MAIN =0;
  DPTR=DH;      
    P2=DPH; 
 WRB=0;
 WRB=1;
 P2=DPL;      
 WRB=0;
 WRB=1;
 CS_MAIN =1; 
}


void main_W_com_data( int com1,dat1)
{
   main_Write_COM(com1);
   main_Write_DATA(dat1);
}


void address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
    main_W_com_data(0x0020,x1);//设置X坐标位置
    main_W_com_data(0x0021,y1);//设置Y坐标位置
    main_W_com_data(0x0050,x1);   //开始X
 main_W_com_data(0x0052,y1);   //开始Y
    main_W_com_data(0x0051,x2);  //结束X
 main_W_com_data(0x0053,y2);  //结束Y
    main_Write_COM(0x0022);
}

void main_init(void)
{

    RES=1;
    delayms(5); 
 RES=0;
 delayms(10);
 RES=1;
 delayms(20);


//************* Start Initial Sequence **********//
main_Write_COM(0x00E5); main_Write_DATA(0x78F0); // set SRAM internal timing
main_Write_COM(0x0001); main_Write_DATA(0x0100); // set SS and SM bit
main_Write_COM(0x0002); main_Write_DATA(0x0700); // set 1 line inversion
main_Write_COM(0x0003); main_Write_DATA(0x1030); // set GRAM write direction and BGR=1.
main_Write_COM(0x0004); main_Write_DATA(0x0000); // Resize register
main_Write_COM(0x0008); main_Write_DATA(0x0207); // set the back porch and front porch
main_Write_COM(0x0009); main_Write_DATA(0x0000); // set non-display area refresh cycle ISC[3:0]
main_Write_COM(0x000A); main_Write_DATA(0x0000); // FMARK function
main_Write_COM(0x000C); main_Write_DATA(0x0000); // RGB interface setting
main_Write_COM(0x000D); main_Write_DATA(0x0000); // Frame marker Position
main_Write_COM(0x000F); main_Write_DATA(0x0000); // RGB interface polarity
//*************Power On sequence ****************//
main_Write_COM(0x0010); main_Write_DATA(0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
main_Write_COM(0x0011); main_Write_DATA(0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
main_Write_COM(0x0012); main_Write_DATA(0x0000); // VREG1OUT voltage
main_Write_COM(0x0013); main_Write_DATA(0x0000); // VDV[4:0] for VCOM amplitude
main_Write_COM(0x0007); main_Write_DATA(0x0001);
delayms(200); // Dis-charge capacitor power voltage
main_Write_COM(0x0010); main_Write_DATA(0x1090); // 1490//SAP, BT[3:0], AP, DSTB, SLP, STB
main_Write_COM(0x0011); main_Write_DATA(0x0227); // DC1[2:0], DC0[2:0], VC[2:0]
delayms(50); // Delay 50ms
main_Write_COM(0x0012); main_Write_DATA(0x001F); //001C// Internal reference voltage= Vci;
delayms(50); // Delay 50ms
main_Write_COM(0x0013); main_Write_DATA(0x1500); //0x1000//1400   Set VDV[4:0] for VCOM amplitude  1A00
main_Write_COM(0x0029); main_Write_DATA(0x0027); //0x0012 //001a  Set VCM[5:0] for VCOMH  //0x0025  0034
main_Write_COM(0x002B); main_Write_DATA(0x000D); // Set Frame Rate   000C
delayms(50); // Delay 50ms
main_Write_COM(0x0020); main_Write_DATA(0x0000); // GRAM horizontal Address
main_Write_COM(0x0021); main_Write_DATA(0x0000); // GRAM Vertical Address
// ----------- Adjust the Gamma Curve ----------//
main_Write_COM(0x0030); main_Write_DATA(0x0000);
main_Write_COM(0x0031); main_Write_DATA(0x0707);
main_Write_COM(0x0032); main_Write_DATA(0x0307);
main_Write_COM(0x0035); main_Write_DATA(0x0200);
main_Write_COM(0x0036); main_Write_DATA(0x0008);//0207
main_Write_COM(0x0037); main_Write_DATA(0x0004);//0306
main_Write_COM(0x0038); main_Write_DATA(0x0000);//0102
main_Write_COM(0x0039); main_Write_DATA(0x0707);//0707
main_Write_COM(0x003C); main_Write_DATA(0x0002);//0702
main_Write_COM(0x003D); main_Write_DATA(0x1D04);//1604

//------------------ Set GRAM area ---------------//
main_Write_COM(0x0050); main_Write_DATA(0x0000); // Horizontal GRAM Start Address
main_Write_COM(0x0051); main_Write_DATA(0x00EF); // Horizontal GRAM End Address
main_Write_COM(0x0052); main_Write_DATA(0x0000); // Vertical GRAM Start Address
main_Write_COM(0x0053); main_Write_DATA(0x013F); // Vertical GRAM Start Address
main_Write_COM(0x0060); main_Write_DATA(0xA700); // Gate Scan Line
main_Write_COM(0x0061); main_Write_DATA(0x0001); // NDL,VLE, REV
main_Write_COM(0x006A); main_Write_DATA(0x0000); // set scrolling line
//-------------- Partial Display Control ---------//
main_Write_COM(0x0080); main_Write_DATA(0x0000);
main_Write_COM(0x0081); main_Write_DATA(0x0000);
main_Write_COM(0x0082); main_Write_DATA(0x0000);
main_Write_COM(0x0083); main_Write_DATA(0x0000);
main_Write_COM(0x0084); main_Write_DATA(0x0000);
main_Write_COM(0x0085); main_Write_DATA(0x0000);
//-------------- Panel Control -------------------//
main_Write_COM(0x0090); main_Write_DATA(0x0010);
main_Write_COM(0x0092); main_Write_DATA(0x0600);
main_Write_COM(0x0007); main_Write_DATA(0x0133); // 262K color and display ON

}

void Pant(unsigned int color)
{
 int i,j;
 address_set(0,0,240,320);

    for(i=0;i<320;i++)
  {
   for (j=0;j<240;j++)
     {
         main_Write_DATA(color);
     }

   }


}

main()
{
    led = 0;
 main_init();   //tft初始化 
 while(1)
 {
    Pant(0xf800); //红
    Pant(0X07E0); //绿
    Pant(0x001f); //蓝   
       Pant(0xffe0); //黄
    Pant(0x0000); //黑
    Pant(0xffff); //白
    Pant(0x07ff); //青
    Pant(0xd343); //暗红
    }

 

}

 

 

 

 

 

 

 




关键词: 320x240     真彩     单片机     驱动     刷屏     程序     W    

高工
2012-02-20 01:31:33     打赏
2楼
顶,

附带配套电路图就更好了

工程师
2012-02-20 13:30:05     打赏
3楼
code???

专家
2012-02-20 19:22:59     打赏
4楼

嗯,楼主继续,最好配几张图片啊。


菜鸟
2012-02-21 09:09:01     打赏
5楼
需要说明呀,程序只是对配套的电路才有用呀!

菜鸟
2012-02-28 10:39:11     打赏
6楼
谢谢分享!

是哦,附上电路图就更好了。

菜鸟
2013-05-15 10:36:31     打赏
7楼
有谁会使用FPGA开驱动320x240真彩TFT屏的吗?使用51单片机来刷屏算是可以,但是如果将其来显示SD卡中的图片的话,显然51单片机的速度是不行的

菜鸟
2013-08-01 15:04:16     打赏
8楼
不错不错

共8条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]