写出来的程序又如何验证是否正确?
其实,你只需要对LCD的打开、关闭,以及能把一个数据块显示在LCD上就行了
“常见字母、数字、符号、中文、自定义字符、图形,以及文字和图形混和显示;光标显示/隐藏(Cursor
on/off)、显示字符闪烁(Display
character
blink);画面清除(Display
clear)、光标归位(Return
home)”
这些功能,只需要在这个数据块上进行 *** 作,然后再送到LCD显示。
//与硬件有关的定义:数据口用的是P3口,控制口用的是P2口,//如果不同,可以更改以下定义。
#include "msp430x44x.h"
#define LCD_CON_DIRP2DIR
#define LCD_CON_OUTP2OUT
#define LCD_DI BIT0
#define LCD_RW BIT1
#define LCD_EN BIT2
#define LCD_CS1BIT3
#define LCD_CS2BIT6
#define LCD_RSTBIT7
#define LCD_DATA_DIR P3DIR
#define LCD_DATA_INP3IN
#define LCD_DATA_OUT P3OUT
#define LCD_DATA_BIT0 BIT0
#define LCD_DATA_BIT1 BIT1
#define LCD_DATA_BIT2 BIT2
#define LCD_DATA_BIT3 BIT3
#define LCD_DATA_BIT4 BIT4
#define LCD_DATA_BIT5 BIT5
#define LCD_DATA_BIT6 BIT6
#define LCD_DATA_BIT7 BIT7
//*****************************************************************
//以下为LCD的命令字
#define DISPLAY_ON0x3F //显示屏开命令字
#define DISPLAY_OFF 0x3E //显示屏关命令字
#define SET_SHOW 0xC0 //设定显示起始行命令字
#define SET_X 0xB8 //设定显示行命令字
#define SET_Y 0x40 //设定显示列命令字
--------------------------------------------------------------------------------------------------------
#include "LCD_DEFINE.H"
void lcd_init(void)
{
LCD_DATA_OUT = 0x00
LCD_DATA_DIR = 0xFF
LCD_CON_OUT = LCD_CS1+LCD_CS2+LCD_RST
LCD_CON_DIR |= LCD_DI+LCD_RW+LCD_EN+LCD_CS1+LCD_CS2+LCD_RST
LCD_CON_OUT &= ~LCD_RST
_NOP()
_NOP()
LCD_CON_OUT |= LCD_EN
_NOP()
_NOP()
LCD_CON_OUT &= ~LCD_EN
_NOP()
_NOP()
LCD_CON_OUT |= LCD_RST
_NOP()
_NOP()
}
void write_command(unsigned char command)
{
LCD_DATA_DIR = 0xFF
LCD_CON_OUT |= LCD_CS1 + LCD_CS2
LCD_CON_OUT &= ~(LCD_RW + LCD_DI)
LCD_DATA_OUT = command
LCD_CON_OUT |= LCD_EN
LCD_CON_OUT &= ~LCD_EN
}
void write_data( unsigned char data, unsigned char CS1, unsigned char CS2 )
{
LCD_DATA_DIR = 0xFF
if(CS1) LCD_CON_OUT |= LCD_CS1
else LCD_CON_OUT &=~LCD_CS1
if(CS2) LCD_CON_OUT |= LCD_CS2
else LCD_CON_OUT &=~LCD_CS2
LCD_CON_OUT |= LCD_DI
LCD_CON_OUT &=~LCD_RW
LCD_DATA_OUT = data
LCD_CON_OUT |= LCD_EN
LCD_CON_OUT &=~LCD_EN
}
void clear_lcd(void)
{
unsigned char i,j
for(i=0i<8i++)
{
write_command(SET_X|i)
write_command(SET_Y)
for(j=0j<128j++)
{
if(j<=63)write_data(0,1,0)
else write_data(0,0,1)
_NOP()
}
}
}
void display( unsigned char *chr, unsigned char nRow, unsigned char nCol,
unsigned char highth,unsigned char wideth )
//*chr 显示数据的地址,nRow 在显示屏上第几行,nCol 在显示屏上第几列
//highth 字体的高度,wideth 字体的宽度
//128*64有8行,128列
{
unsigned char i,tmpCol,tmpRow,h,m
unsigned int j
tmpRow = nRow
m=0
for(h=0h<highthh=h+8)
{
write_command(SET_X|tmpRow)
tmpCol=nCol
for(i=0i<widethi++)
{
if(tmpCol<64)
{write_command(SET_Y|tmpCol)write_data(chr[i+j],1,0)}
else
{write_command(SET_Y|(tmpCol-64))write_data(chr[i+j],0,1)}
tmpCol++
}
m++
j=m*wideth
tmpRow++
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)