今晚捣鼓了一下HT1621显示AD采样值,AD是12位的。
代码:
#include
#include "main.h"
/** @addtogroup Projects_Examples_MD
* @{
*/
#define uchar unsigned char
#define uint unsigned int
#define Smg_a 0x80
#define Smg_b 0x40
#define Smg_c 0x20
#define Smg_d 0x01
#define Smg_e 0x02
#define Smg_f 0x08
#define Smg_g 0x04
#define Smg_dp 0x10
#define Bmp0Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f
#define Bmp1Map Smg_b | Smg_c
#define Bmp2Map Smg_a | Smg_b | Smg_d | Smg_e | Smg_g
#define Bmp3Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_g
#define Bmp4Map Smg_b | Smg_c | Smg_f | Smg_g
#define Bmp5Map Smg_a | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp6Map Smg_a | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp8Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp9Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp7Map Smg_a | Smg_b | Smg_c
#define BmpAMap Smg_a | Smg_b | Smg_c | Smg_e | Smg_f | Smg_g
#define BmpBMap Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpCMap Smg_a | Smg_d | Smg_e | Smg_f
#define BmpDMap Smg_b | Smg_c | Smg_d | Smg_e | Smg_g
#define BmpEMap Smg_a | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpFMap Smg_a | Smg_e | Smg_f | Smg_g
#define CS_0 md_gpio_set_pin_low(CS_GPIO_PORT,CS_GPIO_PIN)
#define CS_1 md_gpio_set_pin_high(CS_GPIO_PORT,CS_GPIO_PIN)
#define WR_0 md_gpio_set_pin_low(WR_GPIO_PORT,WR_GPIO_PIN)
#define WR_1 md_gpio_set_pin_high(WR_GPIO_PORT,WR_GPIO_PIN)
#define DA_0 md_gpio_set_pin_low(DA_GPIO_PORT,DA_GPIO_PIN)
#define DA_1 md_gpio_set_pin_high(DA_GPIO_PORT,DA_GPIO_PIN)
/** @addtogroup Examples_ADC
* @{
*/
/**
* @brief Initializate buf of adc normal value.
*/
uint32_t nm_value;
/**
* @brief adc_handle_t structure.
*/
adc_init_t h_adc;
const unsigned char SegCode[] = {Bmp0Map,Bmp1Map,Bmp2Map,Bmp3Map,Bmp4Map,Bmp5Map,Bmp6Map,Bmp7Map,Bmp8Map,Bmp9Map,BmpAMap,BmpBMap,BmpCMap,BmpDMap,BmpEMap,BmpFMap};
unsigned char DpyNum[6] = {Smg_g,Smg_g,Smg_g,Smg_g,Smg_g,Smg_g}; //?????
unsigned int i;
void delay(uchar x)
{
for(i=0;i
void COMMAND_HT1621(unsigned char comm)
{
unsigned char i;
CS_0;
delay(5);
WR_0;
delay(5);
for(i=0;i<3> {
if((0x04< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<9> {
if((comm< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
CS_1;
delay(5);
}
void HT1621_Display(void)
{
unsigned char i;
CS_0; //??CS
delay(5);
WR_0;
delay(5);
for(i=0;i<3> {
if((0x05< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<6> {
if((20< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8> {
if((DpyNum[5]< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8> {
if((DpyNum[4]< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8> {
if((DpyNum[3]< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8> {
if((DpyNum[2]< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8> {
if((DpyNum[1]< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8> {
if((DpyNum[0]< else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
CS_1; //??CS
delay(5);
}
void LCD_Init(void)
{
COMMAND_HT1621(0x01); //SYS EN
COMMAND_HT1621(0x03); //LCD ON
COMMAND_HT1621(0x29); //4 COM 1/3 BIAS
HT1621_Display(); //clear screen
}
/**
* @brief Initializate pin of adc module.
* @retval None
*/
void adc_pin_init(void)
{
md_gpio_init_t x;
/* Initialize sck pin */
x.mode = GPIO_MODE_INPUT;
x.pupd = GPIO_PUSH_UP;
x.odrv = GPIO_OUT_DRIVE_NORMAL;
x.flt = GPIO_FILTER_DISABLE;
x.type = GPIO_TYPE_CMOS;
x.func = GPIO_FUNC_0;
md_gpio_init(GPIO_CH_PORT, ADC_CH1_PIN, &x);
return;
}
void config_gpio(void)
{
md_gpio_set_pin_function(DA_GPIO_PORT, DA_GPIO_PIN, GPIO_FUNC_1);
md_gpio_set_pin_push_pull(DA_GPIO_PORT, DA_GPIO_PIN);
md_gpio_set_pin_mode_output(DA_GPIO_PORT, DA_GPIO_PIN);
md_gpio_set_pin_function(WR_GPIO_PORT, WR_GPIO_PIN, GPIO_FUNC_1);
md_gpio_set_pin_push_pull(WR_GPIO_PORT, WR_GPIO_PIN);
md_gpio_set_pin_mode_output(WR_GPIO_PORT, WR_GPIO_PIN);
md_gpio_set_pin_function(CS_GPIO_PORT, CS_GPIO_PIN, GPIO_FUNC_1);
md_gpio_set_pin_push_pull(CS_GPIO_PORT, CS_GPIO_PIN);
md_gpio_set_pin_mode_output(CS_GPIO_PORT, CS_GPIO_PIN);
}
/**
* @brief Test main function
* @retval Status.
*/
int main()
{
uchar qian,bai,shi,ge;
/* Initialize 1ms tick */
md_init_1ms_tick();
/* clear adc_handle_t structure */
memset(&h_adc, 0x0, sizeof(h_adc));
/* Initialize adc pin */
adc_pin_init();
/* Initialize ADC0 */
md_adc_struct_init(&h_adc);
md_adc_init(ADC0, &h_adc);
/* Initialize normal convert channel */
md_adc_set_normal_1st_conv_ns1(ADC0, ADC_NC_RANK_14);
md_adc_set_smpt1_cht(ADC0, ADC_SAMPLETIME_4);
config_gpio();
LCD_Init();
DpyNum[0] = Smg_a|Smg_d|Smg_g; //"?"
DpyNum[1] = Smg_a|Smg_d|Smg_g; //"?"
DpyNum[2] = SegCode[3];
DpyNum[3] = SegCode[5];
DpyNum[4] = SegCode[7];
DpyNum[5] = SegCode[9];
HT1621_Display(); //??LCD
while (1)
{
/* Enable ADC0 and start normal convert */
md_adc_converter_enable_adcen(ADC0);
md_adc_set_normal_channel_conv_start_ichtrg(ADC0);
/* Wait convert finish */
while (md_adc_get_stat_nche(ADC0) == 0);
/* Read normal convert result */
nm_value = md_adc_get_normal_channel_val(ADC0);
qian=(uchar)(nm_value/1000);
bai=(uchar)(nm_value 00 /100);
shi=(uchar)(nm_value 0 /10);
ge=(uchar)(nm_value);
DpyNum[2] = SegCode[qian];
DpyNum[3] = SegCode[bai];
DpyNum[4] = SegCode[shi];
DpyNum[5] = SegCode[ge];
HT1621_Display(); //??LCD
md_delay_1ms(1000);
}
}
效果图:
一周热门 更多>