一、原理图3.3V与5V转换电路二、驱动程序2.1HT16C23.c#includestm32f10x.h#includeHT16C23.h#includemyiic.h//дÃüÁî//·µ»ØÖµ£º1£¬ÃüÁî·¢ËÍʧ°Ü//0£¬ÃüÁî·¢Ëͳɹ¦staticu8HT16C23_W_CMD(u8cmdByte,u8cmd){u8ret;IIC_Start();IIC_Send_Byte(ht16c23Add);//´Ó»úµØÖ·¼Óд²Ù×÷ret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Send_Byte(cmdByte);//ÃüÁîÂëret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Send_Byte(cmd);//ÃüÁîÊý¾Ýret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Stop();return0;}u8HT16C23_R_CMD(u8cmdByte,u8*cmd){u8ret;IIC_Start();IIC_Send_Byte(ht16c23Add+0x01);//´Ó»úµØÖ·¼Óд²Ù×÷ret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Send_Byte(cmdByte);//ÃüÁîÂëret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}*cmd=IIC_Read_Byte(1);IIC_Stop();returnret;}//дµ¥¸öÊý¾Ý//·µ»ØÖµ£º1£¬ÃüÁî·¢ËÍʧ°Ü//0£¬ÃüÁî·¢Ëͳɹ¦u8HT16C23_W_Sigle_data(u8add,u8data){u8ret;IIC_Start();IIC_Send_Byte(ht16c23Add);//´Ó»úµØÖ·¼Óд²Ù×÷ret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Send_Byte(dataCmd);//ÃüÁîÂëret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Send_Byte(add);//дÈëµØÖ·ret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Send_Byte(data);//дÈëÊý¾Ýret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Stop();return0;}//д¶à¸öÊý¾Ý//·µ»ØÖµ£º1£¬ÃüÁî·¢ËÍʧ°Ü//0£¬ÃüÁî·¢Ëͳɹ¦u8HT16C23_W_Mul_data(u8add,u8*data,u8len){u8i,ret;IIC_Start();IIC_Send_Byte(ht16c23Add);//´Ó»úµØÖ·¼Óд²Ù×÷ret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}IIC_Send_Byte(dataCmd);//ÃüÁîÂëret=IIC_Wait_Ack();if(ret)returnret;IIC_Send_Byte(add);//дÈëµØÖ·ret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}for(i=0;ilen;i++){IIC_Send_Byte(*data);//дÈëÊý¾Ýdata++;ret=IIC_Wait_Ack();if(ret){IIC_Stop();returnret;}}IIC_Stop();return0;}//ÏÔʾоƬ³õʼ»¯²Ù×÷//·µ»ØÖµ£º1£¬³õʼ»¯Ê§°Ü//0£¬³õʼ»¯³É¹¦u8HT16C23_Init(void){u8ret;ret=HT16C23_W_CMD(biasSetCmd,biasData);//Segment/VLCDsharedpinsetting,¿ÉÒÔ²»Óóõʼ»¯if(ret)returnret;ret=HT16C23_W_CMD(sysModeCmd,lcdRcOn+lcdDisOn);//¿ªLCDRCÕñµ´£¬¿ªÏÔʾreturnret;}u8HT16C23_Open(void){u8ret;ret=HT16C23_W_CMD(sysModeCmd,lcdRcOn+lcdDisOn);//¿ªLCDRCÕñµ´£¬¿ªÏÔʾreturnret;}u8HT16C23_Close(void){u8ret;ret=HT16C23_W_CMD(sysModeCmd,0x00);//¹ØLCDRCÕñµ´£¬¹ØÏÔʾreturnret;}////////////////////////endoffile/////////////////////////2.2ht16C23.h#ifndef__HT16C23_H_#define__HT16C23_H_#includestm32f10x.h#defineht16c23Add0x7C//HT16C23µØÖ·//ÏÔʾÊý¾ÝÊäÈëÃüÁî#definedataCmd0x80//W#definedataRamAdd0x00//Êý¾Ý¶ÁдÃüÁîW1/4dutymaxis1BH1/8dutymaxis33H,µ½´ï×î´óÖµºó±äΪ00H/////////////////////////////////////////////////////Çý¶¯Ä£Ê½ÃüÁî//bit1bit0dutybias//dutybias//001/41/3resetmode//011/41/4//101/81/3//111/81/4//×¢:ÎÞÂÛdutyÉèÖÃΪʲô,48½ÅµÄÖ»ÓÐ1/8dutyģʽ///////////////////////////////////////////////////#definederiveModeCmd0x82//W#definederiveModeData0x01//1/4duty1/3biasW////////////////////////////////////////////////////////////ϵͳģʽÃüÁî//bit1bit0ÄÚ²¿Õñµ´Æ÷LCDÏÔʾ//SE//0Xoffoffresetmode//10onoff//11onon//////////////////////////////////////////////////////////#definesysModeCmd0x84//W#definelcdRcOn0x02#definelcdDisOn0x01#definesysModeData(lcdRcOn+lcdDisOn)//¿ªRCÓëÏÔʾW///////////////////////////////////////////////////////////////֡ƵÂÊÃüÁî//bit0=0--80Hzresetmode//bit0=1--160Hz/////////////////////////////////////////////////////////////#defineframeFreCmd0x86//W#defineFre800x00#defineFre1600x01#defineframeFreDataFre160//W////////////////////////////////////////////////////////////////ÉÁ˸ƵÂÊÃüÁî//bit1bit0ÉÁ˸ƵÂÊ//BK1BK0//00¹Øresetmode//012Hz//101Hz//110.5Hz//////////////////////////////////////////////////////////////#defineshineFreCmd0x88#defineshineOff0x00//¹Ø±Õ#defineshine20Hz0x01//2Hz#defineshine10Hz0x02//1Hz#defineshine05Hz0x03//0.5Hz#defineshineDatashineOff///////////////////////////////////////////////////////////ÄÚ²¿µçѹµ÷Õû(IVA)ÉèÖÃÃüÁî//bit5bit4SEG55/VLCD¹²ÓýÅÑ¡ÔñÄÚ²¿µçѹµ÷Õû¹¦Äܱ¸×¢//DEVE//00VLCDOFFVCCA2CONNECTVLCDBIASDERIVEDBYVLCDPIN//VCCA2CONNECTVDDBIASDERIVEDBYVDDPIN//VLCDCONNECTVDDÄÚ²¿µçѹ¸úËæÆ÷(OP4)±Øͨ¹ýÉèÖÃDA3~DA0Ϊ'0000'À´Ê§ÄÜ//01VLCDONVCCA2CONNECTVLCDBIASDERIVEDBYVLCDPIN//VCCA2CONNECTVDD²»½¨ÒéʹÓÃ//VLCDCONNECTVDD,Èç¹ûVLCD¸¡¿ÕÇÒÄÚ²¿µçѹµ÷Õû¹¦ÄÜʹÄÜ//ÔòÄÚ²¿µçѹµ÷Õû¹¦ÄÜ¿ÉÓÃÀ´µ÷ÕûÄÚ²¿Æ«Öõçѹ//10SEG55OFFVCCA2CONNECTVLCDBIASDERIVEDBYVLCDPIN//VCCA2CONNECTVDDBIASDERIVEDBYVDDPIN//ÄÚ²¿µçѹ¸úËæÆ÷(OP4)×Ô¶¯Ê§ÄÜ,ÓëDA3~DA0ÎÞ¹Ø//11SEG55ONVCCA2CONNECTVLCD,Èç¹ûVLCDµçѹԴÓÚÍⲿµçѹ,ÇÒÄÚ//ÄÚ²¿µçѹµ÷Õû¹¦ÄÜʹÄÜ,ÄÚ²¿µçѹµ÷Õû¹¦ÄÜ¿ÉÓÃÀ´//µ÷ÕûÄÚ²¿Æ«Öõçѹ//VCCA2CONNECTVDD,ÄÚ²¿µçѹµ÷ÕûÆ÷¹¦ÄÜʹÄÜ,ÄÚ²¿//µçѹµ÷Õû¹¦Äܿɵ÷ÕûÄÚ²¿Æ«Öõçѹ.//Éϵç³õʼ»¯Îª:ÄÚ²¿µçѹµ÷Õû¹¦ÄÜʹÄÜÇÒSEG/VLCDÒý½ÅÑ¡ÔñΪSEGÒý½Å//////////////////////////////////////////////////////////////#definebiasSetCmd0x8A#definebiasData0x0Aexternu8HT16C23_W_Sigle_data(u8add,u8data);externu8HT16C23_W_Mul_data(u8add,u8*data,u8len);externu8HT16C23_Init(void);externu8HT16C23_Open(void);externu8HT16C23_Close(void);u8HT16C23_R_CMD(u8cmdByte,u8*cmd);#endif////////////////////////endoffile/////////////////////////2.3Myiic.c源码#includemyiic.hstaticvoiddelay_us(u32time){u16i=0;while(time--){i=10;//×Ô¼º¶¨Òåwhile(i--);}}//STM32Èí¼þÄ£ÄâIIC£¬STM32µÄÓ²¼