|
发表于 2009-7-4 23:32:16
|
显示全部楼层
//与硬件有关的定义:数据口用的是P3口,控制口用的是P2口,
//与硬件有关的定义:数据口用的是P3口,控制口用的是P2口,
//如果不同,可以更改以下定义。
#include "msp430x44x.h"
#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_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=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 字体的宽度
//128*64有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=m*wideth;
tmpRow++;
}
} |
|