ATmega16 HT1621B驱动程序
扫描二维码
随时随地手机看文章
#defineucharunsignedchar
#defineuintunsignedint
//定义HT1621的命令
#defineComMode0x52//4COM,1/3bias100001010010
#defineRCosc0x30//内部RC振荡器(上电默认)100000110000
#defineLCD_on0x06//打开LCD偏压发生器100000000110
#defineLCD_off0x04//关闭LCD显示
#defineSys_en0x02//系统振荡器开100000000010
#defineCTRl_cmd0x80//写控制命令
#defineData_cmd0xa0//写数据命令
//定义端口HT1621数据端口
#defineWR1sbi(PORTD,7)
#defineWR0cbi(PORTD,7)
#defineDATA1sbi(PORTD,6)
#defineDATA0cbi(PORTD,6)
#defineCS1sbi(PORTC,0)
#defineCS0cbi(PORTC,0)
#defineZA10
#defineZB11
#defineZC12
#defineZD13
#defineZE14
#defineZF15
#defineH16
#defineL17
#defineT18
#defineN19
#defineSUBB20
#defineP21
#defineR22
#defineNO23
constcharnum[]={0x5f,0x06,0x6b,0x2f,0x36,0x3d,0x7d,0x07,0x7f,0x3f,
//0123456789
0x77,0x7c,0x59,0x6e,0x79,0x71,0x76,0x58,0x51,0x57,0x20,0x73,0x60,0x00,
//ABCDEFHLTN-PRNO
};
ucharSMG1=0;//1号数码管
ucharSMG2=0;//2号数码管
ucharSMG3=0;//3号数码管
ucharSMG4=0;//4号数码管
ucharSMG5=0;//5号数码管
ucharSMG6=0;//6号数码管
ucharSIGN1=0;//标志1
ucharSIGN2=0;//标志2
#defineADD_SMG10x0
#defineS1(SMG1&0x80)
#defineS1_ON(SMG1|=0x80)//标志S1"ON"
#defineS1_OFF(SMG1&=0x7f)
#defineADD_SMG20x02
#defineS2(SMG2&0x80)
#defineS2_ON(SMG2|=0x80)//标志S2"OFF"
#defineS2_OFF(SMG2&=0x7f)
#defineADD_SMG30x04//数码管3的地址00010000
#defineCOL(SMG3&0x80)
#defineCOL_ON(SMG3|=0x80)//标志COL":"
#defineCOL_OFF(SMG3&=0x7f)
#defineADD_SMG40x06//数码管4的地址00011000
#defineADD_SMG50x0a//数码管5的地址00101000
#defineS14(SMG5&0x80)
#defineS14_ON(SMG5|=0x80)//标志S14
#defineS14_OFF(SMG5&=0x7f)
#defineADD_SMG60x0c
#defineS15(SMG6&0x80)
#defineS15_ON(SMG6|=0x80)//标志S15,除霜标志
#defineS15_OFF(SMG6&=0x7f)
#defineADD_SIGN10x08//标志1
#defineADD_SIGN20x0e//标志2
#defineS13_ON(SIGN1|=0x80)//标志S13,加热的中心标志
#defineS13_OFF(SIGN1&=0x7f)
#defineS10_ON(SIGN1|=0x40)//标志S10
#defineS10_OFF(SIGN1&=0xbf)
#defineS5_ON(SIGN1|=0x20)//标志S5
#defineS5_OFF(SIGN1&=0xdf)
#defineS11_ON(SIGN1|=0x10)//标志S11
#defineS11_OFF(SIGN1&=0xef)
#defineS9_ON(SIGN1|=0x08)//标志S9
#defineS9_OFF(SIGN1&=0xf7)
#defineS8_ON(SIGN1|=0x04)//标志S8
#defineS8_OFF(SIGN1&=0xfb)
#defineS7_ON(SIGN1|=0x02)//标志S7
#defineS7_OFF(SIGN1&=0xfd)
#defineS6_ON(SIGN1|=0x01)//标志S6,S5-S11风扇旋转标志
#defineS6_OFF(SIGN1&=0xfe)
/***************************************************************/
#defineS20_ON(SIGN2|=0x80)//标志S20,"LOCk"标志
#defineS20_OFF(SIGN2&=0x7f)
#defineS12_ON(SIGN2|=0x40)//标志S12,摄氏度标志
#defineS12_OFF(SIGN2&=0xbf)
#defineS4_ON(SIGN2|=0x20)//标志S4,"Warm"标志
#defineS4_OFF(SIGN2&=0xdf)
#defineS3_ON(SIGN2|=0x10)//标志S3,"Time"标志
#defineS3_OFF(SIGN2&=0xef)
#defineS19_ON(SIGN2|=0x08)//标志S19
#defineS19_OFF(SIGN2&=0xf7)
#defineS18_ON(SIGN2|=0x04)//标志S18
#defineS18_OFF(SIGN2&=0xfb)
#defineS17_ON(SIGN2|=0x02)//标志S17
#defineS17_OFF(SIGN2&=0xfd)
#defineS16_ON(SIGN2|=0x01)//标志S16,S16-s19,加热标志
#defineS16_OFF(SIGN2&=0xfe)
/**-------------------------------------------------------------------------
Name:SendBit_1621(送数据程序)
---------------------------------------------------------------------------*/
voidSendBit_1621(ucharsdata,ucharcnt)//data的高cnt位写入HT1621,高位在前
{
uchari;
for(i=0;i{
WR0;
if(sdata&0x80)DATA1;
elseDATA0;
WR1;
sdata<<=1;
}
}
/**-------------------------------------------------------------------------
Name:SendCmd(送命令)
---------------------------------------------------------------------------*/
voidSendCmd_1621(ucharcommand)
{
CS0;
SendBit_1621(0x80,4);//写入标志码“100”和9位command命令,由于
SendBit_1621(command,8);//没有使有到更改时钟输出等命令,为了编程方便
CS1;//直接将command的最高位写“0”
}
/**-------------------------------------------------------------------------
Name:Write_1621(送数据和命令程序)
---------------------------------------------------------------------------*/
voidWrite_1621(ucharaddr,ucharsdata)
{
addr<<=2;
CS0;
SendBit_1621(0xa0,3);//写入标志码“101”
SendBit_1621(addr,6);//写入addr的高6位
SendBit_1621(sdata,8);//写入data的8位
CS1;
}
/**-------------------------------------------------------------------------
Name:all_off(清除1621显示)
---------------------------------------------------------------------------*/
voidHT1621_all_off(void)
{uchari;
ucharaddr=0;
for(i=0;i<8;i++)
{
Write_1621(addr,0x00);
addr+=2;
}
}
/****************************************************************************
Name:all_on(全部点亮1621)
****************************************************************************/
voidHT1621_all_on(void)
{uchari;
ucharaddr=0;
for(i=0;i<8;i++)
{
Write_1621(addr,0xff);
addr+=2;
}
}
/****************************************************************************
Name:Init_1621(初始化1621)
*****************************************************************************/
voidInit_1621(void)
{
SendCmd_1621(Sys_en);
SendCmd_1621(RCosc);
SendCmd_1621(ComMode);
SendCmd_1621(LCD_on);
}
/****************************************************************************
Name:LCDon(初始化1621)
*****************************************************************************/
voidLCDoff(void)
{
SendCmd_1621(LCD_off);
}
/****************************************************************************
Name:LCDon(初始化1621)
*****************************************************************************/
voidLCDon(void)
{
SendCmd_1621(LCD_on);
}
/**-------------------------------------------------------------------------
Name:sun_turn1(太阳旋转标志处理)
--------------------------------------------------------------------------**/
voidsun_turn1(void)
{
S6_ON;S8_ON;S10_ON;S7_OFF;S9_OFF;S11_OFF;
}
/**-------------------------------------------------------------------------
Name:sun_turn2(太阳旋转标志处理)
--------------------------------------------------------------------------**/
voidsun_turn2(void)
{
S7_ON;S9_ON;S11_ON;S6_OFF;S8_OFF;S10_OFF;
}
/**-------------------------------------------------------------------------
Name:sun_turn12off(太阳旋转标志处理)
--------------------------------------------------------------------------**/
voidsun_turn12off(void)
{
S6_OFF;S8_OFF;S10_OFF;S7_OFF;S9_OFF;S11_OFF;S5_OFF;
}
/**-------------------------------------------------------------------------
Name:burn1(燃烧标志处理)
--------------------------------------------------------------------------**/
voidburn1(void)
{
S16_ON;S18_ON;S17_OFF;S19_OFF;
}
/**-------------------------------------------------------------------------
Name:burn2(燃烧标志处理)
--------------------------------------------------------------------------**/
voidburn2(void)
{
S16_OFF;S18_OFF;S17_ON;S19_ON;
}
/**-------------------------------------------------------------------------
Name:burn12off(燃烧标志处理)
--------------------------------------------------------------------------**/
voidburn12off(void)
{
S16_OFF;S18_OFF;S17_OFF;S19_OFF;
}
/**-------------------------------------------------------------------------
Name:Disp_RSTS();
--------------------------------------------------------------------------**/
voidDisp_RSTS(void)
{
SMG1=R;SMG2=5;SMG3=T;SMG4=5;
}
/**-------------------------------------------------------------------------
Name:Disp_RS__();
--------------------------------------------------------------------------**/
voidDisp_RS__(void)
{
SMG1=R;SMG2=5;SMG3=SUBB;SMG4=SUBB;
}
/**-------------------------------------------------------------------------
Name:Disp_CSTS();
--------------------------------------------------------------------------**/
voidDisp_CSTS(void)
{
SMG1=ZC;SMG2=5;SMG3=T;SMG4=5;
}
/**-------------------------------------------------------------------------
Name:Disp_CSOS();
--------------------------------------------------------------------------**/
voidDisp_CSOS(void)
{
SMG1=ZC;SMG2=5;SMG3=0;SMG4=5;
}
/**-------------------------------------------------------------------------
Name:Disp_ENTE();
--------------------------------------------------------------------------**/
voidDisp_ENTE(void)
{
SMG1=ZE;SMG2=N;SMG3=T;SMG4=ZE;
}
/**-------------------------------------------------------------------------
Name:Disp_ONOF();
--------------------------------------------------------------------------**/
voidDisp_ONOF(void)
{
SMG1=0;SMG2=N;SMG3=0;SMG4=ZF;
}
/**-------------------------------------------------------------------------
Name:Disp_HTTS();
--------------------------------------------------------------------------**/
voidDisp_HTTS(void)
{
SMG1=H;SMG2=T;SMG3=T;SMG4=5;
}
/**-------------------------------------------------------------------------
Name:Disp_CSTC();
--------------------------------------------------------------------------**/
voidDisp_CSTC(void)
{
SMG1=ZC;SMG2=5;SMG3=T;SMG4=ZC;
}
/**-------------------------------------------------------------------------
Name:Disp_STS8();
--------------------------------------------------------------------------**/
voidDisp_STS8(void)
{
SMG1=5;SMG2=T;SMG3=5;SMG4=8;
}
/**-------------------------------------------------------------------------
Name:Disp_08__();
--------------------------------------------------------------------------**/
voidDisp_08__(void)
{
SMG1=0;SMG2=8;SMG3=SUBB;SMG4=SUBB;
}
/**-------------------------------------------------------------------------
Name:Disp_10__();
--------------------------------------------------------------------------**/
voidDisp_10__(void)
{
SMG1=SUBB;SMG2=SUBB;SMG3=1;SMG4=0;
}
/**-------------------------------------------------------------------------
Name:Disp_DONH();
--------------------------------------------------------------------------**/
voidDisp_DONH(void)
{
SMG1=ZD;SMG2=0;SMG3=N;SMG4=H;
}
/**-------------------------------------------------------------------------
Name:Disp_DONF();
--------------------------------------------------------------------------**/
voidDisp_DONF(void)
{
SMG1=ZD;SMG2=0;SMG3=N;SMG4=ZF;
}
/**-------------------------------------------------------------------------
Name:Disp_DOFH();
--------------------------------------------------------------------------**/
voidDisp_DOFH(void)
{
SMG1=ZD;SMG2=0;SMG3=ZF;SMG4=H;
}
/**-------------------------------------------------------------------------
Name:Disp_DOFF();
--------------------------------------------------------------------------**/
voidDisp_DOFF(void)
{
SMG1=ZD;SMG2=0;SMG3=ZF;SMG4=ZF;
}
/**-------------------------------------------------------------------------
Name:Disp_LOCT();
--------------------------------------------------------------------------**/
voidDisp_LOCT(void)
{
SMG1=L;SMG2=0;SMG3=ZC;SMG4=T;
}
/**-------------------------------------------------------------------------
Name:Disp_ES();
--------------------------------------------------------------------------**/
voidDisp_ES(void)
{
SMG5=ZE;SMG6=5;
}
/**-------------------------------------------------------------------------
Name:Disp_EL();
--------------------------------------------------------------------------**/
voidDisp_EL(void)
{
SMG5=ZE;SMG6=L;
}
/**-------------------------------------------------------------------------
Name:Disp_EH();
--------------------------------------------------------------------------**/
voidDisp_EH(void)
{
SMG5=ZE;SMG6=H;
}
/**-------------------------------------------------------------------------
Name:Disp_EE();
--------------------------------------------------------------------------**/
voidDisp_EE(void)
{
SMG5=ZE;SMG6=ZE;
}
/**-------------------------------------------------------------------------
Name:Disp_NND();
--------------------------------------------------------------------------**/
voidDisp_NND(void)
{
SMG1=NO;SMG2=NO;SMG3=ZD;
}
/**-------------------------------------------------------------------------
Name:Disp_on();
--------------------------------------------------------------------------**/
voidDisp_on(void)
{
SMG5=0;SMG6=N;
}
/**-------------------------------------------------------------------------
Name:Disp_of();
--------------------------------------------------------------------------**/
voidDisp_of(void)
{
SMG5=0;SMG6=ZF;
}
/**-------------------------------------------------------------------------
Name:Disp_pb_t();
--------------------------------------------------------------------------**/
voidDisp_pb_t(void)
{
SMG1=P;SMG2=ZB;SMG3=SUBB;SMG4=T;
}
/**-------------------------------------------------------------------------
Name:Disp_PP();
--------------------------------------------------------------------------**/
voidDisp_PP(void)
{
SMG5=P;SMG6=P;
}