原创 12864驱动程序

2009-8-7 19:29 4292 1 3 分类: EDA/ IP/ 设计与制造

这也是几个月前的调通的程序了,现在做的规范点,做成了封装好的模块,方便调用!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);
}

广告

文章评论 2条评论)

登录后参与讨论

tear086_727697317 2010-5-18 21:29

excellent

qwer19987 2010-1-9 02:50

恳请版主帮忙= =有关于MSP430驱动LCD12864程序里的#include #include"12864.h"方便提供范例吗???因为小弟正苦无法将它驱动><”

hanbao0371 2009-9-21 11:13

说下控制器的型号,还有接口的连接,这样方便大家移植啊。我感觉好像是并口的,但是控制线只有三根?
相关推荐阅读
zhouwen880728_377327045 2010-04-28 22:18
第一天
capture CIS中的快捷键原理图页面编辑 CTRL+A 全选所有原理图页面编辑 B 放置总线BUS原理图页面编辑 E 放置总线BUS 的分支Entry原理图页面编辑 F 放置电源符号原理图页面编...
zhouwen880728_377327045 2010-04-27 20:33
准备做个板
从咸宁过来武大有半年了,一直忙着毕业的事情以及导师的项目,很久没有更新空间了,现在项目闲下来了,也该做做自己的事情了,准备画一个2440的开发板。想每天上来更新下自己的进度,记录下,也能让自己坚持下去...
zhouwen880728_377327045 2009-09-18 13:01
关于ARM7时钟的问题
在ARM7处理器中,在没有配置PLL和VPB分频器前,系统时钟Fcclk就是外部晶振的时钟Fosc,内部VPB总线的时钟是Fcclk/4也就是说是Fosc/4,开始关于时钟这章的疑惑就在这里。网上有学...
zhouwen880728_377327045 2009-09-15 18:38
msp430开发板
对msp430的一个总结板,集成了学习430来做过的一些东西,彩色触摸液晶屏,24L01,DDS AD9851……正面反面http://space.ednchina.com/Upload/2009/9...
zhouwen880728_377327045 2009-09-09 11:10
开始学习ARM了
开始两天了,今天终于能在Proteus里仿真lpc2100了,对系统启动的过程也有了个大致的认识,再过两天我的板子就到了。...
zhouwen880728_377327045 2009-08-30 15:04
AD603调试心得
在众多网友的经验下,AD603的调试也算是顺风顺水,半天解决了,开始直接照着PDF搭了个模式二的电路,直接将函数发生器的信号输入进来,波形严重失真,扭曲的不成样子,频率也不对,并且增益不可控,但是很稳...
我要评论
2
1
广告
关闭 热点推荐上一条 /1 下一条