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

📄 lcd_16x2.c

📁 LCD basic code for LPC2114 with Proteus simulation. LCD of type 16x2
💻 C
字号:
//Author: Kanishka Shah
//LCD test code for LPC2114
		
#include <LPC21xx.H>
#include "string.h"
#include <stdio.h>
/*
    LCD connections:
    P1.20   P1.23   P1.19   P1.18   P1.17   P1.16
    RS  EN  D7  D6  D5  D4
    4 bit interface is used.
*/

void SmallDelay ()
{
/*
    does nothing, but produces small delay due to call and return instructions
*/
}
void LcdCmd1 (unsigned char cmd)
{
    unsigned int temp ;

    IOSET1 = temp = 0x0F0000 & (cmd << 16) ;
    IOCLR1 = (temp ^ 0x0F0000) | 0x900000 ;

    SmallDelay() ;
    IOSET1 = 0x800000 ;
    SmallDelay() ;
    IOCLR1 = 0x800000 ;
    SmallDelay() ;
}
void LcdDat1 (unsigned char dat)
{
    unsigned int temp ;

    IOSET1 = temp = (0x0F0000 & (dat << 16)) | 0x100000 ;
    IOCLR1 = (temp ^ 0x1F0000) | 0x800000 ;

    SmallDelay() ;
    IOSET1 = 0x800000 ;
    SmallDelay() ;
    IOCLR1 = 0x800000 ;
    SmallDelay() ;
}
void Delay250 ()
{
    int k ;
    for(k = 0 ; k < 100 ; k ++)
    {
    }
}
void DelayMs (int n)
{
    int k ;
    for(k = 0 ; k < n ; k ++)
    {
        Delay250() ;
        Delay250() ;
        Delay250() ;
        Delay250() ;
    }
}
void LcdCmd (unsigned char cmd)
{
    LcdCmd1(cmd >> 4) ;
    LcdCmd1(cmd) ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
}
void LcdDat (unsigned char dat)
{
    LcdDat1(dat >> 4) ;
    LcdDat1(dat) ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;

}
void LcdInit ()
{
    IODIR1 = 0x9F0000 ;
    IOCLR1 = 0x9F0000 ;
    DelayMs(15) ;
    DelayMs(15) ;
    DelayMs(15) ;
    DelayMs(15) ;
    LcdCmd1(0x03) ;
    DelayMs(6) ;
    DelayMs(6) ;
    DelayMs(6) ;
    DelayMs(6) ;
    LcdCmd1(0x03) ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    LcdCmd1(0x03) ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    LcdCmd1(0x02) ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;
    Delay250() ;

    LcdCmd(0x28) ;
    LcdCmd(0x08) ;
    LcdCmd(0x0c) ;
    LcdCmd(0x06) ;
}
void DisplayRow(int row,char *str)
{
/*
    pass pointer to 16 character string
    displayes the message on line1 or line2 of LCD, depending on whether row is 1 or 2.
*/
    int k ;

    if (row == 1)
        LcdCmd(0x80) ;
    else 
        LcdCmd(0xc0) ;
	for(k = 0 ; k < 16 ; k ++)
    {
        if (str[k])
            LcdDat(str[k]) ;
        else
            break ;
    }
	

    while(k < 16)
    {
        LcdDat(' ') ;
        k ++ ;
    }
}

void ClearLine(int row)
{
    char szTemp[17] ;
    sprintf(szTemp,"                ") ;
        DisplayRow(row,szTemp) ;

}

int main()
{
 LcdInit();

  DisplayRow(1,"Nex-Robotics");		 //Line '1'; Position '2'
  DisplayRow(2,"Kanishka Shah");
  //ClearLine(2);
return 0;
}

⌨️ 快捷键说明

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