这也是几个月前的调通的程序了,现在做的规范点,做成了封装好的模块,方便调用!msp430f247调试,有不懂得可以回复上,我看到了能解决就帮忙解决下,当初自己摸索的时候吃了很多亏!
//由于430的指令周期要比51短的多,忙时检测程序一定要有
//并且延时程序要准确
#include<msp430x24x.h>
#include<string.h>
#include"12864.h"
//宏定义三个命令字
#define ENH P3OUT|=BIT7;
#define ENL P3OUT&=~BIT7;
#define RWH P3OUT|=BIT6;
#define RWL P3OUT&=~BIT6;
#define RSH P3OUT|=BIT5;
#define RSL P3OUT&=~BIT5;
#define data_in P4IN
#define data_out P4OUT
#define dir_data_in P4DIR=0X00
#define dir_data_out P4DIR=0XFF
#define dir_com_out P3DIR=BIT5+BIT6+BIT7;
//#define uint unsigned int
//#define uchar unsigned char
uint z,num,LCD_X,LCD_Y,COUNT1,COUNT2,COUNT3;
/*static const uchar table_1[]=
{"细雨带风湿透黄昏的街道,抹去雨水双眼无故的仰望,望向孤单的晚灯,是那伤感的记忆,喜欢你,那双眼动人,笑声更迷人。愿再可,轻抚你,那可爱面容,挽手说梦话,像昨天,你共我……"};
static const uchar table[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x41,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x40,0xBE,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x40,
0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x62,0x24,0x80,0x00,0x00,0x00,0x00,0x00,0xA0,
0x00,0x00,0x00,0x00,0x00,0x00,0x42,0xBE,0x3F,0xE0,0x00,0x00,0x00,0x00,0x00,0xA0,
0x00,0x00,0x00,0x00,0x00,0x3C,0x41,0xBE,0x24,0x80,0x00,0x00,0x00,0x00,0x00,0x5E,
0x00,0x00,0x00,0x00,0x00,0xFE,0x40,0x80,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0x32,
0x00,0x00,0x00,0x00,0x00,0xFC,0x41,0x7F,0x24,0x82,0x00,0x00,0x00,0x00,0x00,0x20,
0x00,0x04,0xE0,0x00,0x03,0xFC,0x41,0x55,0x22,0x80,0x00,0x00,0x00,0x00,0x00,0x20,
0x00,0x7F,0x00,0x00,0x07,0xEC,0x41,0x55,0x41,0x02,0x00,0x00,0x00,0x00,0x00,0x20,
0x00,0x7C,0x00,0x00,0x73,0xFE,0x41,0xFF,0xCE,0xE0,0x00,0x00,0x00,0x30,0x00,0x20,
0x00,0x0C,0x07,0x00,0x63,0x98,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x12,
0x00,0x0C,0x02,0x01,0x6C,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,
0x00,0x18,0x02,0x05,0x78,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x3C,0x07,0x99,0x70,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x7F,0xE3,0xED,0xC0,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x82,0x37,0x8E,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x03,0xA2,0x3F,0x1E,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x02,0xA0,0x3F,0xF6,0x00,0x00,0x40,0x00,0x25,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x06,0xB8,0x3F,0xD6,0x00,0x00,0x48,0x00,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x06,0x28,0x3F,0xC6,0x00,0x00,0x45,0xF0,0xFA,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0x28,0x3F,0xC7,0x00,0x00,0x43,0x10,0xA9,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x68,0x3F,0xC6,0xC0,0x00,0x55,0xF0,0xA8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xE8,0x3F,0xFE,0xC0,0x00,0x4D,0xF0,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFF,0xFF,0xFF,0x38,0x00,0x44,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFE,0x33,0xFF,0xEC,0x00,0x4B,0xF8,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFE,0x33,0xBF,0x5E,0x00,0x4A,0xA8,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFF,0xFF,0x07,0x3F,0x00,0x4A,0xA8,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFF,0xFC,0x07,0x7F,0xC0,0x4F,0xFC,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0xFF,0xFF,0xCF,0xC0,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0E,0x00,0xFF,0x0F,0x0F,0xC0,0x40,0x80,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xC0,0xFB,0x0F,0x0F,0x80,0x47,0xF8,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xF0,0xFB,0x1B,0x0C,0x80,0x49,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xFF,0xFE,0x1A,0x0F,0x80,0x4F,0xF8,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xFF,0x87,0x00,0x2F,0xC0,0x49,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xFF,0xFF,0xA6,0x8B,0xC0,0x49,0xC0,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xFF,0xF7,0xA6,0x1B,0xC0,0x49,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFF,0xFE,0x00,0x2B,0x80,0x48,0xA0,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFF,0xFE,0xFF,0xFF,0x80,0x50,0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFF,0xFC,0x3F,0xFF,0x80,0x53,0xB8,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xFF,0xFC,0x07,0xFF,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0xDC,0x00,0xFC,0x00,0x40,0x80,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x3F,0xF0,0x00,0x00,0x00,0x40,0x88,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1F,0xE0,0x00,0x00,0x00,0x47,0x70,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x07,0xC0,0x00,0x00,0x00,0x45,0x50,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x49,0x48,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x56,0xB0,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x41,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xF8,0x07,0x1C,0x00,0x00,0x40,0xC0,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xA8,0x08,0xA2,0x00,0x00,0x41,0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x08,0xA2,0x00,0x00,0x46,0x38,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,
0x00,0x23,0xE8,0xA2,0x00,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x06,
0x00,0x20,0x07,0x9E,0x00,0x00,0x42,0x40,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x20,0x00,0x82,0x00,0x00,0x42,0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x06,
0x00,0x20,0x04,0x92,0x00,0x00,0x44,0x40,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0xDC,
0x00,0x70,0x07,0x1C,0x00,0x00,0x44,0x50,0x25,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x4C,0x60,0x25,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x54,0x40,0x25,0x00,0x00,0x00,0x00,0x00,0x00,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x45,0xC0,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x48,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x78,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};*/
//系统时钟初始化函数
/*void clk_init()
{
uint i;
BCSCTL1&=~XT2OFF;//开XT2
do
{
IFG1&=~OFIFG;//清除时钟出错标志
for(i=0;i<100;i++);
}
while((IFG1&OFIFG)!=0);//如果振荡器失效,停在这里等待
BCSCTL2|=SELM_2;
}*/
//延时函数ms
static void delay_us(uint i)
{
while(i--)
{
_NOP();
}
}
static void delay_ms(uint i)
{
uint j;
while(i--)
for(j=0;j<800;j++);
}
//读取忙标志
void if_busy()
{
uchar temp;
dir_data_in;
RSL;
RWH;
do
{
ENH;
delay_us(1);
temp="data"_in;
ENL;
}
while(temp&0x80);
}
/*****写命令*****/
void lcm_com(uchar com)
{
if_busy();
RSL;
RWL;
dir_data_out;
data_out=com;
ENH;
delay_us(1);
ENL;
}
void WR_ZB()
{
lcm_com(0x34);
lcm_com(LCD_Y);
lcm_com(LCD_X);
lcm_com(0x30);
}
/******写数据********/
void lcm_dat(uchar dat)
{
if_busy();
RSH;
RWL;
ENL;
dir_data_out;
data_out=dat;
ENH;
delay_us(1);
ENL;
}
/****************清除GDram即图形清屏*************/
void CLEAR_GDRAM()
{
lcm_com(0x34);
COUNT3=0x02;
LCD_X=0X80;
for(;COUNT3!=0;COUNT3--)
{
LCD_Y=0x80;
COUNT2=0x20;
for(;COUNT2!=0;COUNT2--)
{
COUNT1=0x10;//16
WR_ZB();
for(;COUNT1!=0;COUNT1--)
{
lcm_dat(0x00);
}
LCD_Y+=1;
}
LCD_X=0x88;
}
lcm_com(0x36);
lcm_com(0x30);
}
/*****汉字清屏******/
void clear_hanzi()
{
lcm_com(0x01);
_NOP();
}
//指定地址
void goto_xy(uchar x,uchar y)
{
if(y==1)
lcm_com(0x80|x);
if(y==2)
lcm_com(0x90|x);
if(y==3)
lcm_com(0x80|x+8);
if(y==4)
lcm_com(0x90|x+8);
}
//显示汉字方式1
void hanzi(uchar x,uchar y,uchar *zi)
{
lcm_com(0x30);
goto_xy(x,y);
while(*zi!=0)
{
lcm_dat(*zi++);
// delay_ms(10);
}
}
//统计有多少个字,用来确定页码
uchar zishu(const char *j)
{
uint n,yeshu,temp1,temp2;
n="strlen"(j);
temp1=n/2/32;
if((n/2%32)!=0)
temp2=1;
yeshu="temp1"+temp2;
return yeshu;
}
//显示汉字方式2,ye_shu为总页数,time为每翻一页的等待时间,ye_n表示从第几页开始
//第一页为,*p表示数组表
void text(uint time,uchar ye_n,const char *p)
{
uchar a="0x80",i,j,k,temp=0;
lcm_com(0x30);
for(k=ye_n;k<zishu(p);k++)
{
lcm_com(0x01);
delay_ms(1);
for(i=0;i<4;i++)
{
lcm_com(a);
for(j=0;j<16;j++)
{
lcm_dat(p[64*k+16*i+j]);
delay_ms(10);
if(p[64*k+16*i+j]==0)
{
temp="1";
}
if(temp==1)
break;
}
switch(a)
{
case 0x80:a=0x90;break;
case 0x90:a=0x88;break;
case 0x88:a=0x98;break;
case 0x98:a=0x80;break;
}
if(temp==1)
break;
}
delay_ms(time);
if(temp==1)
break;
}
}
//反白显示,当写入0xff时就反白了,当反白第3行是,y地址不能写0x88,要写0x80
//要反白第4行时同理只能在Y地址里写入0x90
void con_disp(uchar data1,uchar data2,uchar x0,uchar y0,uchar x1,uchar y1)
{
CLEAR_GDRAM();
uchar i,j;
lcm_com(0x34);
for(j=0;j<y1;j++)//y1一般取16,刚好一行字的宽度
{
for(i=0;i<x1;i++)//x1就是你要反白的字的多少
{
lcm_com(y0+j);
lcm_com(x0+i);
lcm_dat(data1);
lcm_dat(data2);
}
}
lcm_com(0x36) ;
}
//打点函数,X坐标从左往右0-127,Y坐标从上往下0-63;
void point(uchar x,uchar y)
{
uchar hang,lie,msb_data=0,lsb_data=0,temp=0x01;
if(y<32)
{
hang=0x80+y;
lie=0x80;
}
if(y>31)
{
hang=0x80+y-32;
lie=0x88;
}
if(y>63)//return;
{
lcm_com(0x80);
while(1);
}
lie=lie+x/16;
if(x%16==0)
{
msb_data=0;
lsb_data=0;
}
if(x%16<8)
{
msb_data=msb_data|(temp<<(7-x%16));
lsb_data=0x00|lsb_data;
}//保留以前的数据,把第x个点亮
if(x%16==8)
{
msb_data=msb_data|0x00;
lsb_data=lsb_data|0x80;
}
if(x%16>8)
{
msb_data=msb_data|0x00;
lsb_data=lsb_data|(temp<<(15-x%16));
}
lcm_com(0x34);//扩充指令集
lcm_com(hang);
lcm_com(lie);
lcm_dat(msb_data);
lcm_dat(lsb_data);
lcm_com(0x36);//绘图显示开
}
/***********************************/
/*************图形显示**************/
/***********************************/
void pho_disp(const uchar *s)
{
lcm_com(0x34);
lcm_com(0x01);//清屏
delay_ms(5);
COUNT3=0x02;
LCD_X=0X80;
for(;COUNT3!=0;COUNT3--)
{
LCD_Y=0x80;
COUNT2=0x20;
for(;COUNT2!=0;COUNT2--)
{
COUNT1=0x10;//16
WR_ZB();
for(;COUNT1!=0;COUNT1--)
{
lcm_dat(*s++);
}
LCD_Y+=1;
}
LCD_X=0x88;
}
lcm_com(0x36);
// lcm_com(0x30);
}
//初始化函数
void init_yejing()
{
WDTCTL="WDTPW"+WDTHOLD;
// clk_init();
dir_com_out;
lcm_com(0x80);
delay_ms(1);
lcm_com(0x30);
delay_ms(1);
lcm_com(0x0C);
delay_ms(1);
lcm_com(0x06);
delay_ms(1);
lcm_com(0x01);
}
//直接往液晶里面写入一个原型码
void one_char(uchar x,uchar y,uchar dat)
{
lcm_com(0x30);
goto_xy(x,y);
lcm_dat(dat);
}
用户1373959 2010-5-18 21:29
用户229351 2010-1-9 02:50
用户175873 2009-9-21 11:13