|
液晶自然是3伏液晶片。HT1621是比较好的液晶驱动片子,**和泰出品,只要接上电源地,连接四个或三个控制信号线,就可以让液晶片显示了。HT1621的资料。
我连接了电源和地后,DATA、WR、CS、分别接到MSP4302452的P1:0、1、2脚。
//-----------------------------------------------------------------------------------------
//程序说明:MSP4302452 驱动HT1621B 48脚贴片封装,从而达到控制段显液晶的目的
//时 间:2012-3-8
//-----------------------------------------------------------------------------------------
#include <io430g2452.h>
#include <in430.h>
#include <stdio.h>
#define uint unsigned int
#define uchar unsigned char
#define NOP() __no_operation() //本句很重要是关于NOP在430里好不好用的问题
#define HT1621_CS BIT2 //LCD 引脚定义
#define HT1621_WR BIT1
#define HT1621_DAT BIT0
#define BIAS 0x52 //0b1000 0101 0010 1/3duty 4com
#define SYSDIS 0X00 //0b1000 0000 0000 关振系统荡器和LCD偏压发生器
#define SYSEN 0X02 //0b1000 0000 0010 打开系统振荡器
#define LCDOFF 0X04 //0b1000 0000 0100 关LCD偏压
#define LCDON 0X06 //0b1000 0000 0110 打开LCD偏压
#define XTAL 0x28 //0b1000 0010 1000 外部接时钟
#define RC256 0X30 //0b1000 0011 0000 内部时钟
#define TONEON 0X12 //0b1000 0001 0010 打开声音输出
#define TONEOFF 0X10 //0b1000 0001 0000 关闭声音输出
#define WDTDIS1 0X0A //0b1000 0000 1010 禁止看门狗
//-----------------------------------------------------------------------------------------
//函数名称:Delay()
//功 能:延时子程序
//-----------------------------------------------------------------------------------------
void Delay(uchar us) //5,7,9
{
while(--us);
}
//-----------------------------------------------------------------------------------------
//函数名称:DelayMS()
//功 能:延时子程序
//-----------------------------------------------------------------------------------------
void DelayMS(uint iMs)
{
uint i,j;
for(i=0;i<iMs;i++)
for(j=0;j<65;j++)
{
Delay(1);
}
}
//-----------------------------------------------------------------------------------------
//函数名称:Ht1621Wr_Data()
//功 能:写数据函数,cnt为传送数据位数,数据传送为低位在前
//-----------------------------------------------------------------------------------------
void Ht1621Wr_Data(uchar Data,uchar cnt)
{
uchar i;
for (i=0;i<cnt;i++)
{
P1OUT &= ~HT1621_WR;
NOP();
NOP();
NOP();
NOP();
if((Data & 0x80)==0x80)
{
P1OUT |=HT1621_DAT;
}
else
{
P1OUT &=~HT1621_DAT;
}
P1OUT |=HT1621_WR;
NOP();
NOP();
NOP();
NOP();
Data<<=1;
}
}
//-----------------------------------------------------------------------------------------
//函数名称:void Ht1621WrCmd(uchar Cmd)
//功能描述: HT1621命令写入函数
//参数说明:Cmd为写入命令数据
//说 明:写入命令标识位100
//-----------------------------------------------------------------------------------------
void Ht1621WrCmd(uchar Cmd)
{
P1OUT&=~HT1621_CS;
NOP();
NOP();
NOP();
NOP();
Ht1621Wr_Data(0x80,4); //写入命令标志100
Ht1621Wr_Data(Cmd,8); //写入命令数据
P1OUT |= HT1621_CS;
}
//-----------------------------------------------------------------------------------------
//函数名称:void Ht1621WrOneData(uchar Addr,uchar Data)
//功能描述: HT1621在指定地址写入数据函数
//参数说明:Addr为写入初始地址,Data为写入数据
//说 明:因为HT1621的数据位4位,所以实际写入数据为参数的后4位
//-----------------------------------------------------------------------------------------
void Ht1621WrOneData(uchar Addr,uchar Data)
{
P1OUT &=~HT1621_CS;
Ht1621Wr_Data(0xa0,3); //写入数据标志101
Ht1621Wr_Data(Addr<<2,6); //写入地址数据
Ht1621Wr_Data(Data<<4,4); //写入数据
P1OUT |= HT1621_CS;
}
//-----------------------------------------------------------------------------------------
//函数名称:void Ht1621WrAllData()
//功能描述: HT1621连续写入方式函数
//说 明:HT1621的数据位4位,此处每次数据为8位,写入数据总数按8位计算
//-----------------------------------------------------------------------------------------
void Ht1621WrAllData(void)
{
uchar i;
P1OUT &=~HT1621_CS;
Ht1621Wr_Data(0xa0,3); //写入数据标志101
Ht1621Wr_Data(0x00<<2,6); //写入地址数据
for (i=0;i<16;i++)
{
Ht1621Wr_Data(0x00,8); //写入数据
}
P1OUT |=HT1621_CS;
}
//-----------------------------------------------------------------------------------------
//函数名称:void Ht1621_Init(void)
//功能描述: HT1621初始化
//说 明:初始化后,液晶屏所有字段均显示
//-----------------------------------------------------------------------------------------
void Ht1621_Init(void)
{
P1OUT |=HT1621_CS;
P1OUT |=HT1621_WR;
P1OUT |=HT1621_DAT;
DelayMS(2000); //延时使LCD工作电压稳定
Ht1621WrCmd(BIAS);
Ht1621WrCmd(RC256); //使用内部振荡器
Ht1621WrCmd(SYSDIS);
Ht1621WrCmd(WDTDIS1);
Ht1621WrCmd(SYSEN);
Ht1621WrCmd(LCDON);
}
//-----------------------------------------------------------------------------------------
//函数名称:Initial()
//功 能:初始化子程序
//-----------------------------------------------------------------------------------------
void Initial(void)
{
WDTCTL = WDTPW + WDTHOLD;//关闭看门狗
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 1MHz
P1DIR=0xFF;
P1OUT=0xFF;
}
//-----------------------------------------------------------------------------------------
//函数名称:void Ht1621WrByteData(uchar address,uchar what)
//功 能:在指定的地址写入一个字节数,注意高字节先写,每次写入奇数地址
//-----------------------------------------------------------------------------------------
void Ht1621WrByteData(uchar address,uchar what)
{
P1OUT &=~HT1621_CS;
Ht1621Wr_Data(0xa0,3); //写入数据标志101
Ht1621Wr_Data(address<<2,6); //写入地址数据
Ht1621Wr_Data(what,8); //写入数据
P1OUT |=HT1621_CS;
}
//-----------------------------------------------------------------------------------------
//函数名称:main()
//功 能:主函数
//-----------------------------------------------------------------------------------------
void main(void)
{
uchar i,j,t;
Initial(); //初始化子程序
Ht1621_Init(); //上电初始化LCD
DelayMS(1000); //延时一段时间
Ht1621WrAllData();
//while(1)
{
Ht1621WrAllData();
for(i=0;i<16;i++) //SEG0-SEG31
{
t=0x01;
for(j=0;j<4;j++) //COM0 - COM3
{
Ht1621WrOneData(i,t);
t<<=1;
t++;
DelayMS(5000);
}
}
}
Ht1621WrAllData(); //清屏
Ht1621WrByteData(0x06,0x05); //显示101
Ht1621WrByteData(0x02,0x05);
Ht1621WrByteData(0x04,0xF5);
}
工程文件:
[size=0.83em]IMG_0083.JPG (3.24 MB, 下载次数: 0)
下载附件
2012-3-9 09:14 上传
|
|
|