|
#include<avr/io.h>
#include<util/delay.h>
#define uchar unsigned char
#define uint unsigned int
//系统宏定义
#define BIAS 0x52 //0b100001010010 1/3duty 4com
//#define BIAS 0x42 //0b100001001010 1/3duty 3com
//#define BIAS 0x4a //0b100001010010 1/3duty 2com
#define SYSDIS 0x00 //关振系统荡振器和LCD偏压发生器
#define SYSEN 0x02 //打开系统振荡漾器
#define LCDOFF 0x04 //关LCD偏压
#define LCDON 0x06 //
#define XTAL 0x28 //外接时钟
#define RC256 0x30 //内部时钟
#define TONEON 0x12 //打开声音
#define TONEOFF 0x10 //关闭声音
#define WDTDIS 0x0a //禁止看门狗
//引脚置高
#define WR_HIGH PORTC|=(1<<PC2)
#define CS_HIGH PORTC|=(1<<PC1)
#define DA_HIGH PORTC|=(1<<PC0)
//引脚置低
#define WR_LOW PORTC&=~(1<<PC2)
#define CS_LOW PORTC&=~(1<<PC1)
#define DA_LOW PORTC&=~(1<<PC0)
const uchar HT1621Tab[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/***********************************************************
* 函数说明:HT1621写一个字节数据 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:_delay_us(int) *
***********************************************************/
void HT1621Write_Data(uchar Data,uchar cnt)
{
uchar i;
for(i=0;i<cnt;i++)
{
WR_LOW;
_delay_us(10);
if(Data&0x80)
{DA_HIGH;}
else
DA_LOW;
_delay_us(10);
WR_HIGH;
_delay_us(10);
Data<<=1;
}
}
/***********************************************************
* 函数说明:HT1621写命令 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:HT1621write_data(uchar add,uchar data) *
_delay_us(int) *
***********************************************************/
void HT1621Write_Cmd(uchar Cmd)
{
CS_LOW;
_delay_us(10);
HT1621Write_Data(0x80,4);
HT1621Write_Data(Cmd,8);
CS_HIGH;
_delay_us(10);
}
/***********************************************************
* 函数说明:HT1621写数据 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:HT1621write_data(uchar add,uchar data) *
_delay_us(int) *
***********************************************************/
void HT1621Write0neData(uchar Addr,uchar Data)
{
CS_LOW;
HT1621Write_Data(0xa0,3);
HT1621Write_Data(Addr<<2,6);
HT1621Write_Data(Data<<4,4);
CS_HIGH;
_delay_us(10);
}
/***********************************************************
* 函数说明:HT1621全部点亮 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:HT1621write_data(uchar add,uchar data) *
_delay_us(int) *
***********************************************************/
void HT1621BWrite_AllData(uchar Addr,uchar *p,uchar cnt)
{
uchar i;
CS_LOW;
HT1621Write_Data(0xa0,3);
HT1621Write_Data(Addr<<2,6);
for(i=0;i<cnt;i++)
{
HT1621Write_Data(*p,8);
p++;
}
CS_HIGH;
_delay_us(10);
}
/***********************************************************
* 函数说明:HT1621 初始化 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:HT1621write_Cmd(Cmd) *
_delay_ms(int) *
***********************************************************/
void HT1621B_Init()
{
CS_HIGH;
WR_HIGH;
DA_HIGH;
_delay_ms(2000);
HT1621Write_Cmd(BIAS);
HT1621Write_Cmd(RC256); //内部时钟
HT1621Write_Cmd(SYSDIS); //关振系统荡振器和LCD偏压发生器
HT1621Write_Cmd(WDTDIS); //禁止看门狗
HT1621Write_Cmd(SYSEN); //打开系统振荡漾器
HT1621Write_Cmd(LCDON); //关LCD偏压
HT1621Write_Cmd(0x12);
_delay_ms(1000);
HT1621Write_Cmd(0x10);
}
int main()
{
uchar i,j,t;
DDRC=0xFF;
HT1621B_Init();
while(1)
{
HT1621BWrite_AllData(0,HT1621Tab,16);
for(i=0;i<32;i++)
{
t=0x01;
for(j=0;j<4;j++)
{
HT1621Write0neData(i,t);
t<<=1;
t++;
_delay_ms(100);
}
}
}
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|