?? lcd_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 + -