打印

菜鸟跪求HD61202和KS0108的驱动程序

[复制链接]
2764|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
数字钟|  楼主 | 2007-5-16 18:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我用凌阳61单片机做数字钟,液晶显示器是12864点阵的,现在连线连不好,驱动程序也没有,请各位大虾帮帮忙,万分感谢

相关帖子

沙发
tyw| | 2007-5-16 18:56 | 只看该作者

去这里下

液晶控制器HD61202中文使用手册

 下载地址一:
http://soft.laogu.com/download/hd61202new.pdf 









 
    KS0108 →              http://www.laogu.com/wz_1282.htm

MSP430与12864连接驱动程序(KS0108)

发布时间:2006年3月13日 点击次数:1211 
来源: 
作者:
详细内容: 
 

#include           "msp430x14x.h"        // Standard Equations
#include           "math.h"
#include           "stdlib.h"
#include           "stdio.h"
#include           "string.h"
#include           "ctype.h"
#include   "HZTable.h"
#include   "ASCII816.h"
#define uint unsigned int
#define uchar unsigned char
//**********************************************
#define    RS         BIT0
#define    RW        BIT1
#define    E           BIT2
#define    CS1       BIT3
#define    CS2       BIT4
#define    RST       BIT5
#define    EL          BIT6          //背光
//数据线:p4口   ,控制线:  p5口
//**********************************************
uchar  cradd1,cradd2;
 uchar item1[5]={0,1,2,3,50};       //欢迎使用
 uchar item2[5]={4,5,6,7,50};       //请等待……
//=======================================================
void short_delay(uint i)
     { uint j;
       for(j=0;j<=i;j++);
     }
void delayms(uchar tickms)
     { uchar count,i;
       _NOP(); 
       _NOP(); 
       _NOP();
       for(i=tickms;i>0;i--)
         { for(count=0;count<=58;count++) {;}
           _NOP();
         }
      }
//**************************************************
void prl0(uchar com1)// 写指令代码子程序(左)

        P5DIR =0X7F;      //P5为输出口
        P5OUT =CS1;       //csa=1  
        P5OUT&=~CS2;      //csb=0
        P5OUT&=~RS;         
        P5OUT =RW;        //RS=0,R/W=1,以便读液晶状态
        P4DIR=0x00;       //P4口为输入口
        do
        {
                 P5OUT =E;      //E=1
                 cradd1=P4IN;
                P5OUT&=~E;     //E=0  
        }
        while((cradd1&0x80)!=0);
         P5OUT&=~RW;        //rw=0
         P4DIR=0xff;       //P4口为输出口
        P4OUT=com1;
        P5OUT =E;      //E=1
        P5OUT&=~E;     //E=0  
}
//**************************************************
void prl1(uchar dat1)// 写显示数据子程序(左)
{       
         P5DIR =0X7F;      //P5为输出口
         P5OUT =CS1;       //csa=1  
         P5OUT&=~CS2;      //csb=0
         P5OUT&=~RS;         
         P5OUT =RW;        //RS=0,R/W=1,以便读液晶状态
         P4DIR=0x00;       //P4口为输入口
        do
        {
                 P5OUT =E;      //E=1
                 cradd1=P4IN;
                P5OUT&=~E;     //E=0  
        }
        while((cradd1&0x80)!=0);
        P5OUT =RS;         //rs=1  
        P5OUT&=~RW;        //rw=0
         P4DIR=0xff;       //P4口为输出口
         P4OUT=dat1;
        P5OUT =E;      //E=1
        P5OUT&=~E;     //E=0  
     }
//**************************************************
void prr0(uchar com2)// 写指令代码子程序(右)

         P5DIR =0X7F;      //P5为输出口
         P5OUT&=~CS1;      //csa=0  
        P5OUT =CS2;       //csb=1
        P5OUT&=~RS;         
        P5OUT =RW;        //RS=0,R/W=1,以便读液晶状态
        P4DIR=0x00;       //P4口为输入口
        do
        {
                P5OUT =E;      //E=1
                cradd1=P4IN;
                P5OUT&=~E;     //E=0  
        }
        while((cradd1&0x80)!=0);
         P5OUT&=~RW;        //rw=0
         P4DIR=0xff;       //P4口为输出口
         P4OUT=com2;
         P5OUT =E;      //E=1
         P5OUT&=~E;     //E=0  
}
//*************************************************
void prr1(uchar dat2)// 写显示数据子程序(右)

         P5DIR =0X7F;      //P5为输出口
         P5OUT&=~CS1;      //csa=0  
         P5OUT =CS2;       //csb=1
        P5OUT&=~RS;         
        P5OUT =RW;        //RS=0,R/W=1,以便读液晶状态
        P4DIR=0x00;       //P4口为输入口
        do
        {
                 P5OUT =E;      //E=1
                 cradd1=P4IN;
                P5OUT&=~E;     //E=0  
        }
        while((cradd1&0x80)!=0);
        P5OUT =RS;         //rs=1  
        P5OUT&=~RW;        //rw=0
        P4DIR=0xff;       //P4口为输出口
        P4OUT=dat2;
        P5OUT =E;      //E=1
        P5OUT&=~E;     //E=0  
}
//****************************************************
//读显示数据子程序      (左屏)
//****************************************************
uchar ReadDatal(void)
{
      uchar Rdata;
      P5DIR =0X7F;      //P5为输出口
      P5OUT =CS1;       //csa=1  
      P5OUT&=~CS2;      //csb=0
      P5OUT&=~RS;         
      P5OUT =RW;        //RS=0,R/W=1,以便读液晶状态
      P4DIR=0x00;       //P4口为输入口
      do
      {
                P5OUT =E;      //E=1
                cradd1=P4IN;
                P5OUT&=~E;     //E=0  
      }
      while((cradd1&0x80)!=0);
      P5OUT =RS;                 //RS=1 
      //P5OUT =RW;               //R/W=1
      P5OUT =E;                  //E=1
      Rdata=P4IN;
      P5OUT&=~E;                 //E=0  
      return Rdata;        
}
//****************************************************
//读显示数据子程序          (右屏)
//****************************************************
uchar ReadDatar(void)
{
      uchar Rdata;
      P5DIR =0X7F;      //P5为输出口
      P5OUT&=~CS1;      //csa=0  
      P5OUT =CS2;       //csb=1
      P5OUT&=~RS;         
      P5OUT =RW;        //RS=0,R/W=1,以便读液晶状态
      P4DIR=0x00;       //P4口为输入口
      do
      {
                 P5OUT =E;      //E=1
                cradd1=P4IN;
                P5OUT&=~E;     //E=0  
      }
      while((cradd1&0x80)!=0);
      P5OUT =RS;                 //RS=1 
      //P5OUT =RW;               //R/W=1
      P5OUT =E;                  //E=1
      Rdata=P4IN;
      P5OUT&=~E;                 //E=0  
      return Rdata;        
}
//**********************************************
//**********************************************
void clsr(void)     //清屏         
{      uchar i,j;
       for(i=0;i<8;i++)
       {   prl0(i 0xb8);      //设置页地址
           prr0(i 0xb8);
           prl0(0x40);
           prr0(0x40);
           for(j=0;j<64;j++)  //设置列地址
             { prl1(0x00);    //写0x00 
               prr1(0x00);
             }
       }
}
//**********************************************
void allon(void)    //满屏
    { uchar i,j;
      for(i=0;i<8;i++)
         { prl0(i 0xb8);
           prr0(i 0xb8);
           prl0(0x40);
           prr0(0x40);
           for(j=0;j<64;j++)
             { prl1(0xff);  //写0xff
               prr1(0xff);
             }
          }
      }
//***********************************************
void stripe(void)
    { uchar i,j;
      for(i=0;i<8;i++)
         { prl0(i 0xb8);
           prr0(i 0xb8);
           prl0(0x40);
           prr0(0x40);
           for(j=0;j<64;j++)
             { prl1(0xaa);
               prr1(0xaa);  // 写0xaa
             }
          }
      }
//***********************************************
void stripe1(void)
{ uchar i,j;
      for(i=0;i<8;i++)
      {    prl0(i 0xb8);
           prr0(i 0xb8);
           prl0(0x40);
           prr0(0x40);
           for(j=0;j<64;j++)
             { prl1(0x55);   // 写0x55
               prr1(0x55);
             }
      }
}
//***************************************************
//***************************************************
void hzw_pr(uchar colum2,uchar  page2,uchar code2)// 写汉字 
//page2:页  colum2:列    code2:代码  code2=0,1,2,3……表示第几个汉字
{   uchar i,j,colum;
    uchar  *hzp;         
    uchar flag;
   hzp=&HZTable[code2][0]; 
    for(j=0;j<2;j++)
    {    prl0(page2 0xb8);         //页
         prr0(page2 0xb8);
         colum=colum2;
         if(colum2>63)           //右屏
   { colum=colum-64;
                       prr0(colum 0x40);  
                       flag=1;
   }
         else                    //左屏
   {prl0(colum 0x40);
                  flag=0;
   }
   //*********************
         for(i=0;i<16;i++)
         { 
    if(flag==0)
    {
     prl1(*hzp);
    }
                else
    {prr1(*hzp);}
                hzp++;
                if(colum==64)   //列=64
    {
     colum=0;
                    if(flag==0)
     {
      flag=1;
                        prr0(colum 0x40);
     }
                    else{break;}
                }
                colum++;
         }
         page2++;
    }
}
//***********************************************
void w_hzstr(uchar colum4,uchar  page4,uchar   *str1)// 写汉字字符串    
{
      while(*str1!=50)
      { 
                hzw_pr( colum4,  page4,*str1) ;
                colum4=colum4+16;
                str1++;
       }
}
//***************************************************
//init_xt2;   初始化XT2     晶振为4MHZ
//*****************************************************
void init_xt2(void)
{
     unsigned int iq0;
   
   //使用XT2振荡器
   BCSCTL1&=~XT2OFF;             //打开XT2振荡器
   do
   {
   IFG1 &= ~OFIFG;    // 清除振荡器失效标志
   for (iq0 = 0xFF; iq0 > 0; iq0--); // 延时,等待XT2起振
   } while ((IFG1 & OFIFG) != 0);   // 判断XT2是否起振
  BCSCTL2 =SELM_2+SELS;                 //选择MCLK、SMCLK为XT2,
  BCSCTL2 =DIVM_1;                            //MCLK 2分频SMCLK=MCLK=2MHZ
}
//***********************************************
//主程序 
//***********************************************
void main(void)
{    
   uchar  a;
  // uchar i,j;
   WDTCTL=WDTPW+WDTHOLD; 
   init_xt2();
   P5DIR =0X7F;       //P5为输出口
   P5OUT&=~RST;       //rst=0  
   delayms(10);        //1ms
   P5OUT =RST;        //rst=1
   P5OUT&=~EL;       //EL=0  背光=0 
   do
    {   
         prl0(0xc0);prr0(0xc0);   //显示开始行
         prl0(0x3f);prr0(0x3f);   //开显示
         //P5OUT&=~EL;       //EL=0  背光=0 
         //******************************************************
         clsr();        //  clear screen  
                           //写汉字字符串1   欢迎使用 
                           //写汉字字符串2   请等待…                                     
         w_hzstr(32,2,item1);w_hzstr(32,5,item2);                                              
         delayms(100);                                      
         for(a=0;a<50;a++)
         { delayms(100);} 
         prl0(0xc0);prr0(0xc0);

         clsr();        
         allon();       //  fill screen   
         delayms(100);
         for(a=0;a<25;a++)
           { delayms(100);}
         prl0(0xc0);prr0(0xc0);
         clsr();        //  clear screen   
         delayms(100);
         for(a=0;a<25;a++)
           { delayms(100);}

        /*  stripe screen   */
         prl0(0xc0);prr0(0xc0);
         stripe();
         delayms(100);
         for(a=0;a<20;a++)
           { delayms(100);}
         prl0(0xc0);prr0(0xc0);
         stripe1();
         delayms(100);
         for(a=0;a<50;a++)
           { delayms(100);}
    }while(1);
}

//****************************************************

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

6

帖子

0

粉丝