//与硬件有关的定义:数据口用的是P3口,控制口用的是P2口,
//如果不同,可以更改以下定义。
#include "msp430x44xh"
#define LCD_CON_DIR P2DIR
#define LCD_CON_OUT P2OUT
#define LCD_DI BIT0
#define LCD_RW BIT1
#define LCD_EN BIT2
#define LCD_CS1 BIT3
#define LCD_CS2 BIT6
#define LCD_RST BIT7
#define LCD_DATA_DIR P3DIR
#define LCD_DATA_IN P3IN
#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_ON 0x3F //显示屏开命令字
#define DISPLAY_OFF 0x3E //显示屏关命令字
#define SET_SHOW 0xC0 //设定显示起始行命令字
#define SET_X 0xB8 //设定显示行命令字
#define SET_Y 0x40 //设定显示列命令字
--------------------------------------------------------------------------------------------------------
#include "LCD_DEFINEH"
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=0;i<8;i++)
{
write_command(SET_X|i);
write_command(SET_Y);
for(j=0;j<128;j++)
{
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 字体的宽度
//12864有8行,128列
{
unsigned char i,tmpCol,tmpRow,h,m;
unsigned int j;
tmpRow = nRow;
m=0;
for(h=0;h<highth;h=h+8)
{
write_command(SET_X|tmpRow);
tmpCol=nCol;
for(i=0;i<wideth;i++)
{
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=mwideth;
tmpRow++;
}
}
//向Lcd发送命令程序
void
Lcd_Command(unsigned
char
Command)
{
while(Lcd_Busy());
//判断lcd是否内部 *** 作状态
E_L;RS_L;RW_L;
//E=0(致能),RS=0(命令),RW=0(写)
delay_us(2);
//液晶延时子程序
E_H;
PORTB
=
Command;
//向Lcd发送命令
delay_us(2);
//液晶延时子程序
E_L;
}
以上就是关于关于128X64点阵LCD液晶显示的使用-程序全部的内容,包括:关于128X64点阵LCD液晶显示的使用-程序、单片机LCD问题、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)