⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 9320.c

📁 这是我为公司写的手机上用的TFT显示屏的测试软件
💻 C
字号:
/************************************************
module                  HYT038-028          ILI9320+Wintek 2.8
LCD
IC			9320
VDD			2.8V
IDD
Iled
interface	8080/16bits
programed	Zhalingun	 
date		2007.8.1   
************************************************/
#include <reg51.h>
#include "stdio.h"
#include "ABSACC.h"

sbit  CS    	=P3^3;
sbit  Reset 	=P3^4;
sbit  RS        =P3^0;
sbit  Wr        =P3^1;
sbit  Rd        =P3^2;
sbit  Key       =P1^6;
////////////////
sbit  P10         =P1^0;
sbit  P11         =P1^1;
sbit  P12         =P1^2;
sbit  P13         =P1^3;
sbit  P14         =P1^4;
sbit  P16         =P1^6;
sbit  P17         =P1^7;
/////////////////////////
sbit  Ram_chip_select1  =P1^4;
sbit  Ram_chip_select2  =P1^5;
sbit  Ram_chip_select3  =P1^3;
#define	 uint   unsigned int
#define  uchar  unsigned char
uchar code Picture[];
uchar *p;

void WData(uchar i,j)
{
    CS = 0;
	RS = 1;
	Rd = 1;
	Wr = 0;
	P2  = i; // high
	P0  = j; // low
	Wr = 1;
	CS = 1;
}

void WCom(uchar i,j)
{
    CS = 0;
	Rd = 1;
    RS = 0;
	Wr = 0;
    P2  = i; // high
    P0  = j; // low
	Wr  = 1;
	CS  = 1;
}
void Delay_ms(uchar Nms)//1ms
{
 uchar i,j,k;
 for(i=0;i<Nms;i++)
	for(j=0;j<5;j++)
		for(k=0;k<131;k++);
}
void WaitKey()
{
 Key=1;
 while(Key);
}
 void LCD_RESET()

{      Reset=1;

       Delay_ms(10);

       Reset=0;

       Delay_ms(100);

       Reset=1;

       Delay_ms(100);

}
void InitMain()
{
	//exit sleep_9320
   WCom(0x00,0xE5);WData(0x80,0x00);     // Set the internal vcore voltage
   WCom(0x00,0x00);WData(0x00,0x01);     // Start internal OSC.
   WCom(0x00,0x01);WData(0x01,0x00);	 // set SS and SM bit
   WCom(0x00,0x02);WData(0x07,0x00);     // set 1 line inversion
   WCom(0x00,0x03);WData(0x10,0x30);     // set GRAM write direction and BGR=1.
   WCom(0x00,0x04);WData(0x00,0x00);     // Resize register
   
   WCom(0x00,0x08);WData(0x02,0x02);     // set the back porch and front porch
   WCom(0x00,0x09);WData(0x00,0x00);     // set non-display area refresh cycle ISC[3:0]
   WCom(0x00,0x0A);WData(0x00,0x00);     // FMARK function
   WCom(0x00,0x0C);WData(0x00,0x00);     // RGB interface setting
   WCom(0x00,0x0D);WData(0x00,0x00);     // Frame marker Position
   WCom(0x00,0x0E);WData(0x00,0x00);     // RGB interface polarity
   //*************Power On sequence ****************//
   WCom(0x00,0x10);WData(0x00,0x00);     // SAP, BT[3:0], AP, DSTB, SLP, STB
   WCom(0x00,0x11);WData(0x00,0x07);     // DC1[2:0], DC0[2:0], VC[2:0]
   WCom(0x00,0x12);WData(0x00,0x00);     // VREG1OUT voltage
   WCom(0x00,0x13);WData(0x00,0x00);     // VDV[4:0] for VCOM amplitude
    Delay_ms(200);                       // Dis-charge capacitor power voltage

   WCom(0x00,0x10);WData(0x17,0xB0);     // SAP, BT[3:0], AP, DSTB, SLP, STB
   WCom(0x00,0x11);WData(0x00,0x37);     // DC1[2:0], DC0[2:0], VC[2:0]
     Delay_ms(50);			 // Delay 50ms
   WCom(0x00,0x12);WData(0x01,0x3A);     // VREG1OUT voltage
      Delay_ms(50);			 // Delay 50ms
   WCom(0x00,0x13);WData(0x18,0x00);     // VDV[4:0] for VCOM amplitude
   WCom(0x00,0x29);WData(0x00,0x14);     // VCM[4:0] for VCOMH
      Delay_ms(50);

   WCom(0x00,0x20);WData(0x00,0x00);     // GRAM horizontal Address
   WCom(0x00,0x21);WData(0x00,0x00);     // GRAM Vertical Address


  // ----------- Adjust the Gamma  Curve ----------//
    WCom(0x00,0x30);WData(0x00,0x00);
    WCom(0x00,0x31);WData(0x02,0x03);
    WCom(0x00,0x32);WData(0x03,0x01);
    WCom(0x00,0x35);WData(0x00,0x03);
    WCom(0x00,0x36);WData(0x10,0x0B);
    WCom(0x00,0x37);WData(0x06,0x05);
    WCom(0x00,0x38);WData(0x05,0x05);
    WCom(0x00,0x39);WData(0x07,0x07);
    WCom(0x00,0x3C);WData(0x07,0x00);
    WCom(0x00,0x3D);WData(0x0F,0x04);

//------------------ Set GRAM area ---------------//
    WCom(0x00,0x50);WData(0x00,0x00);               // Horizontal GRAM Start Address
    WCom(0x00,0x51);WData(0x00,0xEF);   	    // Horizontal GRAM End Address
    WCom(0x00,0x52);WData(0x00,0x00);               // Vertical GRAM Start Address
    WCom(0x00,0x53);WData(0x01,0x3F);               // Vertical GRAM Start Address


    WCom(0x00,0x60);WData(0x27,0x00);               // Gate Scan Line
    WCom(0x00,0x61);WData(0x00,0x01);               // NDL,VLE, REV
    WCom(0x00,0x6A);WData(0x00,0x00);               // set scrolling line

  //-------------- Partial Display Control ---------//
    WCom(0x00,0x80);WData(0x00,0x00);
    WCom(0x00,0x81);WData(0x00,0x00);
    WCom(0x00,0x82);WData(0x00,0x00);
    WCom(0x00,0x83);WData(0x00,0x00);
    WCom(0x00,0x84);WData(0x00,0x00);
    WCom(0x00,0x85);WData(0x00,0x00);

  //-------------- Panel Control -------------------//
    WCom(0x00,0x90);WData(0x00,0x10);
    WCom(0x00,0x92);WData(0x00,0x00);
    WCom(0x00,0x93);WData(0x00,0x03);
    WCom(0x00,0x95);WData(0x01,0x10);
    WCom(0x00,0x97);WData(0x00,0x00);
    WCom(0x00,0x98);WData(0x00,0x00);


    WCom(0x00,0x07);WData(0x01,0x73);       	    // 262K color and display ON
}

