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

📄 cmc-cg1n0298dfsw-w-e.c

📁 LCD driver CMC-CG1N0298DFSW-W-E CSTN 128*160
💻 C
字号:
/*****************************************************************************************/
/*                                                        
                      (c) Copyright 2007   WLAN Department
------------------------------------------------------------------------------------
File        : 
Author      : Li Qin
Purpose     : LCD Driver
              Truly CMC-CG1N0298DFSW-W-E CSTN 128*160
              16-bit driver : S633BC

              RS      -- A1
              NCS     -- CS3    0x83000000    Index
                                0x83000010    Control 
              NRESET  -- P0.10                          
------------------------------------------------------------------------------------ */
/*****************************************************************************************/

#include "LPC2220.h"
#include "type.h"
#include "includes.h"

typedef struct _RECT
{
   int x;
   int y;
   int width;
   int height;
}RECT;

#define  CMC_BASE  0x83000000
#define  PIN_RST  (1<<10)  //Reset p0.10 
#define  PIN_BAK  (1<<19)  //Reset p1.19

#define  CTRL1 0xC2
#define  PageAddress_Offset  0x00
#define  ColumnAddress_Offset  0x00
#define  Init_PageS  0x00+PageAddress_Offset
#define  Init_PageE  0x9F+PageAddress_Offset
#define  Init_ColumnS  0x00+ColumnAddress_Offset
#define  Init_ColumnE  0x7F+ColumnAddress_Offset

#define MainLCD_WCom(_data)   *((volatile unsigned char *)(CMC_BASE )) = _data 
#define Delayms       OSTimeDly

#ifndef SCREEN_WIDTH  
#define SCREEN_WIDTH 160//128
#endif

#ifndef SCREEN_HEIGHT  
#define SCREEN_HEIGHT 128//160
#endif

unsigned char contrast1;
unsigned char ElectronicValue;

uint16 ScreenBuf[SCREEN_HEIGHT][SCREEN_WIDTH];

static void SetRST( bool status ) /* "0" reset, "1" normal mode */                                
{
   if(status) 
   IOSET0 |= PIN_RST;
   else 
   IOCLR0 |= PIN_RST;
}

static void SetBacklight( bool status) /* "0" off, "1" on*/
{
   if(status) 
   IOSET1 |= PIN_BAK; 
   else 
   IOCLR1 |= PIN_BAK; 	
}

static void InitCPU( void )
{	 
    PINSEL2 &= ~(1<<3); 
    IODIR0 |= (PIN_RST);
    IODIR1 |= (PIN_BAK);
	
    /*Bus config*/   
    
    BCFG3 = (0x00<<28)|(0x01<<10)|(0x7<<11)|(0x7<<5)|7; 
	 /*IDCY   3:0
                                                WST1   9:5  
                                                WST2   15:11
												0- byte 1-16bit        10
                                                width 01     8bit */
 /*                                               
    EMC_STA_CFG3      = 0x00000080;        // 8 bit width 
    EMC_STA_WAITWEN3  = 0x7;		   // write enable delay (n+1) cclk
    EMC_STA_WAITOEN3  = 0x7;		   // read enable dealy	 (n+1) cclk
    EMC_STA_WAITRD3   = 0x1f;		   // read access  32 CLK	 __QUESTION
    //EMC_STA_WAITPAGE0 = 0x1f;
    EMC_STA_WAITWR3   = 0x1f;		   // write access  32 CLK
    EMC_STA_WAITTURN3 = 0xf;		   // turn around delay
  */
    OSTimeDly(10);
                   
    SetRST(0); 
    OSTimeDly(20);
    SetRST(1);
    OSTimeDly(20);
    
    SetBacklight(0);
}
/*
static int InitCMC(void)
{
    InitCPU();
    memset( &(ScreenBuf[0][0]), 0x00, 2*SCREEN_WIDTH*SCREEN_HEIGHT );
    return 1;
}
*/

