亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? hal_lcd_srf04.c

?? cc2430最新的例子程序
?? C
字號:
/***********************************************************************************
    Filename:     hal_lcd.c

    Description:  Functions for accessing the LCD on SmartRF04EB (Varitronix COG-1626512C)

***********************************************************************************/

/***********************************************************************************
* INCLUDES
*/
#include "hal_board.h"
#include "hal_types.h"
#include "hal_defs.h"
#include "hal_lcd.h"
#include "hal_lcd_srf04.h"
#include "cc8051/hal_cc8051.h"
#include "util.h"

/***********************************************************************************
 * MACROS, CONSTANTS AND DEFINES
 */
#define DATA_HIGH()     MCU_IO_INPUT(1, 2, MCU_IO_PULLUP)
#define DATA_LOW()      MCU_IO_OUTPUT(1, 2, 0)

#define CLOCK_HIGH()    MCU_IO_INPUT(2, 0, MCU_IO_PULLUP)
#define CLOCK_LOW()     MCU_IO_OUTPUT(2, 0, 0)

#define LCD_SDA         P1_2
#define LCD_SCL         P2_0


/* SM-Bus address of the LCD controller */
#define LCD_ADDR        0x76

/* Internal addresses */
#define LINE1_ADDR      0x80    // Upper line of LCD
#define LINE2_ADDR      0xC0    // Lower line of LCD
#define CHAR1_ADDR      0x08    // First character

/*  RS selects the register to be accessed for read and write
    RS = 0 => selects instruction register for write and busy flag
    RS = 1 => selects the data register for both read and write */
#define REG_SEL_0       0x00
#define REG_SEL_1       0x40

// LCD lines
#define LCD_LINE_COUNT                  2
#define LCD_LINE_LENGTH                 16


/***********************************************************************************
 * LOCAL DATA
 */
static char pLcdLineBuffer[LCD_LINE_LENGTH];

/***********************************************************************************
 * LOCAL FUNCTIONS
 */

static void  smbStart(void);
static void  smbSend(const uint8* buffer, uint8 n);
static void  smbStop(void);
static void  smbClock(uint8 value);
static void  smbWrite(uint8 value);
static uint8 smbSendByte(uint8 b);

static char  lcdConvertChar(char c);
static void  lcdWait(void);



/***********************************************************************************
 * @fn          halLcdInit
 *
 * @brief       Initialize LCD
 *
 * @param       none
 *
 * @return      none
 */
void halLcdInit(void)
{
    uint8 sendBuffer[8];

    // Setting the ports as inputs.
    MCU_IO_INPUT(1, 2, MCU_IO_PULLUP);
    MCU_IO_INPUT(2, 0, MCU_IO_PULLUP);


    // Setting up the lcd initialisation data.
    sendBuffer[0] = LCD_ADDR;
    sendBuffer[1] = REG_SEL_0; // Instruction Register
    sendBuffer[2] = 0x0C;      // Display control         D =  1:      Display On
    //                                                    C =  0:      Cursor Off
    //                                                    B =  0:      Cursor character blink off
    sendBuffer[3] = 0x21;      // Function set            H =  1:      Use extended instruction set
    sendBuffer[4] = 0xA0;      // Set DDRAM address       ADD = 0x20
    sendBuffer[5] = 0x07;      // Display configuration   P =  1:      Column data right to left
    //                                                    Q =  1:      Row data, bottom to top
    sendBuffer[6] = 0x34;      // Function set            DL=  0:      4 bits
    //                                                    M =  1:      2-line by 16 display
    //                                                    SL=  0:      MUX1:18
    //                                                    H =  0:      Use basic instruction set
    sendBuffer[7] = 0x01;      // Clearing display
    smbSend(sendBuffer, 8);

    halLcdClear();
}


/***********************************************************************************
 * @fn          halLcdClear
 *
 * @brief       Clear all lines on LCD
 *
 * @param       none
 *
 * @return      none
 */
void halLcdClear(void)
{
    halLcdWriteLines(NULL, NULL, NULL);
}

/***********************************************************************************
 * @fn          halLcdGetLineLength
 *
 * @brief       Get max number of characters on each line
 *
 * @param       none
 *
 * @return      uint8 - number of characters on a line
 */
uint8 halLcdGetLineLength(void)
{
    return LCD_LINE_LENGTH;
}

/***********************************************************************************
 * @fn          halLcdGetNumLines
 *
 * @brief       Get the number of lines on the LCD.
 *
 * @param       none
 *
 * @return      uint8 - number of lines
 */
uint8 halLcdGetNumLines(void)
{
    return LCD_LINE_COUNT;
}


/***********************************************************************************
 * @fn          halLcdWriteChar
 *
 * @brief       Write a character on LCD.
 *
 * @param       line - line on display
 *              col - column
 *              char - character to display
 *
 * @return      none
 */
void halLcdWriteChar(uint8 line, uint8 col, char c)
{
    uint8 sendBuffer[3];
    uint8 i;

    if (col > HAL_LCD_LINE_SIZE) {
        col = HAL_LCD_LINE_SIZE - 1;
    }

    i = 0;
    sendBuffer[i++] = LCD_ADDR;
    sendBuffer[i++] = REG_SEL_0;
    sendBuffer[i++] = ((line == HAL_LCD_LINE_1) ?  LINE1_ADDR : LINE2_ADDR) + col;
    smbSend(sendBuffer, i);

    i = 0;
    sendBuffer[i++] = LCD_ADDR;
    sendBuffer[i++] = REG_SEL_1;
    sendBuffer[i++] = lcdConvertChar(c);
    smbSend(sendBuffer, i);
}


/***********************************************************************************
 * @fn          halLcdWriteLine
 *
 * @brief       Write line on LCD.
 *
 * @param       line - line on display
 *              text - text string
 *
 * @return      none
 */
void halLcdWriteLine(uint8 line, const char* text)
{
   BYTE sendBuffer[50];
   UINT8 i, j;
   char c;

    if (text == NULL)
        return;

   i = 0;
   sendBuffer[i++] = LCD_ADDR;
   sendBuffer[i++] = REG_SEL_0;
   sendBuffer[i++] = ((line == HAL_LCD_LINE_1) ?  LINE1_ADDR : LINE2_ADDR);
   smbSend(sendBuffer, i);

   i = j = 0;
   sendBuffer[i++] = LCD_ADDR;
   sendBuffer[i++] = REG_SEL_1;
   while( ( (c = text[j]) != '\0' ) && j < HAL_LCD_LINE_SIZE ){
      sendBuffer[i++] = lcdConvertChar(c);
      j++;
   }
   for ( ;j < HAL_LCD_LINE_SIZE; j++){
      sendBuffer[i++] = lcdConvertChar(' ');
   }
   smbSend(sendBuffer, i);
}


/***********************************************************************************
 * @fn          halLcdWriteLine
 *
 * @brief       Write all lines on LCD.
 *
 * @param       line1 - text string to display on line 1
 *              line2 - text string to display on line 2
 *              line3 - ignored for this display
 *
 * @return      none
 */
void halLcdWriteLines(const char* line1, const char* line2, const char* line3)
{
   halLcdWriteLine(HAL_LCD_LINE_1, line1);
   halLcdWriteLine(HAL_LCD_LINE_2, line2);
   return;
}


/***********************************************************************************
 * @fn          halLcdCreateSpecChar
 *
 * @brief       Create special character
 *
 * @param       uint8 index
 *              const char *p5x8Spec
 *
 * @return      none
 */
void halLcdCreateSpecChar(uint8 index, const char *p5x8Spec)
{
    uint8 sendBuffer[10];
    uint8 address = CHAR1_ADDR + (index * 0x08);

    //send control data
    sendBuffer[0] = LCD_ADDR;
    sendBuffer[1] = REG_SEL_0;

    if (address < 0x40)
        sendBuffer[2] = 0x80;
    else
        sendBuffer[2] = 0xC0;

    sendBuffer[3] = 0x40 | (address & 0x3F);
    smbSend(sendBuffer, 4);

    //send data
    sendBuffer[0] = LCD_ADDR;
    sendBuffer[1] = REG_SEL_1;

    sendBuffer[2] = p5x8Spec[0];
    sendBuffer[3] = p5x8Spec[1];
    sendBuffer[4] = p5x8Spec[2];
    sendBuffer[5] = p5x8Spec[3];
    sendBuffer[6] = p5x8Spec[4];
    sendBuffer[7] = p5x8Spec[5];
    sendBuffer[8] = p5x8Spec[6];
    sendBuffer[9] = p5x8Spec[7];

    smbSend(sendBuffer, 10);
}

