技术文章

HT1621B的驱动程序---AVR

      
 

  

#define uchar   unsigned char
#define uint   unsigned int
//定义HT1621的命令
#define  ComMode    0x52  //4COM,1/3bias  1000    010 1001  0
#define  RCosc      0x30  //内部RC振荡器(上电默认)1000 0011 0000
#define  LCD_on     0x06  //打开LCD 偏压发生器1000     0000 0 11 0
#define  LCD_off    0x04  //关闭LCD显示
#define  Sys_en     0x02  //系统振荡器开 1000   0000 0010
#define  Ctrl_cmd   0x80  //写控制命令
#define  Data_cmd   0xa0  //写数据命令  

//定义端口HT1621数据端口
#define WR1      sbi(PORTD, 7)
#define WR0      cbi(PORTD, 7)
#define DATA1    sbi(PORTD, 6)
#define DATA0    cbi(PORTD, 6)
#define CS1      sbi(PORTC, 0)
#define CS0      cbi(PORTC, 0)
#define  ZA      10
#define  ZB      11
#define  ZC      12
#define  ZD      13
#define  ZE      14
#define  ZF      15
#define  H       16
#define  L       17
#define  T       18
#define  N       19
#define  SUBB    20
#define  P       21
#define  R       22
#define  NO      23
const char num[]={0x5f,0x06,0x6b,0x2f,0x36,0x3d,0x7d,0x07,0x7f,0x3f,
                   //0    1    2    3    4    5     6   7    8     9
               0x77,0x7c,0x59,0x6e,0x79,0x71,0x76,0x58,0x51,0x57,0x20,0x73,0x60,0x00,
             // A    B     C    D    E    F    H    L    T    N    -    P     R   NO
                   };
uchar        SMG1=0;    //1号数码管
uchar        SMG2=0;    //2号数码管
uchar        SMG3=0;    //3号数码管
uchar        SMG4=0;    //4号数码管
uchar        SMG5=0;    //5号数码管
uchar        SMG6=0;    //6号数码管
uchar        SIGN1=0;   //标志1
uchar        SIGN2=0;   //标志2
#define      ADD_SMG1     0x0
#define      S1           (SMG1&0x80)               
#define      S1_ON        (SMG1|=0x80)   //标志S1"ON"
#define      S1_OFF       (SMG1&=0x7f)

#define      ADD_SMG2     0x02
#define      S2           (SMG2&0x80)
#define      S2_ON        (SMG2|=0x80)   //标志S2"OFF"
#define      S2_OFF       (SMG2&=0x7f)

#define      ADD_SMG3     0x04               //数码管3的地址00 010000
#define      COL          (SMG3&0x80)
#define      COL_ON       (SMG3|=0x80)       //标志COL":"
#define      COL_OFF      (SMG3&=0x7f)

#define      ADD_SMG4      0x06              //数码管4的地址  00 01 1000

#define      ADD_SMG5      0x0a              //数码管5的地址0010 1000
#define      S14           (SMG5&0x80)
#define      S14_ON        (SMG5|=0x80)      //标志S14
#define      S14_OFF       (SMG5&=0x7f)

#define      ADD_SMG6       0x0c
#define      S15           (SMG6&0x80)
#define      S15_ON        (SMG6|=0x80)      //标志S15,除霜标志
#define      S15_OFF       (SMG6&=0x7f)

#define      ADD_SIGN1      0x08             //标志1
#define      ADD_SIGN2      0x0e  //标志2

#define      S13_ON        (SIGN1|=0x80)  //标志S13,加热的中心标志
#define      S13_OFF       (SIGN1&=0x7f)

#define      S10_ON        (SIGN1|=0x40)  //标志S10
#define      S10_OFF       (SIGN1&=0xbf)

#define      S5_ON         (SIGN1|=0x20)  //标志S5
#define      S5_OFF        (SIGN1&=0xdf)

#define      S11_ON        (SIGN1|=0x10)  //标志S11
#define      S11_OFF       (SIGN1&=0xef)

#define      S9_ON         (SIGN1|=0x08)  //标志S9
#define      S9_OFF        (SIGN1&=0xf7)

#define      S8_ON         (SIGN1|=0x04)  //标志S8
#define      S8_OFF        (SIGN1&=0xfb)

#define      S7_ON         (SIGN1|=0x02)  //标志S7
#define      S7_OFF        (SIGN1&=0xfd)

#define      S6_ON         (SIGN1|=0x01)  //标志S6,S5-S11风扇旋转标志
#define      S6_OFF        (SIGN1&=0xfe)
/***************************************************************/
#define      S20_ON        (SIGN2|=0x80)  //标志S20,"Lock"标志
#define      S20_OFF       (SIGN2&=0x7f)

#define      S12_ON        (SIGN2|=0x40)  //标志S12,摄氏度标志
#define      S12_OFF       (SIGN2&=0xbf)

#define      S4_ON         (SIGN2|=0x20)  //标志S4,"Warm"标志
#define      S4_OFF        (SIGN2&=0xdf)

#define      S3_ON         (SIGN2|=0x10)  //标志S3,"Time"标志
#define      S3_OFF        (SIGN2&=0xef)

#define      S19_ON        (SIGN2|=0x08)  //标志S19
#define      S19_OFF       (SIGN2&=0xf7)

#define      S18_ON        (SIGN2|=0x04)  //标志S18
#define      S18_OFF       (SIGN2&=0xfb)

#define      S17_ON        (SIGN2|=0x02)  //标志S17
#define      S17_OFF       (SIGN2&=0xfd)

#define      S16_ON        (SIGN2|=0x01)  //标志S16,S16-s19,加热标志
#define      S16_OFF       (SIGN2&=0xfe)

/**-------------------------------------------------------------------------
                  Name: SendBit_1621(送数据程序)
---------------------------------------------------------------------------*/
void SendBit_1621(uchar sdata,uchar cnt) //data 的高cnt 位写入HT1621,高位在前
{
 uchar i;
 for(i=0;i
                      {
                  WR0;
                       if(sdata&0x80) DATA1;
                       else DATA0;
                       WR1;
                       sdata<<=1;
                       }
}
/**-------------------------------------------------------------------------
                  Name: SendCmd(送命令)
---------------------------------------------------------------------------*/
void SendCmd_1621(uchar command)
{
CS0;
SendBit_1621(0x80,4);    //写入标志码“100”和9 位command 命令,由于
SendBit_1621(command,8); //没有使有到更改时钟输出等命令,为了编程方便
CS1;                     //直接将command 的*高位写“0”
}
/**-------------------------------------------------------------------------
                  Name: Write_1621(送数据和命令程序)
---------------------------------------------------------------------------*/
void Write_1621(uchar addr,uchar sdata)
{
 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显示)
---------------------------------------------------------------------------*/
void HT1621_all_off(void)
{ uchar i;
  uchar addr=0;
  for(i=0;i<8;i++)
                 {
                   Write_1621(addr,0x00);
               addr+=2;
              }
}
/****************************************************************************
                          Name: all_on(全部点亮1621)
****************************************************************************/
void HT1621_all_on(void)
{ uchar i;
  uchar addr=0;
  for(i=0;i<8;i++)
                 {
                   Write_1621(addr,0xff);
               addr+=2;
              }
}

/****************************************************************************
                          Name: Init_1621(初始化1621)
*****************************************************************************/
void Init_1621(void)
{
 SendCmd_1621(Sys_en);
 SendCmd_1621(RCosc);   
 SendCmd_1621(ComMode); 
 SendCmd_1621(LCD_on); 
}
/****************************************************************************
                          Name: LCDon(初始化1621)
*****************************************************************************/
void LCDoff(void)

 SendCmd_1621(LCD_off); 
}
/****************************************************************************
                          Name: LCDon(初始化1621)
*****************************************************************************/
void LCDon(void)

 SendCmd_1621(LCD_on); 
}
/**-------------------------------------------------------------------------
                          Name: sun_turn1(太阳旋转标志处理)
--------------------------------------------------------------------------**/
void  sun_turn1(void)
{
 S6_ON;S8_ON;S10_ON;  S7_OFF;S9_OFF;S11_OFF;
}

/**-------------------------------------------------------------------------
                          Name: sun_turn2(太阳旋转标志处理)
--------------------------------------------------------------------------**/
void  sun_turn2(void)
{
 S7_ON;S9_ON;S11_ON;  S6_OFF;S8_OFF;S10_OFF;  
}

/**-------------------------------------------------------------------------
                          Name: sun_turn12off(太阳旋转标志处理)
--------------------------------------------------------------------------**/
void  sun_turn12off(void)
{
 S6_OFF;S8_OFF;S10_OFF;S7_OFF;S9_OFF;S11_OFF;S5_OFF;
}

/**-------------------------------------------------------------------------
                          Name: burn1(燃烧标志处理)
--------------------------------------------------------------------------**/
void  burn1(void)
{
 S16_ON;S18_ON;S17_OFF;S19_OFF;
}
/**-------------------------------------------------------------------------
                          Name: burn2(燃烧标志处理)
--------------------------------------------------------------------------**/
void  burn2(void)
{
 S16_OFF;S18_OFF;S17_ON;S19_ON;
}
/**-------------------------------------------------------------------------
                          Name: burn12off(燃烧标志处理)
--------------------------------------------------------------------------**/
void  burn12off(void)
{
 S16_OFF;S18_OFF;S17_OFF;S19_OFF;
}

/**-------------------------------------------------------------------------
                          Name: Disp_RSTS();
--------------------------------------------------------------------------**/
void  Disp_RSTS(void)
{
 SMG1=R;SMG2=5;SMG3=T;SMG4=5;
}
/**-------------------------------------------------------------------------
                          Name: Disp_RS__();
--------------------------------------------------------------------------**/
void  Disp_RS__(void)
{
 SMG1=R;SMG2=5;SMG3=SUBB;SMG4=SUBB;
}
/**-------------------------------------------------------------------------
                          Name: Disp_CSTS();
--------------------------------------------------------------------------**/
void  Disp_CSTS(void)
{
 SMG1=ZC;SMG2=5;SMG3=T;SMG4=5;
}
/**-------------------------------------------------------------------------
                          Name: Disp_CSOS();
--------------------------------------------------------------------------**/
void  Disp_CSOS(void)
{
 SMG1=ZC;SMG2=5;SMG3=0;SMG4=5;
}
/**-------------------------------------------------------------------------
                          Name: Disp_ENTE();
--------------------------------------------------------------------------**/
void  Disp_ENTE(void)
{
 SMG1=ZE;SMG2=N;SMG3=T;SMG4=ZE;
}
/**-------------------------------------------------------------------------
                          Name: Disp_ONOF();
--------------------------------------------------------------------------**/
void  Disp_ONOF(void)
{
 SMG1=0;SMG2=N;SMG3=0;SMG4=ZF;
}
/**-------------------------------------------------------------------------
                          Name: Disp_HTTS();
--------------------------------------------------------------------------**/
void  Disp_HTTS(void)
{
 SMG1=H;SMG2=T;SMG3=T;SMG4=5;
}
/**-------------------------------------------------------------------------
                          Name: Disp_CSTC();
--------------------------------------------------------------------------**/
void  Disp_CSTC(void)
{
 SMG1=ZC;SMG2=5;SMG3=T;SMG4=ZC;
}
/**-------------------------------------------------------------------------
                          Name: Disp_STS8();
--------------------------------------------------------------------------**/
void  Disp_STS8(void)
{
 SMG1=5;SMG2=T;SMG3=5;SMG4=8;
}
/**-------------------------------------------------------------------------
                          Name: Disp_08__();
--------------------------------------------------------------------------**/
void  Disp_08__(void)
{
 SMG1=0;SMG2=8;SMG3=SUBB;SMG4=SUBB;
}
/**-------------------------------------------------------------------------
                          Name: Disp_10__();
--------------------------------------------------------------------------**/
void  Disp_10__(void)
{
 SMG1=SUBB;SMG2=SUBB;SMG3=1;SMG4=0;
}
/**-------------------------------------------------------------------------
                          Name: Disp_DONH();
--------------------------------------------------------------------------**/
void  Disp_DONH(void)
{
 SMG1=ZD;SMG2=0;SMG3=N;SMG4=H;
}
/**-------------------------------------------------------------------------
                          Name: Disp_DONF();
--------------------------------------------------------------------------**/
void  Disp_DONF(void)
{
 SMG1=ZD;SMG2=0;SMG3=N;SMG4=ZF;
}
/**-------------------------------------------------------------------------
                          Name: Disp_DOFH();
--------------------------------------------------------------------------**/
void  Disp_DOFH(void)
{
 SMG1=ZD;SMG2=0;SMG3=ZF;SMG4=H;
}
/**-------------------------------------------------------------------------
                          Name: Disp_DOFF();
--------------------------------------------------------------------------**/
void  Disp_DOFF(void)
{
 SMG1=ZD;SMG2=0;SMG3=ZF;SMG4=ZF;
}
/**-------------------------------------------------------------------------
                          Name: Disp_LOCT();
--------------------------------------------------------------------------**/
void  Disp_LOCT(void)
{
 SMG1=L;SMG2=0;SMG3=ZC;SMG4=T;
}
/**-------------------------------------------------------------------------
                          Name: Disp_ES();
--------------------------------------------------------------------------**/
void  Disp_ES(void)
{
 SMG5=ZE;SMG6=5;
}
/**-------------------------------------------------------------------------
                          Name: Disp_EL();
--------------------------------------------------------------------------**/
void  Disp_EL(void)
{
 SMG5=ZE;SMG6=L;
}
/**-------------------------------------------------------------------------
                          Name: Disp_EH();
--------------------------------------------------------------------------**/
void  Disp_EH(void)
{
 SMG5=ZE;SMG6=H;
}
/**-------------------------------------------------------------------------
                          Name: Disp_EE();
--------------------------------------------------------------------------**/
void  Disp_EE(void)
{
 SMG5=ZE;SMG6=ZE;
}
/**-------------------------------------------------------------------------
                          Name: Disp_NND();
--------------------------------------------------------------------------**/
void  Disp_NND(void)
{
 SMG1=NO;SMG2=NO;SMG3=ZD;
}
/**-------------------------------------------------------------------------
                          Name: Disp_on();
--------------------------------------------------------------------------**/
void  Disp_on(void)
{
 SMG5=0;SMG6=N;
}
/**-------------------------------------------------------------------------
                          Name: Disp_of();
--------------------------------------------------------------------------**/
void  Disp_of(void)
{
 SMG5=0;SMG6=ZF;
}
/**-------------------------------------------------------------------------
                          Name: Disp_pb_t();
--------------------------------------------------------------------------**/
void  Disp_pb_t(void)
{
 SMG1=P;SMG2=ZB;SMG3=SUBB;SMG4=T;
}
/**-------------------------------------------------------------------------
                          Name: Disp_PP();
--------------------------------------------------------------------------**/
void  Disp_PP(void)
{
 SMG5=P;SMG6=P;
}

深圳市立业微电子有限公司    地址:深圳市宝安区西乡前进二路桃源居三区1栋3楼    邮编:518001
电话:0755-27452985(非上班时间所有电话关机)    传真:0755-27451955