#include"ht1621.h"
#include"msp430x21x1.h"
#include "data_math.h"
//----------------------------------------------------------------
//段码表
//----------------------------------------------------------------
//0x01---> h
//0x08---> a
//0x04---> b
//0x02---> c
//0x10---> d
//0x20---> e
//0x40---> g
//0x80---> f
//-----------------------------------------------------------------
//字符表: 0,1,2,3,4,5,6,7,8,9,A,b,C,c,d,E,F,H,L,N,n,o,P,q,r,S,U,u,y
//-----------------------------------------------------------------
const unsigned char lcd_data[32]={ //用户自定义LCD缓冲区
0xbe,/*0*/ //a+b+c+d+e+f --> 0
0x06,/*1*/ //b+c --> 1
0x7c,/*2*/ //a+b+g+e+d --> 2
0x5e,/*3*/ //a+b+g+c+d --> 3
0xc6,/*4*/ //f+g+b+c --> 4
0xda,/*5*/ //a+f+g+c+d --> 5
0xfa,/*6*/ //a+f+g+d+e+c --> 6
0x0e,/*7*/ //a+b+c --> 7
0xfe,/*8*/ //a+b+c+d+e+f+g --> 8
0xde,/*9*/ //a+b+c+d+f+g --> 9
0xee,/*A*/ // a+b+c+f+e+g --> 10
0xf2,/*b*/ // f+e+d+c+g --> 11
0xb8,/*C*/ // a+f+e+d --> 12
0x70,/*c*/ // g+e+d --> 13
0x76,/*d*/ // b+g+e+d+c --> 14
0xf8,/*E*/ // a+f+g+e+d --> 15
0xe8,/*F*/ // a+f+g+e --> 16
0xe6,/*H*/ // b+c+f+e+g --> 17
0xb0,/*L*/ // f+e+d --> 18
0xae,/*N*/ // a+b+c+e+f --> 19
0x62,/*n*/ // c+e+g --> 20
0x72,/*o*/ // c+d+e+g --> 21
0xec,/*P*/ // a+b+f+g+e --> 22
0xce,/*q*/ // a+b+c+f+g --> 23
0x60,/*r*/ // e+g --> 24
0xda,/*S*/ // a+f+g+c+d --> 25
0xf0,/*t*/ // f+g+e+d --> 26
0xb6,/*U*/ // f+e+d+c+b --> 27
0x32,/*u*/ // e+d+c --> 28
0xd6,/*y*/ // f+g+b+c+d --> 29
0x40, /*-*/ // g --> 30
0x00 /* */ // --> 31
};
void lcdwbit(unsigned char n) //写入一个位
{
_NOP();
LCDDATA =n;
_NOP();
LCDCLK =1;
_NOP();
_NOP();
LCDCLK =0; //一个上升沿写入
_NOP();
_NOP();
LCDCLK =1;
_NOP();
_NOP();
}
//非连续命令
void lcdwc(unsigned char cmdcode) //送命令字
{
unsigned char i;
//__bic_SR_register(GIE);
LCDCS =1; //在不连续命令模式,/CS 应设为1
_NOP();
_NOP();
LCDCS =0;
lcdwbit(1); //写入100发送指令模式
lcdwbit(0);
lcdwbit(0);
for (i=0;i<8;i++)
{ if((cmdcode&0x80)==0x80) //先高后低
lcdwbit(1);
else
lcdwbit(0);
cmdcode <<=1;
}
lcdwbit(0); //最后一位是0是1都可以
LCDDATA =1;
_NOP();
LCDCS =1;
_NOP();
//__bis_SR_register(GIE);
}
//
void lcdreset() //初始化
{
lcdwc(SYS_DIS); //掉电
lcdwc(LCD_OFF); //关闭偏压发生器
lcdwc(SYS_EN); //打开系统振荡器
lcdwc(CMDB3C4); //模式设置
lcdwc(LCD_ON); //打开LCD 偏压发生器
lcdwc(TONE_4K);
}
// 多字节写入
void lcdmwd(unsigned char address, unsigned char* data1,unsigned char data2,unsigned char n,unsigned char flg) //送6位地址+8位数据
{
unsigned char i,j,temp_data;
//__bic_SR_register(GIE);
LCDCS =1;
_NOP();
_NOP();
LCDCS =0;
_NOP();
_NOP();
lcdwbit(1); //写入101写数据模式
lcdwbit(0);
lcdwbit(1);
address<<=2; //移出高两位
for (i=0;i<6;i++) //由高位到低位(地址)
{ if((address&0x80)==0x80)
lcdwbit(1);
else
lcdwbit(0);
address<<=1;
_NOP();
}
for(j=0;j<n;j++)
{
if(flg==1)
temp_data =data2;
else
temp_data = *(data1+j);
for (i=0;i<8;i++) //由低位到高位(数据)
{ if((temp_data&0x01)==0x01)
lcdwbit(1);
else
lcdwbit(0);
temp_data>>=1;
}
_NOP();
}
LCDDATA =1;
_NOP();
LCDCS =1;
_NOP();
_NOP();
// __bis_SR_register(GIE);
}
void const_write(unsigned char addr,unsigned char* point,unsigned char n)
{
lcdmwd(addr,point,0,n,0);
}
void data_write(unsigned char addr,unsigned char reg_data,unsigned char n)
{
lcdmwd(addr,(unsigned char*)0x1000,reg_data,n,1);
}
void delay(unsigned int t) // 延时子程序
{ unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10;j++)
_NOP();
}