/***********************************************************************************
 * @fn          halLcdWriteSpecChar
 *
 * @brief       Write special character on display
 *
 * @param       uint8 line
 *              uint8 col
 *              uint8 index
 *
 * @return      none
 */
void halLcdWriteSpecChar(uint8 line, uint8 col, uint8 index)
{
    halLcdWriteChar(line, col, index);
}


/***********************************************************************************
 * @fn          halLcdDisplayValue
 *
 * @brief       Display value on display with optional text on right and left side
 *
 * @param       uint8 line
 *              char *pLeft
 *              int32 value
 *              char *pRight
 *
 * @return      none
 */
void halLcdDisplayValue(uint8 line, char __xdata *pLeft, int32 value, char __xdata *pRight)
{
    uint8 n;
    char *pValue = convInt32ToText(value);
    for (n = 0; n < LCD_LINE_LENGTH; n++) {
        if (pLeft && *pLeft) {
            pLcdLineBuffer[n] = *(pLeft++);
        } else if (*pValue) {
            pLcdLineBuffer[n] = *(pValue++);
        } else if (pRight && *pRight) {
            pLcdLineBuffer[n] = *(pRight++);
        } else {
            pLcdLineBuffer[n] = ' ';
        }
    }
    halLcdWriteLine(line, pLcdLineBuffer);
}

/***********************************************************************************
* LOCAL FUNCTIONS
*/

/***********************************************************************************
 * @fn          smbSend
 *
 * @brief       Send n bytes over the SMB bus
 *
 * @param       BYTE *buffer
 *              const UINT8 n
 *
 * @return      none
 */
static void smbSend(const uint8 *buffer, uint8 n)
{
   UINT8 i = 0;

   smbStart();
   for(i = 0; i < n; i++){
      while(!smbSendByte(buffer[i])); //send until ACK received
   }
   smbStop();
}

/***********************************************************************************
 * @fn          smbStart
 *
 * @brief       This function initiates SMBus communication. It makes sure that 
 *              both the data and the clock of the SMBus are high. Then the data 
 *              pin is set low while the clock is kept high. This initializes 
 *              SMBus transfer.
 *
 * @param       none
 *
 * @return      none
 */
static void smbStart(void)
{
   while (! (LCD_SDA && LCD_SCL) ); //wait for Data and clk high
   DATA_LOW();
   lcdWait();
   smbClock(0);
}


/***********************************************************************************
 * @fn          smbStop
 *
 * @brief       This function terminates SMBus communication. It makes sure that the 
 *              data and clock of the SMBus are low and high, respectively. Then 
 *              the data pin is set high while the clock is kept high. This 
 *              terminates SMBus transfer.
 *
 * @param       none
 *
 * @return      none
 */
static void smbStop(void)
{
   while (! (!LCD_SDA && LCD_SCL));
   smbClock(0);
   DATA_HIGH();
   lcdWait();
   smbClock(1);
}

/***********************************************************************************
 * @fn          smbStop
 *
 * @brief       This function is used to clock the SMBus connected to the LCD. 
 *              If a negative edge is to follow, the pin is set as an output and 
 *              driven low. If a positive edge is to follow, the pin is set as an 
 *              input and the pull-up resistor is to drive the node high. This way 
 *              the slave device can hold the node low if a longer setup time is 
 *              desired.
 *
 * @param       uint8 value
 *
 * @return      none
 */
static void smbClock(uint8 value)
{
   if(!value)
   {
      CLOCK_LOW();
   }
   else {
      CLOCK_HIGH();
   }
   lcdWait();
}

/***********************************************************************************
 * @fn          smbStop
 *
 * @brief       Function for writing bit to the data line. Setting the port as input
 *              make the SMBus go high because of the pull-up resistors.
 *
 * @param       uint8 value
 *
 * @return      none
 */
static void smbWrite(uint8 value)
{
   smbClock(0);
   lcdWait();
   if(value){
      DATA_HIGH();
   }
   else{
      DATA_LOW();
   }
   smbClock(1);
   lcdWait();
}

/***********************************************************************************
 * @fn          smbSendByte
 *
 * @brief       Sends the byte b over the smb bus. Returns 1 if the byte was sent
 *              successfully.
 *
 * @param       uint8 b
 *
 * @return      none
 */
static uint8 smbSendByte(uint8 b)
{
   uint8 i;
   uint8 ack;
   for (i = 0; i < 8; i++){
      smbWrite(b & 0x80);
      b = (b <<  1);
   }
   smbClock(0);
   DATA_HIGH();
   smbClock(1);
   ack = !LCD_SDA;
   return ack; //high = ACK received, else ACK not received
}

/***********************************************************************************
 * @fn          lcdConvertChar
 *
 * @brief       Converts ASCII characters to the character set the LCD display uses
 *              (works for all digits and letters and some other common characters)
 *
 * @param       char c
 *
 * @return      none
 */
static char lcdConvertChar(char c)
{
   //character set R in data sheet
   if ((c >= 'a') && (c <= 'z')) //lower case
      c += ('a' - 0xE1);//0x80;
   else if ((c >= 'A') && (c <= 'Z')) //upper case
      c+= ('A' - 0xC1);
   else if ((c >= ' ') && (c <= '#') || (c >= '%') && (c <= '?'))
      c += (' ' - 0xA0);
   else{
      switch (c){
      case '$':
         c = 0x82;
         break;
      case '

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
av在线不卡免费看| 久久国产福利国产秒拍| 久久久久久久性| 亚洲精品在线电影| 久久精品人人做| 国产精品久久久一区麻豆最新章节| 精品国产乱码久久久久久浪潮| 日韩免费高清av| 久久久久久久久久久黄色| 久久久国产精品午夜一区ai换脸| 精品欧美久久久| 中文字幕亚洲一区二区av在线 | 香港成人在线视频| 香蕉影视欧美成人| 国产高清不卡二三区| 99精品欧美一区二区三区综合在线| 不卡高清视频专区| 欧美精品vⅰdeose4hd| 久久综合狠狠综合久久激情 | 成人免费不卡视频| 欧美色网一区二区| 亚洲国产高清在线观看视频| 亚洲精品一二三区| 国产麻豆一精品一av一免费| aaa欧美大片| 精品国产乱码久久久久久图片 | 91成人在线精品| 精品久久久久久久久久久久久久久 | 亚洲日本在线天堂| 激情都市一区二区| 91精品国产一区二区人妖| 1024成人网色www| 国产福利精品一区| 日韩精品一区二区三区四区| 亚洲综合一区二区三区| 成人午夜精品在线| 久久精品欧美一区二区三区不卡| 性做久久久久久免费观看| 99久久精品国产一区| 国产午夜亚洲精品午夜鲁丝片| 婷婷国产v国产偷v亚洲高清| 在线看国产一区二区| 欧美一区二区免费| 99re热这里只有精品视频| 欧美日韩精品一区二区三区四区| 伊人婷婷欧美激情| 在线一区二区观看| 一区二区三区中文字幕精品精品| 91免费观看在线| 综合av第一页| 国产又黄又大久久| 国产欧美一区二区三区在线老狼 | 不卡视频一二三| 日韩理论电影院| 欧美日韩精品电影| 另类人妖一区二区av| 国产亚洲制服色| 一本大道久久a久久综合| 亚洲sss视频在线视频| 日韩欧美一区中文| jizz一区二区| 婷婷综合另类小说色区| 久久综合久久综合亚洲| 成人av在线资源网| 日本伊人色综合网| 国产精品美日韩| 欧美福利电影网| 成人久久视频在线观看| 午夜精品福利久久久| 久久嫩草精品久久久精品| 欧美色综合网站| 9l国产精品久久久久麻豆| 日本vs亚洲vs韩国一区三区 | 在线免费观看视频一区| 成人av动漫在线| 欧美精品第1页| 亚洲综合成人在线视频| 欧美色区777第一页| 亚洲韩国一区二区三区| 国产精品免费久久| 中文字幕第一区二区| 久久久天堂av| 日韩精品一区国产麻豆| 欧美日韩精品一区二区在线播放| 91亚洲精品一区二区乱码| 国产不卡视频一区| 成人午夜视频在线观看| 国产精品亚洲人在线观看| 韩国精品免费视频| 国产自产高清不卡| 国产很黄免费观看久久| 国产精品一区专区| 高清国产一区二区| 91在线观看美女| 日本乱人伦aⅴ精品| 欧美日韩情趣电影| 日韩欧美一区在线观看| 日韩欧美三级在线| 欧美—级在线免费片| 中文字幕字幕中文在线中不卡视频| 国产精品欧美极品| 亚洲精品五月天| 蜜桃视频一区二区| 成人一区二区三区视频在线观看| 成人国产电影网| 欧美一区二区三区免费在线看| 精品久久国产字幕高潮| 久久久精品蜜桃| 亚洲激情男女视频| 国内外成人在线视频| 在线观看欧美精品| 国产日韩精品视频一区| 亚洲福利视频三区| 国产98色在线|日韩| 在线不卡一区二区| 亚洲男同性视频| 处破女av一区二区| 欧美tk丨vk视频| 亚洲一区国产视频| 一本大道综合伊人精品热热| 日韩精品一区二区三区视频| 有码一区二区三区| 91在线视频网址| 亚洲国产精品精华液2区45| 狂野欧美性猛交blacked| 91久久一区二区| 亚洲色图欧美在线| 成人高清免费观看| 国产日韩欧美在线一区| 国内精品在线播放| 欧美成人bangbros| 老汉av免费一区二区三区| 欧美一级黄色大片| 奇米影视一区二区三区| 欧美美女bb生活片| 日韩精品电影一区亚洲| 欧美电影在哪看比较好| 轻轻草成人在线| 久久久久99精品一区| 国产宾馆实践打屁股91| 亚洲欧洲成人av每日更新| 成人91在线观看| 成人欧美一区二区三区在线播放| 成人久久久精品乱码一区二区三区| 国产欧美精品国产国产专区 | 日韩欧美一级在线播放| 看电视剧不卡顿的网站| 亚洲国产精品黑人久久久 | 久久久久久久久99精品| av电影在线观看不卡| 亚洲一级电影视频| 国产无一区二区| 欧美影院精品一区| 国产高清久久久| 日韩高清欧美激情| 欧美激情一二三区| 欧美一级理论性理论a| 99久久精品国产麻豆演员表| 亚洲国产视频在线| 中文字幕不卡在线观看| 欧美一三区三区四区免费在线看| 国产成人亚洲综合a∨婷婷图片| 有码一区二区三区| 18成人在线视频| 久久青草欧美一区二区三区| 在线看日本不卡| 色综合视频在线观看| 国产高清不卡一区| 国产精品一区在线观看乱码 | 精品欧美久久久| 91精品午夜视频| 欧美一级在线观看| 在线成人午夜影院| 91精品婷婷国产综合久久性色| 91美女视频网站| 91原创在线视频| av激情亚洲男人天堂| 国产成人av一区二区| 国产成人一区二区精品非洲| 丰满亚洲少妇av| av不卡免费电影| 欧美日韩三级一区| 欧美精品色一区二区三区| 欧美日韩日本视频| 日韩视频一区二区在线观看| 91精品国产欧美一区二区成人| 欧美日韩精品欧美日韩精品一综合 | jvid福利写真一区二区三区| 99国产精品久| 欧美性色欧美a在线播放| 91精品久久久久久蜜臀| 日韩一区二区三区四区| 久久久www成人免费无遮挡大片| 国产精品婷婷午夜在线观看| 久久女同精品一区二区| 悠悠色在线精品| 国产一区二区三区免费| 91高清视频免费看| 欧美大片在线观看一区| 自拍偷在线精品自拍偷无码专区|