static int StartCMC(void)
{
    //int i;
    //RECT rect = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};

  
    /* Initialize S6B33BCX01-B0CY */
  
    MainLCD_WCom(0x2C);  //STANDBY MODE OFF
    Delayms(40);        
    //MainLCD_WCom(0xEA);  //OTP MODE OFF
    MainLCD_WCom(0x02); MainLCD_WCom(0x01);   //SET INTERNAL OCS ON
    Delayms(20);
    MainLCD_WCom(0x20); MainLCD_WCom(0x05);   //1'ST DC/DC SET TO 2X TIME BOOSTER
    Delayms(20);
    MainLCD_WCom(0x26); MainLCD_WCom(0x01);   //BOOSTER1 ON
    Delayms(20);
    MainLCD_WCom(0x26); MainLCD_WCom(0x09);   //BOOSTER1 ON AND AMP ON
    Delayms(20);
    MainLCD_WCom(0x26); MainLCD_WCom(0x0B);   //BOOSTER1 ON AND AMP ON
    Delayms(20);
    MainLCD_WCom(0x26); MainLCD_WCom(0x0F);   //BOOSTER1 ON AND AMP ON
    Delayms(20);
    MainLCD_WCom(0x28); MainLCD_WCom(0x01);   //TEMP COMPENSATION RATIO -0.00%
    Delayms(5);
    MainLCD_WCom(0x2E);   //BURST MODE OFF  8 BIT
    MainLCD_WCom(0x45); MainLCD_WCom(0x00);   //RAM SKIP AREA SET NO SKIP
    MainLCD_WCom(0x53); MainLCD_WCom(0x00);   //NORMAL DISPLAY
    MainLCD_WCom(0x10); MainLCD_WCom(0x25);   //drive mode   SET SDIR=0,DUTY=1/132,SWAP=0
    MainLCD_WCom(0x24); MainLCD_WCom(0x22);   //SET CLOCK DIV FPCK=FOSE/16
    MainLCD_WCom(0x30); MainLCD_WCom(0x02);   //ADDRESSING MODE SET TO DEFAULT, GSM,DSG,SGF,SGP,SGM0d
    MainLCD_WCom(0x32); MainLCD_WCom(0x0E);   //ROW VECTOR TYPE=DIAGONAL,INCREMENT TYPE=Y
    MainLCD_WCom(0x40); MainLCD_WCom(0x00);   //ENTRY MODE SET:Y ADDRESS INCRECE,READ MODIFY WRITE OFF
    MainLCD_WCom(0x42); MainLCD_WCom(Init_PageS); MainLCD_WCom(Init_PageE);  //X ADDRESS
    MainLCD_WCom(0x43); MainLCD_WCom(Init_ColumnS); MainLCD_WCom(Init_ColumnE);  //Y ADDRESS
    Delayms(1);
    MainLCD_WCom(0x34); MainLCD_WCom(0x07);  //FRAME Set FIM,FIP,N-BLK
    MainLCD_WCom(0x2A); MainLCD_WCom(CTRL1);  //对比度1, CONTRAST SET V1
    Delayms(20);
    MainLCD_WCom(0x2B); MainLCD_WCom(0x54);   //对比度2, set V1,partial display
    Delayms(20);
    MainLCD_WCom(0x22); MainLCD_WCom(0x11);   //BIAS SET TO 1/5 AND -4X TIME 2'ND BOOSTER
    MainLCD_WCom(0x36); MainLCD_WCom(0x00);   // Frame Frequency Control
    MainLCD_WCom(0x55); MainLCD_WCom(0x00);   //ENTER PARTIAL DISPLAY MODE, OFF
    MainLCD_WCom(0x51);                       //DISPLAY ON
   
    contrast1=CTRL1;     /*用全局变量记住对比度1的初始值,以便调节*/
    ElectronicValue=CTRL1;

    return 1;
}

void RefreshCMC( RECT* rect )
{
      uint8 i,j;
       
      uint8 width = rect->width;
      uint8 height = rect->height;
      uint8 PageS = rect->x;
      uint8 PageE = rect->x + width -1;
      uint8 ColumnS = rect->y;
      uint8 ColumnE = rect->y + height-1;     
      uint8 Offset = SCREEN_WIDTH - width; 
      uint16* pRead = &ScreenBuf[0][0]+rect->y*SCREEN_WIDTH+rect->x;
          
      MainLCD_WCom(0x40); MainLCD_WCom(0x00);
      MainLCD_WCom(0x42); MainLCD_WCom(PageS); MainLCD_WCom(PageE);
      MainLCD_WCom(0x43); MainLCD_WCom(ColumnS); MainLCD_WCom(ColumnE); 
   
	  //Delayms(10);
       
      for( i=0;i<height;i++)
      {
       	for( j=0;j<width;j++)
	    {     
		  uint16 data = *pRead++;
		  *((volatile unsigned char *)(CMC_BASE+2 )) = (uint8)(data); 
		  *((volatile unsigned char *)(CMC_BASE+2 )) = (uint8)(data>>8); 
	    }
	  pRead +=Offset;
	}                   
}