void MainAddset()
{

	WCom(0x00,0x21);WData(0x00,0x00);
	WCom(0x00,0x22);
}

void MainWriteRGB(uchar H,uchar L)
{
	int	Row,Column;
	MainAddset();
	for(Row=0;Row<240;Row++)
		for(Column=0;Column<320;Column++)
			WData(H,L);
}

void BankSelect(uchar Bank)
{
       switch (Bank)
       {
              case 0://ROM PAGE 0
              P10=0;
              P11=0;
              P12=0;
              break;

              case 1://ROM PAGE 1
              P10=1;
              P11=0;
              P12=0;
              break;

              case 2://ROM PAGE 2
              P10=0;
              P11=1;
              P12=0;
              break;

              case 3://ROM PAGE 3
              P10=1;
              P11=1;
              P12=0;
              break;

              case 4://ROM PAGE 4
              P10=0;
              P11=0;
              P12=1;
              break;

              case 5://ROM PAGE 5
              P10=1;
              P11=0;
              P12=1;
              break;

              case 6://ROM PAGE 6
              P10=0;
              P11=1;
              P12=1;
              break;

              case 7://ROM PAGE 7
              P10=1;
              P11=1;
              P12=1;
              break;
       }
}
void picc1( int Addr,char Pic_number1,char Pic_number2,char Pic_number3,char Pic_number4)
{
       int Row,Column;
       int RamData1,RamData2;
       MainAddset();
//////////////////////////////////////////
       BankSelect(Pic_number1);


       for(Row=0;Row<240;Row++)
             {
              for(Column=0;Column<80;Column++)

                   {   Ram_chip_select2=0;
                     RamData1=XBYTE[Addr++];
                     RamData2=XBYTE[Addr++];
                     Ram_chip_select2=1;
                     WData(RamData1,RamData2);

              }  }
        Addr=0X0000;
		//WaitKey();
/////////////////////////////////////////
       BankSelect(Pic_number2);
       for(Row=0;Row<240;Row++)
              {
              for(Column=0;Column<80;Column++)
                     {
                     Ram_chip_select2=0;
                     RamData1=XBYTE[Addr++];
                     RamData2=XBYTE[Addr++];
                       Ram_chip_select2=1;
                     WData(RamData1,RamData2);
                     }
              }
        Addr=0X0000;   //WaitKey();
/////////////////////////////////////////
       BankSelect(Pic_number3);
       for(Row=0;Row<240;Row++)
              {
              for(Column=0;Column<80;Column++)
                      {
                    Ram_chip_select2=0;
                     RamData1=XBYTE[Addr++];
                     RamData2=XBYTE[Addr++];
                     Ram_chip_select2=1;
                     WData(RamData1,RamData2);
                     }
					 }
            Addr=0X0000;   //WaitKey();
//////////////////////////////////////////
       BankSelect(Pic_number4);
       for(Row=0;Row<240;Row++)
              {
              for(Column=0;Column<80;Column++)
                     {
                     Ram_chip_select2=0;
                     RamData1=XBYTE[Addr++];
                     RamData2=XBYTE[Addr++];
                      Ram_chip_select2=1;
                     WData(RamData1,RamData2);
                     }
                }
            Addr=0X0000; //WaitKey();
           }



void Main()
{LCD_RESET();
 InitMain();
   while(1)
 {


         picc1(0x0000,0,1,2,3);
	 Delay_ms(200);Delay_ms(200); //WaitKey();
          picc1(0x0000,4,5,6,7);
	  Delay_ms(200);Delay_ms(200);//WaitKey();

	   MainWriteRGB(0xf8,0x00);
          Delay_ms(200);Delay_ms(200);// WaitKey();
	  MainWriteRGB(0x07,0xe0);
         Delay_ms(200);Delay_ms(200);//WaitKey();
	   MainWriteRGB(0x00,0x1f);
          Delay_ms(200);Delay_ms(200);//WaitKey();
		  display_pic();
	WaitKey();



  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -