首页 > 评测 > 【CuriosityNano测评报告】+PIC16F15244 HT1621驱动液晶显示ADC
【CuriosityNano测评报告】+PIC16F15244 HT1621驱动液晶显示ADC
- [导读]
- 今天用HT1621液晶模块显示一路AD的值。代码外设配置用MCC生成,我们这里开启调试串口和一路ADC。串口配置:9600,N,8,1 启用printf重定向 S1.png (41.46 KB, 下载次数: 0) 下载附件 保存到相册 2021-
今天用HT1621液晶模块显示一路AD的值。代码外设配置用MCC生成,我们这里开启调试串口和一路ADC。串口配置:9600,N,8,1 启用printf重定向
ADC 用RC3对应的ANC3 ,主意数据格式为右对齐,一开始我选择的左对齐,然后发现与生成的代码里面的算法不匹配,
参考电压选择VDD。软件触发模式~
我们模拟IIC来启动HT1621:
其中HT6121代码如下:
h文件:
- /*
- * File: HT1621.h
- * Author: Administrator
- *
- * Created on February 21, 2021, 9:01 AM
- */
- #ifndef HT1621_H
- #define HT1621_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <xc.h>
- //HT1621??
- #define BIAS 0x52 //0b1000 0101 0010 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 WDTDIS1 0X0A //0b1000 0000 1010 ?????
- void Ht1621Wr_Data(unsigned char Data,unsigned char cnt) ;
- void Ht1621WrCmd(unsigned char Cmd) ;
- void Ht1621WrOneData(unsigned char Addr,unsigned char Data);
- void Ht1621WrAllData(unsigned char Addr,unsigned char *p,unsigned char cnt);
- void Ht1621_Init(void) ;
- void Display(void) ;
- void Display_lcd_dot(void) ;
- void data_convertor(unsigned long adc_value) ;
- #ifdef __cplusplus
- }
- #endif
- #endif /* HT1621_H */
C文件:
- #include "HT1621.h"
- #include "pin_manager.h"
- unsigned int tmp;
- unsigned int n1, n2, n3, n4;
- unsigned char DispTab[]={0xEB,0x0A,0xAD,0x8F,0x4E,0xC7,0xE7,0x8A,0xEF,0xCF,0x85,0xEE, 0x67, 0xE1,0x2F,0xE5,0xE4};
- //??????
- void Ht1621_CS_0() { HT1621_CS_SetLow() ;} //
- void Ht1621_CS_1() { HT1621_CS_SetHigh() ;}
- void Ht1621_WR_0() { HT1621_WR_SetLow();} //
- void Ht1621_WR_1() { HT1621_WR_SetHigh();}
- void Ht1621_DAT_0() { HT1621_DATA_SetLow();} //
- void Ht1621_DAT_1() { HT1621_DATA_SetHigh();}
- void Ht1621_GND_0() { HT1621_GND_SetLow();} //
- void Ht1621_GND_1() { HT1621_GND_SetLow();}
- void Ht1621_VCC_0() { HT1621_VCC_SetLow();} //
- void Ht1621_VCC_1() { HT1621_VCC_SetHigh();}
- /*******************************************************************************
- ****????:
- ****????:1621?????
- ****??:V1.0
- ****??:14-2-2014
- ****????:Data-?????? cnt-????????
- ****????:
- ****??:
- ********************************************************************************/
- void Ht1621Wr_Data(unsigned char Data,unsigned char cnt)
- {
- unsigned char i;
- for (i=0;i<cnt;i++)
- {
- Ht1621_WR_0();
- if((Data & 0x80)==0x80)
- {Ht1621_DAT_1();}
- else
- {Ht1621_DAT_0();}
- Ht1621_WR_1();
- Data<<=1;
- }
- }
- /*******************************************************************************
- ****????:
- ****????:1621?????
- ****??:V1.0
- ****??:14-2-2014
- ****????:Cmd ??
- ****????:
- ****??:
- ********************************************************************************/
- void Ht1621WrCmd(unsigned char Cmd)
- {
- Ht1621_CS_0();
- Ht1621Wr_Data(0x80,4); //??????100
- Ht1621Wr_Data(Cmd,8); //??????
- Ht1621_CS_1();
- }
- /*******************************************************************************
- ****????:
- ****????:1621???????
- ****??:V1.0
- ****??:14-2-2014
- ****????:Addr--?? Data--??
- ****????:
- ****??:
- ********************************************************************************/
- void Ht1621WrOneData(unsigned char Addr,unsigned char Data)
- {
- Ht1621_CS_0();
- Ht1621Wr_Data(0xa0,3); //??????101
- Ht1621Wr_Data(Addr<<2,6); //??????
- Ht1621Wr_Data(Data,4); //???????? 7 6 5 4
- Ht1621_CS_1();
- }
- /*******************************************************************************
- ****????:
- ****????:1621???????
- ****??:V1.0
- ****??:14-2-2014
- ****????:Addr--?? p--?? cnt????
- ****????:
- ****??:
- ********************************************************************************/
- void Ht1621WrAllData(unsigned char Addr,unsigned char *p,unsigned char cnt)
- {
- unsigned char i;
- Ht1621_CS_0();
- Ht1621Wr_Data(0xa0,3); //??????101
- Ht1621Wr_Data(Addr<<2,6); //??????
- for (i=0;i<cnt;i++)
- {
- Ht1621Wr_Data(*p,8); //????
- p++;
- }
- Ht1621_CS_1();
- }
- /*******************************************************************************
- ****????:
- ****????:1621?????
- ****??:V1.0
- ****??:14-2-2014
- ****????:
- ****????:
- ****??:
- ********************************************************************************/
- void Ht1621_Init(void)
- {
- Ht1621_GND_0(); //HT1621 power on
- Ht1621_VCC_1();
- Ht1621WrCmd(BIAS);
- Ht1621WrCmd(RC256); //???????
- //Ht1621WrCmd(XTAL); //???????
- Ht1621WrCmd(SYSDIS);
- Ht1621WrCmd(WDTDIS1);
- Ht1621WrCmd(SYSEN);
- Ht1621WrCmd(LCDON);
- }
- /*******************************************************************************
- ****????:
- ****????:1621????
- ****??:V1.0
- ****??:14-2-2014
- ****????:
- ****????:
- ****??:
- ********************************************************************************/
- void Display(void)
- {
- Ht1621WrOneData(0 , DispTab[n4]);
- Ht1621WrOneData(1 , DispTab[n4]<<4);
- Ht1621WrOneData(2 , DispTab[n3]);
- Ht1621WrOneData(3 , DispTab[n3]<<4);
- Ht1621WrOneData(4 , DispTab[n2]);
- Ht1621WrOneData(5 , DispTab[n2]<<4);
- Ht1621WrOneData(6 , DispTab[n1]);
- Ht1621WrOneData(7 , DispTab[n1]<<4);
- }
- /*******************************************************************************
- ****????:
- ****????:??????
- ****??:V1.0
- ****??:14-2-2014
- ****????:Addr--?? Data--??
- ****????:
- ****??:
- ********************************************************************************/
- void Display_lcd_dot(void)
- {
- //Ht1621WrOneData(0 , DispTab[n4]|0x10);//P1
- Ht1621WrOneData(2 , DispTab[n3]|0x10); //2P
- //Ht1621WrOneData(4 , DispTab[n2]|0x10); //3P
- //Ht1621WrOneData(6 , DispTab[n1]|0x10); //4P
- }
- /*******************************************************************************
- ****????:
- ****????:??????
- ****??:V1.0
- ****??:14-2-2014
- ****????:adc_value-???????
- ****????:
- ****??:
- ********************************************************************************/
- void data_convertor(unsigned long adc_value)
- {
- tmp=adc_value; //adc
- n4=tmp/1000;
- tmp=tmp%1000;
- n3=tmp/100;
- tmp=tmp%100;
- n2=tmp/10;
- tmp=tmp%10;
- n1=tmp;
- }
下面,我们在main函数里面调用:
- #include "mcc_generated_files/mcc.h"
- #include "mcc_generated_files/HT1621.h"
- unsigned char Ht1621Tab[]={0x00,0x00,0x00,0x00};
- /*
- Main application
- */
- void main(void)
- {
- //unsigned char i=0;
- uint16_t u16_adc1_value;
- uint16_t VoltageValue;
- // initialize the device
- SYSTEM_Initialize();
- __delay_ms(5000);
- Ht1621_Init(); //?????LCD
- __delay_ms(5000); //??????
- Ht1621WrAllData(0,Ht1621Tab,16);// Clear LCD display
- // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
- // Use the following macros to:
- // Enable the Global Interrupts
- //INTERRUPT_GlobalInterruptEnable();
- // Enable the Peripheral Interrupts
- //INTERRUPT_PeripheralInterruptEnable();
- // Disable the Global Interrupts
- //INTERRUPT_GlobalInterruptDisable();
- // Disable the Peripheral Interrupts
- //INTERRUPT_PeripheralInterruptDisable();
- while (1)
- {
- //u16_adc1_value=ADC_GetConversion(channel_ANC3);
- //u16_adc1_value=ADC_GetConversion(channel_AVSS);
- u16_adc1_value=ADC_GetConversion(channel_FVR_BUF1);
- VoltageValue=u16_adc1_value*3300UL/1024UL;
- data_convertor(VoltageValue);
- Display();
- Display_lcd_dot();
- printf("the ADCVALUE is %d ,the VoltageValue is %d\r\n",u16_adc1_value,VoltageValue);
- __delay_ms(1000);
- }
- }
为了验证不同电压的ADC采样,我开启了FVR,并设定其为:2.048V
编译下载代码,分别测试3V3和2.048:
其中,观察了FVR的电压,会从2.049 来回跳到2.056 ,有(2.056-2.049)=0.007V的波动
查看串口输出的信息:
发现采样到的ADC值就相差2个最小单位,0.007/2=0.0035与官方精度(3.3/1024=0.0032)几乎接近。
- 本文系21ic原创,未经许可禁止转载!
网友评论
- 联系人:巧克力娃娃
- 邮箱:board@21ic.com
- 我要投稿
-
欢迎入驻,开放投稿
-
人均百万?英伟达中国员工收入曝光! 2024-08-29
-
《黑神话:悟空》玩家硬盘升级攻略:提升游戏体验,畅享3A大作 2024-08-29
-
数睿数据参加《系统与软件工程 低代码开发平台通用技术要求》国家标准编制 2024-08-29
- NRF52810蓝牙数字耳机找人定制
预算:¥30005天前
- 125KW模块式PCS软硬件外包开发
预算:¥1100000015小时前
- 12V汽车启动电源项目BMS设计
预算:¥50000023小时前
- 数据可视化软件 开发
预算:¥5000023小时前
- PLC项目调试修改
预算:¥100001天前
- 起动电机控制器开发
预算:¥1100001天前