在线情况
楼主
  • 头像
  • 级别
  • 门派
  • 职务总版主
  • 声望+9
  • 财富5
  • 积分3065
  • 经验390701
  • 文章6744
  • 注册2006-03-07
用MSP430轻松驱动DM128显示模块[适合F1,F2,F5系列用]
   微控论坛原创主贴   [COLOR=blue]MSP430驱动HT1621演示C源程序分享[/COLOR]

【图  片】
        [IMGA=0,absMiddle]http://www.microcontrol.cn/430images/LCD/DM128-1-01.gif[/IMGA]
                                 实物演示图片


  [IMGA=0,absMiddle]http://www.microcontrol.cn/430images/LCD/DM128-1-03.gif[/IMGA]
                             MSP430与MC128DM模块连接非常简单

【公开源码】
描  述:利用MC430开发板驱动微控DM128模块,进行LCD打开和显示5位数字、最后关闭模块的演示过程。非常简单和方便使用。
#include <MSP430x14x.h>
#define BIAS 0x29
#define SYSEN 0x01      //系统使能
#define LCDOFF 0x02     //LCD关
#define LCDON 0x03      //LCD开

#define HT1621IO_DIR P4DIR |= BIT0+BIT1+BIT2
#define CS1 P4OUT |= BIT0
#define CS0 P4OUT &= ~BIT0
#define WR1 P4OUT |= BIT2
#define WR0 P4OUT &= ~BIT2
#define DAT1 P4OUT |= BIT1
#define DAT0 P4OUT &= ~BIT1

unsigned char a[10]={0x60,0xC7,0xE5,0x6C,0xAD};
//******************************************************************************
void SendBit_1621(unsigned char data,unsigned char cnt) //data的高cnt位写入HT1621,高位在前
{
 unsigned char i;
 for(i =0; i <cnt; i ++)
 {
  if((data&0x80)==0) DAT0;
  else DAT1;
  WR0;
  _NOP();
  WR1;
  data<<=1;
 }
}
//******************************************************************************
void SendDataBit_1621(unsigned char data,unsigned char cnt) //data 的低cnt 位写入HT1621,低位在前
{
 unsigned char i;
 for(i =0; i <cnt; i ++)
 {
  if((data&0x01)==0) DAT0;
  else DAT1;
  WR0;
  _NOP();
  WR1;
  data>>=1;
 }
}

//******************************************************************************
void SendCmd(unsigned char command)
{
 CS0;
 SendBit_1621(0x80,3); //写入标志码"100"
 SendBit_1621(command,9); //写入9 位数据,其中前8 位为command 命令,最后1 位任意
 CS1;
}
//******************************************************************************
void Write_1621(unsigned char addr,unsigned char data)
{
 CS0;
 SendBit_1621(0xa0,3); //写入标志码"101"
 SendBit_1621(addr<<2,6); //写入6 位addr
 SendDataBit_1621(data,4); //写入data 的低4 位
 CS1;
}
//******************************************************************************
void WriteAll_1621(unsigned char addr,unsigned char *p,unsigned char cnt)
{
 unsigned char i;
 CS0;
 SendBit_1621(0xa0,3); //写入标志码"101"
 SendBit_1621(addr<<2,6); //写入6 位addr
for(i =0; i <cnt; i ++,p++) //连续写入数据
{
 SendDataBit_1621(*p,8);
}
CS1;
}
//******************************************************************************
void LcdInit(void)
{
  HT1621IO_DIR;
 //_pac=0; //将端口设为输出
 SendCmd(BIAS); //设置偏压和占空比
 SendCmd(SYSEN); //打开系统振荡器
 SendCmd(LCDON); //打开LCD 偏压发生器
 Write_1621(0x09,0x01); //在地址0x09 处写入数据0x01
}
//******************************************************************************
void main()
{WDTCTL = WDTPW + WDTHOLD;
 LcdInit();
 WriteAll_1621(0,a,5); //在起始地址为0,处连续写入5个字节数据
 //a为写入数据的起始地址,5 为写入的字节数
 SendCmd(LCDOFF); //关闭LCD 显示
}

【模块简介】

      [IMGA=0,absMiddle]http://www.microcontrol.cn/430images/LCD/DM128-1-04.gif[/IMGA]
                             
                               模块接口与尺寸

      用户可以在购前将自己的显示电路接口预先定义好。当模块拿到手后就可以连接使用。
[ 此贴最后由DC在2008-11-1 13:00:38编辑过 ]
[COLOR=#0000ff]欢迎发贴分享设计心得、开源DIY...[/COLOR]
Powered by LeadBBS 9.2 .
Page created in 0.1719 seconds with 6 queries.