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

📄 lcd1602_control.h

📁 LCD_BUS4 lcd1602四线传输
💻 H
字号:
/*
 * file:lcd1602_control.h
 * Author:Nicholas Tian		Modified by huangzongchao at 2012/07/21
 * description:
 * 				1.this file contains lcd1602 control functions,to use this file ,you should have the file "data.h" and "lcd1602_4.h"
 * 				2.with this file in you program, you can control lcd1602 fluency,just use "initLCD()" before "onLCD(0,0,""Hello world!)"
 * 				3.How to connect you ms9430g2553 to your LCD1602:P1.3-----RS
 * 																 P1.4-----RW
 * 																 P1.5-----EN
 * 																 P2.4-----D4
 * 																 P2.5-----D5
 * 																 P2.6-----D6
 * 																 P2.7-----D7
 *
 *
 */
#include "data.h"
#include "lcd1602_4.h"
void hzc_delay(unsigned int kcycle)
{
	int i;
	for(i=kcycle;i>0;i--)
	{
		__delay_cycles(1000);
	}
}
/*
void delayTA(unsigned int timeMS)
{
    _EINT();      // Enable interrupts.
    TA1CCR0 = 1000 * timeMS;    // Delay
    TA1CCTL0 |= CCIE;           // Compare-mode interrupt.
    TA1CTL = TASSEL_2 | MC_1;   // TACLK = SMCLK, Up mode.
    LPM0;                      // Wait for delay.
    TA1CCTL0 &= ~CCIE;          // Disable timer Interrupt
}*/
void lcdBusy(void)
{
    bool busy;
    clrLcdRS;
    setLcdRW;
    clrLcdEN;
    lcdDataDirIn;
    do
    {
        setLcdEN;
        busy = (bool)(lcdDataIn & 0x80);
        clrLcdEN;
        setLcdEN;
        clrLcdEN;
    }while(busy);
}

void lcdSendData(unsigned char data)
{
    lcdDataOut &= 0x0f; // clear high 4 bits.
    lcdDataOut |= (data & 0xf0); // send high 4 bits.
    setLcdEN;
    clrLcdEN;
    lcdDataOut &= 0x0f; // clear high 4 bits.
    lcdDataOut |= ((data<<4) & 0xf0); // send low 4 bits.
    setLcdEN;
    clrLcdEN;
}
void lcdWriteData(unsigned char data)
{
    lcdBusy();
    clrLcdRW;
    setLcdRS;
    lcdDataDirOut;
    lcdSendData(data);
}
void lcdWriteReg(unsigned char command)
{
    lcdBusy();
    clrLcdRW;
    lcdDataDirOut;
    lcdSendData(command);
}
void onLcd(unsigned char y, unsigned char x, char * string)
{
    if (y == 1)
    {
        lcdWriteReg( 0xc0 + x );
    }
    else
    {
        lcdWriteReg( 0x80 + x );
    }

    while(*string != 0)
    {
        lcdWriteData(*string);
        string++;
    }
}

void clearLcd(void)
{
    lcdWriteReg(0x01);
}
void initLCD(void)
{
    unsigned char i;
    lcdDataSelIO;
    lcdDataSel2IO;
    lcdCtrlDirIn;
    clrLcdRS;
    clrLcdRW;
    clrLcdEN;
    lcdDataDirOut;
    lcdDataOut &= 0x0f; // clear high 4 bits.
    lcdDataOut |= (0x30 & 0xf0); // send high 4 bits.
    for (i=0; i<4; i++)
    {
        if (i==3)
        {
            lcdDataOut &= 0x0f; // clear high 4 bits.
            lcdDataOut |= (0x20 & 0xf0); // send high 4 bits.
        }
        setLcdEN;
        clrLcdEN;
        hzc_delay(5);
        //delayTA(5);
    }

    lcdWriteReg(0x01);
    lcdWriteReg(0x06);
    lcdWriteReg(0x0c);
    clearLcd();
}
/*
#pragma vector=TIMER1_A0_VECTOR
__interrupt void ta1_isr(void)
{
  TA1CTL = 0;
  LPM0_EXIT;                                // Exit LPM0 on return
}
*/

⌨️ 快捷键说明

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