#ifndef _HT1621_H_ #define _HT1621_H_ //#include "ht1621.h" #define HT1621_ADDR1 0 #define HT1621_ADDR2 1 #define HT1621_ADDR3 2 #define HT1621_ADDR4 3 #define HT1621_ADDR5 4 #define HT1621_ADDR6 5 #define HT1621_ADDR7 6 #define HT1621_ADDR8 7 #define HT1621_ADDR9 8 #define HT1621_ADDR10 9 #define HT1621_ADDR11 10 #define HT1621_ADDR12 11 #define HT1621_ADDR13 12 #define HT1621_ADDR14 13 #define HT1621_ADDR15 14 #define HT1621_ADDR16 15 #define HT1621_ADDR17 16 #define HT1621_ADDR18 17 #define HT1621_ADDR19 18 #define HT1621_ADDR20 19 #define HT1621_ADDR21 20 #define HT1621_ADDR22 21 #define HT1621_ADDR23 22 #define HT1621_ADDR24 23 #define HT1621_ADDR25 24 #define HT1621_ADDR26 25 #define HT1621_ADDR27 26 #define HT1621_ADDR28 27 #define HT1621_ADDR29 28 #define HT1621_ADDR30 29 #define HT1621_ADDR31 30 #define HT1621_ADDR32 31 /* #define HT1621_DAT PA1_OUT //dat #define HT1621_CS PA3_OUT //cs #define HT1621_WR PA2_OUT //clk */ //=========================== extern void Ht1621WrByte(uint8 Addr,uint8 Data) ; extern void Ht1621WrAllData(uint8 Addr,uint8 *p,uint8 DatLong) ; extern void Ht1621_Init(void) ; #endif //-------------------------------------- #include "global.h" #include "ht1621.h" #define BIAS2 0X40 // 1/2偏压 #define BIAS3 0X42 // 1/3偏压 #define COMNUM2 0X00 //2个COM #define COMNUM3 0X08 //3个COM #define COMNUM4 0X10 //4个COM //选择LCD模式 #define BIAS BIAS3|COMNUM4//0x52 1/3duty 4com #define SYSDIS 0X00//0b1000 0000 0000 关振系统荡器和LCD偏压发生器 #define SYSEN 0X02 //0b1000 0000 0010 打开系统振荡器 #define LCDOFF 0X04 //0b1000 0000 0100 关LCD偏压 #define LCDON 0X06 //0b1000 0000 0110 打开LCD偏压 #define XTAL 0x28 //0b1000 0010 1000 外部接时钟 #define RC256 0X30 //0b1000 0011 0000 内部时钟 #define TONEON 0X12 //0b1000 0001 0010 打开声音输出 #define TONEOFF 0X10 //0b1000 0001 0000 关闭声音输出 #define WDTDIS 0X0A //0b1000 0000 1010 禁止看门狗 //================================ void _Nop(void) { _asm("nop");_asm("nop");_asm("nop");_asm("nop"); _asm("nop");_asm("nop");_asm("nop");_asm("nop"); _asm("nop");_asm("nop");_asm("nop");_asm("nop"); _asm("nop");_asm("nop");_asm("nop");_asm("nop"); } //delay ms void DelayMS(uint16 iMs) { uint16 i,j; for(i=0;i 0;i--) { Tmp = (*p) ; Dat=0; //++ if(Tmp&0x01)Dat|=0x08 ; if(Tmp&0x02)Dat|=0x04 ; if(Tmp&0x04)Dat|=0x02 ; if(Tmp&0x08)Dat|=0x01 ; Dat <<= 4 ; Ht1621Wr_Data(Dat,4); //写入数据 p++; } HT1621_CS=1; _Nop(); } //************************************* // 函数名称:Ht1621_Init // 函数功能:1621初始化 // 入口参数:无 // 出口参数:无 //*************************************** void Ht1621_Init(void) { HT1621_CS=1; HT1621_WR=1; HT1621_DAT=1; DelayMS(50); //延时使LCD工作电压稳定 Ht1621WrCmd(BIAS); //设置BASE COM Ht1621WrCmd(RC256); //使用内部振荡器 Ht1621WrCmd(SYSDIS); Ht1621WrCmd(WDTDIS); Ht1621WrCmd(SYSEN); Ht1621WrCmd(LCDON); DelayMS(50); //延时一段时间 }