试一试:
#include <msp430x13x.h>
#define lcdwr BIT2 //p4.2
#define lcdrd BIT3 //p4.3
#define lcdce BIT4 //p4.4
#define lcdcd BIT5 //p4.5
#define lcdrst BIT6 //p4.6
#define lcdfs BIT7 //p4.7
unsigned char dian[32]={ 0x02,0x00,0x02,0x00,0x02,0x08,0x03,0xFC,
0x02,0x00,0x02,0x10,0x3F,0xF8,0x20,0x10,
0x20,0x10,0x20,0x10,0x3F,0xF0,0x00,0x00,
0x29,0x10,0x24,0xC8,0x44,0x44,0x80,0x04};
unsigned char zhen[32]={ 0x00,0x80,0x78,0x84,0x4F,0xFE,0x50,0x80,
0x50,0xA0,0x61,0x20,0x51,0x28,0x4B,0xFC,
0x48,0x20,0x48,0x20,0x68,0x24,0x57,0xFE,
0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20};
unsigned char ye[32]={ 0x00,0x80,0x40,0x44,0x37,0xFE,0x10,0x20,
0x81,0x20,0x61,0x3C,0x22,0x44,0x0A,0x64,
0x16,0x98,0x2B,0x48,0xE2,0x50,0x22,0x20,
0x22,0x50,0x22,0x8E,0x23,0x04,0x22,0x00};
unsigned char jing[32]={ 0x0F,0xE0,0x08,0x20,0x08,0x20,0x0F,0xE0,
0x08,0x20,0x08,0x20,0x0F,0xE0,0x08,0x24,
0x7E,0xFE,0x42,0x84,0x42,0x84,0x7E,0xFC,
0x42,0x84,0x42,0x84,0x7E,0xFC,0x42,0x84};
unsigned char lian[32]={ 0x01,0x04,0xFE,0xCC,0x24,0x50,0x24,0x00,
0x3D,0xFC,0x24,0x20,0x24,0x20,0x24,0x24,
0x3F,0xFE,0x24,0x20,0x24,0x20,0x24,0x50,
0x3E,0x50,0xE4,0x88,0x05,0x0E,0x06,0x04};
unsigned char xi[32]={ 0x00,0x38,0x7F,0xC0,0x04,0x00,0x04,0x10,
0x08,0x20,0x3F,0xC0,0x01,0x00,0x02,0x20,
0x04,0x10,0x3F,0xF8,0x01,0x08,0x09,0x20,
0x09,0x10,0x11,0x08,0x25,0x08,0x02,0x00 };
unsigned char ren[32]={ 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x02,0x80,
0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40,
0x08,0x20,0x10,0x10,0x20,0x0E,0x40,0x04};
unsigned char yang[32]={0x10,0x00,0x13,0xF8,0x10,0x10,0x10,0x20,
0xFC,0x40,0x10,0x84,0x33,0xFE,0x38,0xA4,
0x54,0xA4,0x50,0xA4,0x91,0x24,0x11,0x44,
0x12,0x44,0x14,0x84,0x11,0x28,0x10,0x10};
unsigned char xiao[32]={0x00,0x80,0x08,0x88,0x7C,0xFC,0x4F,0x80,
0x48,0x50,0x48,0x22,0x78,0xD2,0x4B,0x0E,
0x48,0x00,0x4B,0xFC,0x48,0xA0,0x78,0xA0,
0x49,0x22,0x01,0x22,0x02,0x1E,0x0C,0x00};
unsigned char llong[32]={0x02,0x00,0x02,0x40,0x02,0x20,0x02,0x04,
0xFF,0xFE,0x02,0x80,0x02,0x88,0x04,0x88,
0x04,0x90,0x04,0xA0,0x08,0xC0,0x08,0x82,
0x11,0x82,0x16,0x82,0x20,0x7E,0x40,0x00};
void Lcd_Delay(unsigned int x);
void LcdWaitBusy(void);
void LcdWaitBusyAuto(void);
void LcdWrite_D(unsigned char x); //write data
void LcdWrite_I(unsigned char x); //write instruction
void LcdWrite_Com2(unsigned char x,unsigned char y,unsigned char z);
void LcdWrite_Com1(unsigned char x,unsigned char y);
void LcdWrite_Com0(unsigned char x);
void LcdWrite_HanZi(unsigned char* hanzi,unsigned int z);
void LcdWrite_Text(unsigned char w,unsigned int z);
void LcdInit(void);
/*************************************************************/
void main(void)
{
WDTCTL=WDTPW+WDTHOLD; // shut up watchdog
P4SEL&=~(BIT2+BIT3+BIT4+BIT5+BIT6+BIT7); // port function set I/O
port
P4DIR|=BIT2+BIT3+BIT4+BIT5+BIT6+BIT7; // port function set output
P4OUT|=BIT2+BIT3+BIT4+BIT5+BIT6; // port function set
P4OUT&=~BIT7; // select 8*8
LcdInit();
LcdWrite_Com0(0x9c);
LcdWrite_Text(0x13,0x0801); // line 1
LcdWrite_Text(0x36,0x0802);
LcdWrite_Text(0x11,0x0803);
LcdWrite_Text(0x12,0x0804);
LcdWrite_Text(0x18,0x0805);
LcdWrite_Text(0x0a,0x0806);
LcdWrite_Text(0x16,0x0807);
LcdWrite_Text(0x14,0x0808);
LcdWrite_HanZi(dian,0x0809);
LcdWrite_HanZi(zhen,0x080b);
LcdWrite_HanZi(ye,0x080d);
LcdWrite_HanZi(jing,0x080e);
LcdWrite_HanZi(lian,0x09e1); // line 2
LcdWrite_HanZi(xi,0x09e3);
LcdWrite_HanZi(ren,0x09e5);
LcdWrite_Text(0x1a,0x1861);
LcdWrite_HanZi(yang,0x09e9);
LcdWrite_HanZi(xiao,0x09eb);
LcdWrite_HanZi(llong,0x09ed);
LcdWrite_Text(0x10,0x189a); // line 3
LcdWrite_Text(0x17,0x189b);
LcdWrite_Text(0x15,0x189c);
LcdWrite_Text(0x15,0x189d);
LcdWrite_Text(0x0d,0x189e);
LcdWrite_Text(0x12,0x189a);
LcdWrite_Text(0x16,0x189b);
LcdWrite_Text(0x11,0x189c);
LcdWrite_Text(0x15,0x189d);
LcdWrite_Text(0x16,0x189e);
LcdWrite_Text(0x19,0x189c);
LcdWrite_Text(0x13,0x189d);
LcdWrite_Text(0x10,0x189e);
LcdWrite_Text(0x31,0x18b4); // line 4
LcdWrite_Text(0x31,0x18b5);
LcdWrite_Text(0x1a,0x18b6);
LcdWrite_Text(0x13,0x18b7);
LcdWrite_Text(0x17,0x18b8);
LcdWrite_Text(0x16,0x18b9);
LcdWrite_Text(0x10,0x18ba);
LcdWrite_Text(0x12,0x18bb);
LcdWrite_Text(0x17,0x18bc);
LcdWrite_Text(0x12,0x18bd);
LcdWrite_Text(0x17,0x18be);
LcdWrite_Text(0x17,0x18bf);
}
/**************************************************************/
void Lcd_Delay(unsigned int x) //time delay
{
while(x!=0)x--;
}
void LcdWrite_D(unsigned char x) //write date
{
P4OUT&=~lcdcd;
P4OUT|=lcdwr;
P4OUT&=~lcdce;
P4OUT&=~lcdwr;
P5DIR=0xff;
P5OUT=x;
P4OUT|=lcdce;
P4OUT|=lcdwr;
}
void LcdWrite_I(unsigned char x) //write instruction
{
P4OUT|=lcdcd;
P4OUT|=lcdwr;
P4OUT&=~lcdwr;
P4OUT&=~lcdce;
P5DIR=0xff;
P5OUT=x;
P4OUT|=lcdce;
P4OUT|=lcdwr;
}
void LcdWrite_Com2(unsigned char x,unsigned char y,unsigned char z)
{
LcdWaitBusy();
LcdWrite_D(x);
LcdWaitBusy();
LcdWrite_D(y);
LcdWaitBusy();
LcdWrite_I(z);
}
void LcdWrite_Com1(unsigned char x,unsigned char y)
{
LcdWaitBusy();
LcdWrite_D(x);
LcdWaitBusy();
LcdWrite_I(y);
}
void LcdWrite_Com0(unsigned char x)
{
LcdWaitBusy();
LcdWrite_I(x);
}
void LcdWaitBusy(void)
{
unsigned char x;
do
{
P4OUT|=lcdcd;
P4OUT&=~lcdce;
P4OUT|=lcdwr;
P4OUT&=~lcdrd;
P5DIR=0x00; //p5 set input
x=P5IN&0x03;
P4OUT|=lcdce;
P4OUT|=lcdrd;
}
while(x!=0x03); //mask the other status bits and test the busy bit
}
void LcdWaitBusyAuto(void)
{
unsigned char x;
do
{
P4OUT|=lcdcd;
P4OUT&=~lcdce;
P4OUT|=lcdwr;
P4OUT&=~lcdrd;
P5DIR=0x00; //p5 set input
x=P5IN&0x08;
P4OUT|=lcdce;
P4OUT|=lcdrd;
}
while(x!=0x08); //mask the other status bits and test the busy bit
}
void LcdInit(void)
{
unsigned int i;
P4OUT&=~lcdrst;
_NOP();
_NOP();
P4OUT|=lcdrst;
_NOP();
_NOP();
LcdWrite_Com2(0x00,0x00,0x21);
LcdWrite_Com2(0x00,0x00,0x22);
LcdWrite_Com2(0x00,0x00,0x24);
LcdWrite_Com2(0x00,0x18,0x40);
LcdWrite_Com2(0x1E,0x00,0x41);
LcdWrite_Com2(0x00,0x08,0x42);
LcdWrite_Com2(0x1E,0x00,0x43);
LcdWrite_Com0(0x80);
LcdWrite_Com0(0x9c);
LcdWrite_Com0(0xA0);
for(i=0;i<0x2000;i++) //clear lcd
{
LcdWrite_Com1(0x00,0xc0);
}
}
void LcdWrite_HanZi(unsigned char* hanzi,unsigned int z)
{
unsigned char i,x,y;
for(i=0;i<0x20;i++)
{
x=(unsigned char)(z&0x00ff);
y=(unsigned char)((z&0xff00)/0x100);
LcdWrite_Com2(x,y,0x24);
LcdWrite_Com1(hanzi[i],0xc0);
i++;
LcdWrite_Com1(hanzi[i],0xc0);
z=z+0x1e;
}
LcdWrite_Com2(0x00,0x00,0x21);
LcdWrite_Com2(0x00,0x00,0x24);
}
void LcdWrite_Text(unsigned char w,unsigned int z)
{
unsigned int x,y; //z=0x1800
x=(unsigned char)(z&0x00ff);
y=(unsigned char)((z&0xff00)/0x100);
LcdWrite_Com2(x,y,0x24);
LcdWrite_Com1(w,0xc0);
LcdWrite_Com2(0x00,0x00,0x21);
LcdWrite_Com2(0x00,0x00,0x24);
} |