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

📄 glcd_i2c_batron.c

📁 this document is source code for arm9 of atmel
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------
            ATMEL Microcontroller Software Support  -  ROUSSET  -
-------------------------------------------------------------------------------
/ The software is delivered "AS IS" without warranty or condition of any
/ kind, either express, implied or statutory. This includes without
/ limitation any warranty or condition with respect to merchantability or
/ fitness for any particular purpose, or against the infringements of
/ intellectual property rights of others.
/-----------------------------------------------------------------------------
/ File Name           : glcd_i2c_batron.c
/ Object              : Graphic LCD routines for Chip-On-Glass LCD Module.
/                     :
/ Version | mm | dd | yy | author :
/   1.0     11   07   06    PFi   : Creation
/   1.1     11   04   07    PFi   : START / STOP bit clean up according to new
/                                   TWI doc.
/
/-----------------------------------------------------------------------------
 1)Description:

 The functions below show how to communicate with the 96 X 40 DOTS GLCD module,
 BT 96040AV-SRE-12-I2C-COG from BATRON is based on the Philips PCF8558 display
 controller.

 The registers of GLCD are write only.

 2)Configuration and pins used in this example:

 ------| AT91 / IO  | GLCD / IO
 CLOCK | TWCK / PA3 | SCL / 5
 DATA  | TWD / PA4  | SDA / 1

 3) Remarks:

 This example runs in polling mode and makes no use of IRQs. To have further
 details  and implementation example about using IRQs, refer to any Interrupt
 project examples, like AT91SAM7Sxx-Interrupt-IAR4_XX-X_X
 available on www.at91.com --> KIT --> AT91SAM7S-EK --> Software

-----------------------------------------------------------------------------*/
/* Include Standard LIB  files */
#include "project.h"
#include "..\common\lib_twi.h"
#include "glcd_i2c_batron.h"

extern void AT91F_Wait_MicroSecond (unsigned int MicroSecond);

#include "font\full_5_x_7_charset.h" /* This character set contains */
                                     /* standard and extended codes */


/*-----------------------------------------------------------------------------
 This Function writes one charactere in a lcd page (LcdPage) and at the specific
 column address (X_Address).
 This function uses the TWI in Master write mode with multiple data.
-----------------------------------------------------------------------------*/
void AT91F_Glcd_PutChar(unsigned char c,
                        unsigned char LcdPage,
                        unsigned char X_Address)
{
   int i;
   unsigned int status;

   /* Enable Master Mode of the TWI */
    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 command + the Page Address */
    AT91C_BASE_TWI->TWI_THR = Normal+LcdPage;

    /* Wait until TXRDY is high to transmit 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_Address;

   /* Send bit to display a character by using the charset table */
   for ( i=0; i<5; i++ )
   {
     /* 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 the data to turn on the right pixels to display the character */
     AT91C_BASE_TWI->TWI_THR = charset[(c-32)][i];
   }


   /* 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 writes a string in a lcd page at the specific column (X_Address)
 Max 19 characters per line/string.
 Do not use /r/n if sprintf function is used before calling AT91_Glcd_PutString
-----------------------------------------------------------------------------*/
void AT91F_Glcd_PutString(char *s,
                          unsigned char LcdPage,
                          unsigned char X_Address)
{
  while ( *s != 0 )
  {
     AT91F_Glcd_PutChar(*s++, LcdPage,X_Address);
     X_Address+=LCD_CHAR_WIDTH;
  }
}

/*-----------------------------------------------------------------------------
* This Function configure the video Mode the LCD.
* - Normal: Blank background and black characters.
* - Inverse : Blank characters black background.
-----------------------------------------------------------------------------*/
void AT91F_Glcd_VideoMode(char VideoMode)
{

  AT91F_TWI_WriteSingle(AT91C_GLCD_I2C_ADDRESS, &VideoMode);

}

/*-----------------------------------------------------------------------------
* This Function clears a column (X_ADDRES) in a LCD page.
* This function uses the TWI in Master write mode with one data.
-----------------------------------------------------------------------------*/
void AT91F_Glcd_ClearLcdColumn(unsigned char Column, unsigned char LcdPage)
{
    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 data */
    status = AT91C_BASE_TWI->TWI_SR;
    while (!(status & AT91C_TWI_TXRDY_MASTER))
      status = AT91C_BASE_TWI->TWI_SR;

    /* Send column address to access */
     AT91C_BASE_TWI->TWI_THR = Column;

    /* Wait for the Transmit ready is set to send the data */
    status = AT91C_BASE_TWI->TWI_SR;
    while (!(status & AT91C_TWI_TXRDY_MASTER))
      status = AT91C_BASE_TWI->TWI_SR;

    /* Send 0 to clear it */
    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 a char in a page @ location X.
* This function uses the TWI in Master write mode with multiple data.
-----------------------------------------------------------------------------*/
void AT91F_Glcd_ClearChar(unsigned char Column, unsigned char LcdPage)
{
    unsigned int status,i;

    /* 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 data */
    status = AT91C_BASE_TWI->TWI_SR;
    while (!(status & AT91C_TWI_TXRDY_MASTER))
      status = AT91C_BASE_TWI->TWI_SR;

    /* Send column address to access */
     AT91C_BASE_TWI->TWI_THR = Column;

    /* Wait for the Transmit ready is set to send the data */
    status = AT91C_BASE_TWI->TWI_SR;
    while (!(status & AT91C_TWI_TXRDY_MASTER))
      status = AT91C_BASE_TWI->TWI_SR;

    /* Send 0 to clear each lcd colum for a 5 x 7 char */
    for ( i=0; i<5; i++ )
    {
      /*  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 the data to turn on the right pixel to display the character */
      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 a LCD page by sending 0 to all pixels address.
-----------------------------------------------------------------------------*/
void AT91F_Glcd_ClearLcdPage(unsigned char LcdPage)

⌨️ 快捷键说明

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