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

📄 driver.c

📁 it is a sample code for s3c2410 board.
💻 C
📖 第 1 页 / 共 2 页
字号:
	IICPS = 63;				//MCLK / (16X(IICPS+1)-3) = 50K
}


void IICWriteRTC(U8 Addr, U8 Data)
{
		U8 SlaveAddr=(0x51<<1);
	
		IICSetup();

		while(IICCON & BUSY);
		IICCON = START|BF;

		while(!(IICCON & BF));
		IICBUF = SlaveAddr|S_WRITE;
		
		WAIT_I2C

		while(!(IICCON & BF));
		IICBUF = Addr;

		WAIT_I2C
		
		while(!(IICCON & BF));
		IICBUF = Data;
	
		WAIT_I2C
	
		IICCON = STOP;
}


U8 IICReadRTC(U8 Addr)
{
		U8 SlaveAddr=(0x51<<1);
		U8 temp;

		IICSetup();

		while(IICCON & BUSY);
		IICCON = START|BF;

		while(!(IICCON & BF));
		IICBUF = SlaveAddr|S_WRITE;

		WAIT_I2C

		while(!(IICCON & BF));
		IICBUF = Addr;

		WAIT_I2C

		while(!(IICCON & BF));
		IICCON = (RESTART|ACK|BF);

		while(!(IICCON & BF));
		IICCON = (START|ACK|BF);

		while(!(IICCON & BF));
		IICBUF = SlaveAddr|S_READ;

		WAIT_I2C

		while(!(IICCON & BF));
		IICCON &= 0xfe;
	
		while(!(IICCON & BF));

		temp = IICBUF;
		IICCON &= 0xf6;
	
		while(!(IICCON & BF));
		IICCON = STOP;
		return(temp);
}


void IICWriteAIC(U8 Addr, U8 Data)
{
		U8 SlaveAddr=0x80;
	
		IICSetup();

		while(IICCON & BUSY);
		IICCON = START|BF;

		while(!(IICCON & BF));
		IICBUF = SlaveAddr|S_WRITE;

		WAIT_I2C

		while(!(IICCON & BF));
		IICBUF = Addr;

		WAIT_I2C

		while(!(IICCON & BF));
		IICBUF = Data;

		WAIT_I2C

		IICCON = STOP;
}


U8 IICReadAIC(U8 Addr)
{
		U8 temp=0;

		if(0) {	//Bug to be fixed
		
		U8 SlaveAddr=0x80;
		
		IICSetup();

		while(IICCON & BUSY);
		IICCON = START|BF;

		while(!(IICCON & BF));
		IICBUF = SlaveAddr|S_WRITE;

		WAIT_I2C

		while(!(IICCON & BF));
		IICBUF = Addr;
		
		WAIT_I2C

		while(!(IICCON & BF));
		IICCON = STOP;

		while(!(IICCON & BUSY));
		IICCON = (START|ACK|BF);

		while(!(IICCON & BF));
		IICBUF = SlaveAddr|S_READ;

		WAIT_I2C

		while(!(IICCON & BF));
		IICCON &= 0xfe;
	
		while(!(IICCON & BF));

		temp = IICBUF;
		IICCON &= 0xf6;
	
		while(!(IICCON & BF));
		IICCON = STOP;
		}
		return(temp);
}


/*************************************************************************
LCD
*************************************************************************/
void
Initial_LCD (void)
{
        byFontHeight = 8;
        byFontWidth = 8;
        ScrWidth = 128 / byFontWidth;
        ScrHeight = 128 / byFontHeight;
        InitialLCD();
        //LCD_ClearScreen();
        LCD_CursorMode(BLACK_BLINK_CURSOR);
        LCD_EnableCursor(UM);
}



UI
ConvertByteToCCDPattern (UC data)
{
        return ((ConvertData[data>>4] << 8) + ConvertData[data&0xf]);
}


/* ------------------ clear screen area ------------------------------- */
void
LCD_ClearScreen (void)
{
        LCD_ClearViewArea();
        Xpos = Ypos = YScrollOffset = 0;
        WriteLCD(LCD_VET_SCROLL, 0);
	    LCD_Cursor(Xpos, Ypos);		
}



/* ------------------ clear one line ---------------------------------- */
void
LCD_ClearOneLine (int y)
{
        int             x;

        for (x=0; x < ScrWidth; x++)
            LCD_displ(x, y, ' ');
        Xpos = 0;
}



/* ------------------ printf  ----------------------------------------- */
void
LCD_printf (char *fmt,...)
{
        va_list     ap;
        char        string[512], *p=string;

        va_start(ap, fmt);
        vsprintf(string, fmt, ap);
        va_end(ap);
        while (*p)
            LCD_putchar(*p++);
}


/* ------------------ write a character to screen --------------------- */
void
LCD_putchar (char c)
{
        switch (c){
        case '\n' :
            if (Ypos == (ScrHeight-1))
                LCD_scroll();
            else
                Ypos++;
            Xpos = 0;
            break ;
        case '\t' :
            do LCD_putchar(' ');
            while (Xpos%TABS);
            break ;
        default :
            if ((Xpos+1) >= ScrWidth){
                LCD_putchar('\n');
            }
            LCD_displ(Xpos++, Ypos, c);
            break ;
        }
        if (byCursorOn)
            LCD_Cursor(Xpos, Ypos);
}


/* ------------------ scroll contents up or down ---------------------- */
void
LCD_scroll (void)
{
        if (YScrollOffset == 0)
            YScrollOffset = ScrHeight - 1;
        else
            YScrollOffset--;

        WriteLCD(LCD_VET_SCROLL, byFontHeight * (Ypos - YScrollOffset + 1));
        LCD_ClearOneLine(Ypos);
}



/* ------------------ display a character to screen ------------------- */
void
LCD_displ (int x, int y, int ch)
{
        unsigned short  addr, data ;
        int             i, YRelation;

        data = (ch >= 0x20 && ch <= 0x7e) ? ch : ' ';
        YRelation = y - YScrollOffset;
        addr = x + (YRelation * 0x80);

        for (i=0; i < byFontWidth; i++){
            LCD_PutRAMData(addr, charset[data][i]);
            addr += 0x10;
        }
}


/* ------------------ Set  Cursor mode ------------------------------- */
void
LCD_CursorMode (unsigned char Mode)
{
        byCursorMode = Mode & 0x3;
}



/* ------------------ Enable Cursor on/off----------------------------- */
void LCD_EnableCursor (int bCursorOn)
{
        unsigned short  data;

        byCursorOn = bCursorOn;
        if (byCursorOn)
            data = byCursorMode | 0x04;
        else
            data = 0;
        WriteLCD(LCD_CURSOR, data);
}



/* ------------------ set cursor -------------------------------------- */
void LCD_Cursor(int x, int y)
{
        unsigned short  HS, HE, VS;

        HS = x * byFontWidth;
        HE = HS + (byFontWidth - 1);
        WriteLCD(LCD_HOR_CURSOR_POS, (HE << 8) + HS);

        VS = (y + 1) * byFontHeight - 2;
        //VE = VS + (byFontHeight - 1);
        WriteLCD(LCD_VER_CURSOR_POS, ((VS+1)<<8) + VS);
        
        Xpos = x; Ypos = y;
}


void 
InitialLCD (void)
{
	int 	i;
	
	// The eight upper and lower bits can be corrected by a reset triggered by
	// consecutively writing a 00H instruction four times.
	//		
	for (i=0; i < 4; i++){
            LCD_CMD = 0;
            OptimizationDelay();
        }
		
	//The start oscillation instruction restarts the oscillator from the halt state in the standby mode. After issuing
	//this instruction, wait at least 10 ms for oscillation to stabilize before issuing the next instruction	
	//
	WriteLCD(LCD_START_OSC, 1);
	Delay(15);
	
	WriteLCD(LCD_DRV_OUT, 0x030f);		// 128 * 128 ; Inervt Comm&Segment
	WriteLCD(LCD_WAVEFORM, 0);
	WriteLCD(LCD_PWR_CONTROL, 0x23c);	// 0x033c
	WriteLCD(LCD_CONTRAST, 0x18);
	WriteLCD(LCD_ENTRY_MODE, 0x10);
	WriteLCD(LCD_ROTATION, 0);
	
	WriteLCD(LCD_CURSOR, 4);
	WriteLCD(LCD_DB_HEIGHT, 0);
	WriteLCD(LCD_VET_SCROLL, 0);
	WriteLCD(LCD_HOR_CURSOR_POS, 0);
	WriteLCD(LCD_RAM_MASK, 0);
	WriteLCD(LCD_RAM_ADDR, 0);	
	WriteLCD(LCD_DISPLAY, 1);
	LCD_ClearScreen();	
}


void 
LCD_ClearViewArea (void)
{
	int	i;
	
	SET_ADDRESS_LCD(0);
	
	for (i=0; i < 0x800; i++)
	    SET_RAM_DATA_LCD(0);
	WriteLCD(LCD_VET_SCROLL, 0);		
}


void DrawImage (UI *pImageBuffer)
{
	int	i;
	
	SET_ADDRESS_LCD(0);
	
	for (i=0; i < 0x800; i++)
	    SET_RAM_DATA_LCD(pImageBuffer[i]);
}


void LCD_PutRAMData (UI address, UI data)
{
	SET_ADDRESS_LCD(address);
	SET_RAM_DATA_LCD(data);
}


UI LCD_GetRAMData (UI address)
{
	SET_ADDRESS_LCD(address);
	return(ReadLCD(LCD_RAM_DATA));
}


UI 
ReadLCD (UI addr)
{
	UI data;

	LCD_CMD = 0xff;	//MSB
	OptimizationDelay();	// for Optimization	
	LCD_CMD = addr;	//LSB
	data = LCD_DATA << 8;
	data |= LCD_DATA;

	if (addr == LCD_RAM_DATA) {
	    LCD_CMD = 0xff;	//MSB
    	OptimizationDelay();	// for Optimization	    
	    LCD_CMD = addr;	//LSB
	    data = LCD_DATA << 8;
	    data |= LCD_DATA;
	}
	return (data);
}


void 
WriteLCD (UI addr, UI data)
{
	LCD_CMD = 0xff;	//MSB
	OptimizationDelay();	// for Optimization	
	LCD_CMD = addr;	//LSB
		
	LCD_DATA = (data >> 8) ;
	OptimizationDelay();	// for Optimization	
	LCD_DATA = data;
}

⌨️ 快捷键说明

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