void MainLCD_PowerOff(void)
{
       MainLCD_WCom(0x50);     //display off
       MainLCD_WCom(0x2D);      //standby mode on
       MainLCD_WCom(0x26);MainLCD_WCom(0x0B);   //DC-DC3 off
       MainLCD_WCom(0x26);MainLCD_WCom(0x09);   //DC-DC2 off
       MainLCD_WCom(0x26);MainLCD_WCom(0x01);   //AMP off
       MainLCD_WCom(0x26);MainLCD_WCom(0x00);   //DC-DC1 off
       MainLCD_WCom(0x02);MainLCD_WCom(0x00);    //OSC off
       Delayms(20);                              //waiting for discharge
}

void MainLCD_PowerOn(void)
{
       MainLCD_WCom(0x2C);      //standby mode off
       MainLCD_WCom(0x02);MainLCD_WCom(0x01);    //OSC on
       Delayms(20); 
       MainLCD_WCom(0x26);MainLCD_WCom(0x01);   //booster1 on
       MainLCD_WCom(0x26);MainLCD_WCom(0x09);   //AMP on
       MainLCD_WCom(0x26);MainLCD_WCom(0x0B);   //DC-DC2 on
       MainLCD_WCom(0x26);MainLCD_WCom(0x0F);   //DC-DC3 on
       Delayms(20);
       MainLCD_WCom(0x51);     //display on
       Delayms(20);
}



void GxFillRect( RECT* rect, uint16 color)			
{          
     uint8 i,j;
	 uint8 x,y,w,h;
	 uint16* pScreenBuf = (uint16*)ScreenBuf;

	 x = rect->x;
	 y = rect->y;
	 w = rect->width;
	 h = rect->height;
     
     for(j=y;j<y+h;j++)
         for(i=x;i<x+w;i++)
			*(pScreenBuf+j*SCREEN_WIDTH+i) = color; 
			   //ER_DISPLAY_RefreshSurfaceNew( x,  y, w,  h ); 
	 RefreshCMC( rect );               
}

//Define Color
#define CLR_LIGHTGRAY	0xC618
#define CLR_WHITE		0xFFFF
#define CLR_BLACK		0x0000
#define CLR_BLUE		0x001F
#define CLR_RED			0xF800
#define CLR_GREEN		0x07E0
#define CLR_GRAY		0x8410
#define CLR_DARKGRAY            0x2110
#define CLR_CRAY		0x07ff
#define CLR_MAGENTA		0xf81f
#define CLR_LIGHTBLUE           0x421f
#define CLR_BG_HIGHLIGHT	0x001F
#define CLR_FG_HIGHLIGHT	0xFFFF



void MainLCD_Test( void )
{
	RECT rect = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
	RECT rect1 = { 0, 0, SCREEN_WIDTH, 20};

	unsigned short color = 0;

	InitCPU();
	StartCMC();

	GxFillRect( &rect,CLR_RED  );

    while(1)
	{
	   OSTimeDly(10);
   
	   GxFillRect( &rect1,color  );
	   rect1.y += 20;
	   color+= 0x1234;

	   if( rect1.y>=  (SCREEN_HEIGHT-20) )
	   rect1.y = 0;


	}


	//memset( &(ScreenBuf[0][0]), 0xf0, 2*SCREEN_WIDTH*SCREEN_HEIGHT );
	//RefreshCMC( &rect1 );	

	//memset( &(ScreenBuf[0][0]), 0xff, 2*SCREEN_WIDTH*SCREEN_HEIGHT );
	//RefreshCMC( &rect2 );	
}

⌨️ 快捷键说明

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