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

📄 iccontrol.c

📁 T108 LCD屏的DEMO源代码!需要的就下吧
💻 C
字号:
/*##########################################################################
#                      Terawins Inc. Company                               #
#                 Copyright (c) 2005, All rights reserved                  #
#                                                                          #
#  All rights reserved. Reproduction in whole or in parts is prohibited    #
#  without the prior written consent.                                      #
##########################################################################*/
   
///////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                          LCD Application Firmware                          //
// ========================================================================== //
//                                                                            //
//  Module   : ICControl                                                      //
//                                                                            //
//  Purpose  : IC control functions		                                      //
//                                                                            //
//  Version  : 1.00                                                           //
//                                                                            //
//  Compiler : Keil 8051 C Compiler v7.5                                      //
//                                                                            //
//  Reference: [1] Keil C51 Compiler User's Guide 09.2001, Keil Software, Inc.//
//                                                                            //
// ========================================================================== //
//                                                                            //
//  Date        Author        Reason (what and why)                           //
//  ----------- ------------- ----------------------------------------------  //
//  2005/12/30  Kevin Hsu				                                      //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
#include "Common.h"
#include "Global.h"
#include "ICControl.h"
#include "TWICreg.h"
#include "OSD1_Define.h"
#include "OSD2_Define.h"
#include "I2c.h"
#define BASEADDRESS 0x0000

		  
void IC_WritByte(uWORD bPage, uCHAR bAdd, uCHAR bData)
{
    /* start condition */
    StartCondition();
    bPage &= 0xFE;   // Force WRITE address
    /* send device ID and write data */
    if(!Send_Byte(bPage))
    {
        if(!Send_Byte(bAdd))
        {
            if(!Send_Byte(bData))
            {
                StopCondition();
                //return(0);      /* success */
            }
        }
    }
    StopCondition();
    //return(1);		

}

uCHAR IC_ReadByte(uWORD bPage, uCHAR bAdd)
{
    uCHAR cResult = 0;		

    /* write reg offset */
    StartCondition();
    if(Send_Byte(bPage))
	return 0;  // Write address
    if(Send_Byte(bAdd))
	return 0;

    /* read data */
    StartCondition();
    if (Send_Byte(bPage | 0x01)) // Read address
	return 0;
    cResult = Read_Byte(1);

    StopCondition();
    return cResult;
}

void twdDelay(uWORD wLoops)
{
	uWORD wTemp;  
    while (wLoops--) {
	    wTemp = 20;	// one loop below takes about 11 us
        while (wTemp--)
		{
			wTemp=wTemp;
		}
    }

}

/*   C L O S E   P A N E L   */
/*-------------------------------------------------------------------------
   ignore and block the input vsync triggering the output vsync ,
   display user define color in panel
-------------------------------------------------------------------------*/
void ClosePanel(uCHAR uR, uCHAR uG, uCHAR uB)
{
	//IC_WritByte(TWIC_P1, 0xB8, IC_ReadByte(TWIC_P1,0xB8)&0x7F);

	IC_WritByte(TWIC_P0, 0xC2, IC_ReadByte(TWIC_P0, 0xC2)|(PSYNC_STR|IGNORE_VSYNC));
	IC_WritByte(TWIC_P0, 0x9d, uR);
	IC_WritByte(TWIC_P0, 0x9e, uG);
	IC_WritByte(TWIC_P0, 0x9f, uB);
	IC_WritByte(TWIC_P0, PATTERN_CTRL, 0x87);//enable frame background color 
	IC_WritByte(TWIC_P0, 0xe2, 0x11);   //enable registers shadow control,sync all shadow registers
	m_bPanelClose=1;
	
}

void OpenPanel(void)
{	
		   
	IC_WritByte(TWIC_P0, 0xC2, IC_ReadByte(TWIC_P0, 0xC2)&~(PSYNC_STR|IGNORE_VSYNC));
	//IC_WritByte(TWIC_P1, 0xB8, IC_ReadByte(TWIC_P1,0xB8)|0x80);
	IC_WritByte(TWIC_P0, PATTERN_CTRL, IC_ReadByte(TWIC_P0, PATTERN_CTRL)&~0x80); //Enable Frame Background Color
	IC_WritByte(TWIC_P0, 0xe2, 0x11);   //enable registers shadow control,sync all shadow registers
	m_bPanelClose=0;

}
//~ OSD1 Config Register Setting ~//
void OSD1CfgWr(uCHAR index,uCHAR dat)
{
	IC_WritByte(TWIC_P0,OSD1_CFG_INDEX,index);
	IC_WritByte(TWIC_P0,OSD1_CFG_DATA,dat);
}
//~ OSD1 Target OSD Ram Setting.  ~//
void OSD1SetRamAddr(uWORD address)
{
	
  	IC_WritByte(TWIC_P0,OSD1_RAM_AL,(uCHAR)(address & 0xff));  
	IC_WritByte(TWIC_P0,OSD1_RAM_AH,(uCHAR)(address>>8));
}
void OSD1SetRamData(uWORD wdata)
{
	IC_WritByte(TWIC_P0,OSD_RAM_DL,(uCHAR)(wdata & 0xff));
  	IC_WritByte(TWIC_P0,OSD_RAM_DH,(uCHAR)(wdata>>8));
} 


// OSD2 config register Write
void OSD2CfgWr(uCHAR index,uCHAR dat)
{
	IC_WritByte(TWIC_P0,OSD2_CFG_INDEX,index);
	IC_WritByte(TWIC_P0,OSD2_CFG_DATA,dat);
}
//~ OSD2 Target OSD Ram Setting.  ~//
void OSD2SetRamAddr(uWORD address)
{
	IC_WritByte(TWIC_P0,OSD2_RAM_AL,(uCHAR)(address & 0xff));
  	IC_WritByte(TWIC_P0,OSD2_RAM_AH,(uCHAR)(address>>8));

}
void OSD2SetRamData(uWORD wdata)
{
	IC_WritByte(TWIC_P0,OSD2_RAM_DL,(uCHAR)(wdata & 0xff));		
  	IC_WritByte(TWIC_P0,OSD2_RAM_DH,(uCHAR)(wdata>>8));
	
}
			  
//--------------------------------------------------
// 041901, Added for TWD Burst Write
// 1. PT8655X_Wr_Burst_A    (Start + Slave_ID + Address)
// 2. PT8655X_Wr_Burst_D    (Data)
// 3. PT8655X_Wr_Burst_P    (stop)
//--------------------------------------------------
uCHAR ICWr_Burst_A(uCHAR cReg)
{
    StartCondition();
    if(!Send_Byte(TWIC_P0))
    {
        if(!Send_Byte(cReg))
        {
            return(0);               
        }
    }
    return(1);                  
}


void ICWr_Burst_D(uCHAR cData)
{
    uCHAR ix;

    for(ix = 0; ix < 8; ix++)
    {
        Set_SCL2Low;
        if(cData&0x80)Set_SDA2High;
		else Set_SDA2Low;
		cData<<=1;
        Set_SCL2High;
    }
    Set_SCL2Low;
    Set_SDA2High;                /* release data line for acknowledge */
    Set_SCL2High;                /* Send a clock for Acknowledge */
    Set_SCL2Low;                   /* Finish Acknoledge */
}


void ICWr_Burst_P(void)
{
    StopCondition();
}
void OSDSetRamDataBuest(uWORD wdata)
{
	ICWr_Burst_D((uCHAR)(wdata & 0xff));
	ICWr_Burst_D((uCHAR)(wdata>>8));		 	
}

⌨️ 快捷键说明

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