📄 ht1621.h
字号:
/*********HT1621液晶段码显示**********
型号 : HT1621/HT1622
mcu : M48
crystal : 8.0000Mhz
作者 : Joe Yuan
日期 : 2007.03.25
**************************************/
#ifndef _HT1621_H
#define _HT1621_H
/**************************** HT1621端口定义 **********************/
/*
#define CS_PORT PORTC
#define CS1621 PC4
#define DT_PORT PORTD
#define WR_PORT PORTD
#define DT1621 PD4
#define WR1621 PD5
*/
//ATB-S10
/*
#define CS_PORT PORTC
#define CS1621 PC0
#define DT_PORT PORTC
#define WR_PORT PORTC
#define DT1621 PC2
#define WR1621 PC1
*/
#define CS_PORT PORTC
#define CS1621 PC1
#define DT_PORT PORTC
#define WR_PORT PORTC
#define DT1621 PC5
#define WR1621 PC4
Byte buf[32],disbuf[32];
//段码表常量数组
Byte const table[31]=
{
0xBE,/*0*/0x06,/*1*/0x7C,/*2*/0x5E,/*3*/0xC6,/*4*/
0xDA,/*5*/0xFA,/*6*/0x0E,/*7*/0xFE,/*8*/0xDE,/*9*/
0xEE,/*A*/0xF2,/*b*/0x70,/*C*/0x76,/*d*/0xF8,/*E*/
0xE8,/*F*/0xE2,/*h*/0xE6,/*H*/0x72,/*o*/0xEC,/*p*/
0xB0,/*L*/0x60,/*r*/0xD6,/*y*/0x40,/*-*/0x10,/*_*/
0x00,/* */
};
/*****************函数声明******************/
void Initrial_1621(void); //初始化1621
void Send_data8bit(Byte dat); //发送一个字节的数据
void Send_data(Byte num); //1621发送连续数据
void Send_command(Byte dat); //1621命令字发送
void Send_comand4bit(void); //1621命令字首4位(0b1000)发送
void Start_wr1621(void); //写1621初始化
void End_wr1621(void); //写结束
void Up_write(void); //写上升沿
void Send_data(Byte num); //num为发送的字节数
void Coding(Byte num); //译码子程序
void Setb_disbuf(void); //Disbuf[i]全置1
void Clr_disbuf(void); //Disbuf[i]清零
void Delay_1621(void);
void Changliang(void);
void Coding(Byte num) //译码子程序 功能:把buf[i]译码后给disbuf[i]
{ //num为段码的个数
Byte i;
for(i=0;i<num;i++)
{
/* ****连续连接方式******/
disbuf[i]=table[buf[i]];
/******隔段连接方式*****/
// disbuf[2*i]=table[buf[i]]&0xf0;
// disbuf[2*i+1]=table[buf[i]]<<4;
}
disbuf[5] |=0x01;
//disbuf[4] |=0x01;
}
void Clr_disbuf(void) //Disbuf[i]清零
{
Byte i;
for(i=0;i<16;i++)
disbuf[i]=0x00;
}
void Setb_disbuf(void) //Disbuf[i]全置1
{
Byte i;
for(i=0;i<16;i++)
disbuf[i]=0xff;
}
void Initrial_1621(void)
{
Send_command(0x52); //1/3 偏压4背极
Send_command(0x30); //系统时钟选用片内RC振荡器
Send_command(0x0A); //禁止WDT溢出标志输出
Send_command(0x08); //时基输出禁能
Send_command(0x02); //打开系统时钟
Send_command(0x06); //打开偏压发生器
}
void Send_data(Byte num) //num为发送的字节数
{
Byte i;
Start_wr1621(); //写初始化
DT_PORT |=BIT(DT1621); //先发1
Up_write (); //写上升沿
Send_data8bit(0x40); //发送01+6位首地址00
for(i=0;i<num;i++) //发送连续的数据
Send_data8bit(disbuf[i]);
End_wr1621(); //写结束
}
void Send_command(Byte command_dat)//1621命令字发送
{
Byte i,dat=0x80;
Start_wr1621(); //写初始化
for(i=0;i<4;i++)
{
if(dat&0x80)
DT_PORT|=BIT(DT1621);
else
DT_PORT&=~BIT(DT1621);
Up_write();
dat<<=1;
}
Send_data8bit(command_dat);
End_wr1621(); //写结束
}
void Send_data8bit(Byte dat)
{
Byte i;
for(i=0;i<8;i++)
{
if(dat&0x80)
DT_PORT|=BIT(DT1621);
else
DT_PORT&=~ BIT(DT1621);
Up_write();
dat<<=1;
}
}
void Start_wr1621(void) //写1621初始化
{
CS_PORT|=BIT(CS1621);
WR_PORT|=BIT(WR1621);
Delay_1621();
CS_PORT&=~ BIT(CS1621);
Delay_1621();
WR_PORT&=~ BIT(WR1621);
Delay_1621();
}
void End_wr1621(void) //写结束
{
WR_PORT |=BIT(WR1621);
Delay_1621();
CS_PORT |=BIT(CS1621);
Delay_1621();
DT_PORT |=BIT(DT1621);
}
void Up_write(void) //写上升沿
{
WR_PORT &=~ BIT(WR1621);
Delay_1621();
WR_PORT |=BIT(WR1621);
Delay_1621();
}
void Delay_1621(void)
{
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -