?? glcd_i2c_batron.c
字號:
{
int Pixel;
unsigned int status;
/* Enable Master Mode */
AT91C_BASE_TWI->TWI_CR = AT91C_TWI_MSEN|AT91C_TWI_SVDIS ;
/* Set the TWI Master Mode Register */
AT91C_BASE_TWI->TWI_MMR = AT91C_GLCD_I2C_ADDRESS & ~AT91C_TWI_MREAD;
/* Send the LCD mode and the page to address */
AT91C_BASE_TWI->TWI_THR = Normal+LcdPage;
/* Wait for the Transmit ready is set to send the next data */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXRDY_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
/* Send X address (column address) */
AT91C_BASE_TWI->TWI_THR = X_START;
for ( Pixel=X_START; Pixel<X_END; Pixel++ )
{
/* Wait for the Transmit ready is set to send the next data */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXRDY_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
/* Send 0 to all pixel to turn them off */
AT91C_BASE_TWI->TWI_THR = 0x0;
}
/* Wait for the Transmit complete is set */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXCOMP_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
}
/*-----------------------------------------------------------------------------
* This Function clears the whole LCD by sending 0 to all pixels address.
* It does not need to increment the page address. just send 0's.
-----------------------------------------------------------------------------*/
void AT91F_Glcd_ClearLcd(void)
{
int Page=0,Pixel;
unsigned int status;
/* Enable Master Mode */
AT91C_BASE_TWI->TWI_CR = AT91C_TWI_MSEN|AT91C_TWI_SVDIS ;
/* Set the TWI Master Mode Register */
AT91C_BASE_TWI->TWI_MMR = AT91C_GLCD_I2C_ADDRESS & ~AT91C_TWI_MREAD;
/* Send the LCD mode and the page to address */
AT91C_BASE_TWI->TWI_THR = Normal+Page;
/* Wait for the Transmit ready is set to send the next data */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXRDY_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
/* Send X address (column address) */
AT91C_BASE_TWI->TWI_THR = X_START;
for( Pixel=0; Pixel<96*40; Pixel++ )
{
/* Wait for the Transmit ready is set to send the next data */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXRDY_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
/* Send 0 to all pixel to turn them off */
AT91C_BASE_TWI->TWI_THR = 0x0;
}
/* Wait for the Transmit complete is set */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXCOMP_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
}
/*-----------------------------------------------------------------------------
* This Function displays an image (BMP 1bpp) on the LCD.
-----------------------------------------------------------------------------*/
void AT91F_Glcd_DisplayBitmap(unsigned char *Image,
unsigned int X_Location,
unsigned int LcdPageStart,
unsigned int X_Size,
unsigned int Y_Size)
{
unsigned int LcdPage, PixelIndex, LcdColumIndex;
unsigned int NumOfPage=0;
unsigned int status;
PixelIndex = 0 ;
if ( (LcdPage = Y_Size % LCD_PAGE_HEIGHT) == 0 )
NumOfPage = 5;
else
NumOfPage= Y_Size % LCD_PAGE_HEIGHT ;
for ( LcdPage= LcdPageStart; LcdPage < NumOfPage; LcdPage++ )
{
/* Enable Master Mode */
AT91C_BASE_TWI->TWI_CR = AT91C_TWI_MSEN|AT91C_TWI_SVDIS ;
/* Set the TWI Master Mode Register */
AT91C_BASE_TWI->TWI_MMR = AT91C_GLCD_I2C_ADDRESS & ~AT91C_TWI_MREAD;
/* Send the LCD mode and the page to address */
AT91C_BASE_TWI->TWI_THR = Normal+LcdPage;
/* Wait for the Transmit ready is set to send the next data */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXRDY_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
/* Send X address (column address) */
AT91C_BASE_TWI->TWI_THR = X_START+X_Location;
for ( LcdColumIndex = X_Location;
(LcdColumIndex < X_Size)&&(PixelIndex < ((X_Size*Y_Size)/8));
LcdColumIndex++ )
{
/* Wait for the Transmit ready is set to send the next data */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXRDY_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
/* Send pixel */
AT91C_BASE_TWI->TWI_THR = Image[PixelIndex];
PixelIndex++;
}
/* Wait for the Transmit complete is set */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXCOMP_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
}
/* Wait for the Transmit complete is set */
status = AT91C_BASE_TWI->TWI_SR;
while (!(status & AT91C_TWI_TXCOMP_MASTER))
status = AT91C_BASE_TWI->TWI_SR;
}
/*-----------------------------------------------------------------------------
Function: AT91F_Glcd_Reset(void)
Arguments:
- <const AT91PS_PIO pPio> : Pointer to a PIO structure,
- <int PioID> : PIO peripheral ID
- <int Twck> : PIO/TWI clock pin
- <int Twd> : PIO/TWI data pin
Comments:
This function sends a "bus recovery" sequence" compatible with I2C(tm)
MEMORY RESET: After an interruption in protocol, power loss or system reset,
any two-wire part can be reset by following these steps:
1. Clock up to 9 cycles.
2. Send a stop condition.
Return Value: None
-----------------------------------------------------------------------------*/
void AT91F_Glcd_Reset (const AT91PS_PIO pPio,
int PioID,
int Twck,
int Twd)
{
unsigned int ClockPulse;
/* First, enable the clock of the PIO */
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
/* Set the TWI pins controlled by the PIO */
AT91F_PIO_Enable(pPio,Twck|Twd ) ;
/* then, we configure the PIO Lines corresponding to TWD & TWCK
to be outputs. */
AT91F_PIO_CfgOutput (pPio, Twck|Twd ) ;
/* Enable open drain on TWCK / TWD PIO lines */
pPio->PIO_MDER = (Twck|Twd) ;
/* Disable the pull up on the TWI line */
pPio->PIO_PPUDR = (Twck|Twd) ;
/* Set TWCK and TWD to high level */
AT91F_PIO_SetOutput(pPio, Twck|Twd ) ;
AT91F_Wait_MicroSecond(2);
/* Perform the bus recovery sequence */
/* Clock up to nine cycles */
for (ClockPulse=0 ; ClockPulse < 9 ; ClockPulse++)
{
/* Toggle the clock */
AT91F_PIO_SetOutput(pPio, Twck );
AT91F_Wait_MicroSecond(2);
AT91F_PIO_ClearOutput(pPio, Twck );
AT91F_Wait_MicroSecond(2);
}
/* Send a stop condition */
AT91F_PIO_ClearOutput(pPio, Twck );
AT91F_Wait_MicroSecond(2);
AT91F_PIO_ClearOutput(pPio, Twd );
AT91F_Wait_MicroSecond(2);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -