1263 views|1 replies

501

Posts

4

Resources
The OP
 

[Shanghai Hangxin ACM32F070 development board + touch function evaluation board] Two-way counter implementation [Copy link]

 

Demo Video

计数器

Preface

Based on the official HAL library, we can easily develop. This time, based on touch buttons and segment code display, a counter function is realized.

process

Based on LCD_TK.

Design two counters to display the upper and lower 4-digit numbers of the segment code respectively.

The return and confirmation buttons correspond to two counting inputs respectively.

Modification of App_Test function in App.c

as follows

void App_Test(void)

{

float ff_getTempHum[2];

uint16_t fu16_num_up, fu16_num_down;

uint32_t fu32_Displayup[4]={0},fu32_Displaydown[4]={0},fu32_num_123567p[7]={0},fu32_num_col[2]={0},fu32_num_s=0;

uint8_t fu8_Tkey_state = 0xff, fu8_Work_Mode=0;

uint16_t fu16_set_num_up=0,fu16_set_num_down=0;

uint8_t fu8_Hidden_point=0;//

uint8_t ret = 0;

LCD_Config();

SHT30_Init();

BUZZER_Init();

ret = TouchKey_Init();

if(ret)

{

printfS("TouchKey_Init is Fail!\r\n");

}

else

{

printfS("TouchKey_Init is Success!\r\n");

}

LCD_YR1618A_SelfDisplay();

SysTick_Handler_Callback = SysTick_Callback;

while(1)

{

fu8_Tkey_state = TK_TimerSacn_GetKeyVal();//Get_Touch_Key_Value();

if(fu8_Tkey_state != 0xFF)

{

Beep_On(5);

#ifndef TKEY_WAVEFORM_OUTPUT

printfS("TK_%d\r\n", fu8_Tkey_state);

#endif

}

TKEY_Calibrate_Process();

#if 1

if(fu8_Tkey_state == 10)//÷ °· ±

{

fu16_set_num_up++;

if(fu16_set_num_up>9999) fu16_set_num_up=9999;//4×ó9999

fu32_Displayup[0]=fu16_set_num_up/1000%10;//§,LCD1(×ó)--5

fu32_Displayup[1]=fu16_set_num_up/100%10;//°×,LCD2(×ó)---6

fu32_Displayup[2]=fu16_set_num_up/10%10;//,LCD3(×ó)----7

fu32_Displayup[3]=fu16_set_num_up/1%10;//,LCD4(×ó)-----8

LCD_YR1618A_VIEW(fu32_Displayup,fu32_Displaydown,fu32_num_123567p,fu32_num_col,fu32_num_s);

}

if(fu8_Tkey_state == 15)//÷ °· ±è

{

fu16_set_num_down++;

if(fu16_set_num_down>9999) fu16_set_num_down=9999;//4×ó9999

fu32_Displaydown[0]=fu16_set_num_down/1000%10;//§,LCD1(×ó)--5

fu32_Displaydown[1]=fu16_set_num_down/100%10;//°×,LCD2(×ó)---6

fu32_Displaydown[2]=fu16_set_num_down/10%10;//,LCD3(×ó)----7

fu32_Displaydown[3]=fu16_set_num_down/1%10;//,LCD4(×ó)-----8

LCD_YR1618A_VIEW(fu32_Displayup,fu32_Displaydown,fu32_num_123567p,fu32_num_col,fu32_num_s);

}

#else

if(fu8_Work_Mode == 0)//

{

if(fu8_Tkey_state == 15)//÷ °· ±è

{

fu8_Work_Mode = 1;

}

if(gu8_time_count_free == 1)gu8_time_count_free=0;

else if(gu8_time_count_free == 2)

{

gu8_time_count_free=0;

SHT30_Read_Dat(I2C_Handle,gu8_RxBuffer);

SHT30_Read_Result(gu8_RxBuffer,ff_getTempHum);

fu16_num_up=(uint16_t)(ff_getTempHum[0]*100);

fu16_num_down=(uint16_t)(ff_getTempHum[1]*100);

fu32_num_123567p[1] |= 1;

fu32_num_123567p[4] |= 1;

fu32_num_s |= S_DATA[1];

fu32_num_s |= S_DATA[3];

fu32_num_s &=~S_DATA[0];

fu32_num_s |=S_DATA[12];//S13_BATW,S14_BAT1,S15_BAT2,S16_BAT3

fu32_num_s |= S_DATA[13];

fu32_num_s |= S_DATA[14];

fu32_num_s |= S_DATA[15];

if(fu16_num_up>9999) fu16_num_up=9999;//4×ó9999

fu32_Displayup[0]=fu16_num_up/1000%10;//§,LCD1(×ó)--5

fu32_Displayup[1]=fu16_num_up/100%10;//°×,LCD2(×ó)---6

fu32_Displayup[2]=fu16_num_up/10%10;//,LCD3(×ó)----7

fu32_Displayup[3]=fu16_num_up/1%10;//,LCD4(×ó)-----8

if(fu16_num_down>9999) fu16_num_down=9999;//4×ó9999

fu32_Displaydown[0]=fu16_num_down/1000%10;//§,LCD1(×ó)--5

fu32_Displaydown[1]=fu16_num_down/100%10;//°×,LCD2(×ó)---6

fu32_Displaydown[2]=fu16_num_down/10%10;//,LCD3(×ó)----7

fu32_Displaydown[3]=fu16_num_down/1%10;//,LCD4(×ó)-----8

LCD_YR1618A_VIEW(fu32_Displayup,fu32_Displaydown,fu32_num_123567p,fu32_num_col,fu32_num_s);

}

}

else //è

{

if(fu8_Tkey_state == 10)//÷ °· ±

{

fu8_Work_Mode = 0;

}

else if(fu8_Tkey_state == 7)// °×ó ±

{

if(fu8_Hidden_point<7)fu8_Hidden_point++;

}

else if(fu8_Tkey_state == 9)// ° ±

{

if(fu8_Hidden_point>0)fu8_Hidden_point--;

}

else if(fu8_Tkey_state == 11)// ° ±

{

switch(fu8_Hidden_point)

{

case 0:

if(fu16_set_num_up<9000)

fu16_set_num_up+=1000;

break;

case 1:

fu16_set_num_up+=100;

break;

case 2:

fu16_set_num_up+=10;

break;

case 3:

fu16_set_num_up+=1;

break;

case 4:

if(fu16_set_num_down<9000)

fu16_set_num_down+=1000;

break;

case 5:

fu16_set_num_down+=100;

break;

case 6:

fu16_set_num_down+=10;

break;

case 7:

fu16_set_num_down+=1;

break;

};

}

else if(fu8_Tkey_state == 8)// ° ±

{

switch(fu8_Hidden_point)

{

case 0:

if(fu16_set_num_up>=1000)

fu16_set_num_up-=1000;

break;

case 1:

if(fu16_set_num_up>=100)

fu16_set_num_up-=100;

break;

case 2:

if(fu16_set_num_up>=10)

fu16_set_num_up-=10;

break;

case 3:

if(fu16_set_num_up>0)

fu16_set_num_up-=1;

break;

case 4:

if(fu16_set_num_down>=1000)

fu16_set_num_down-=1000;

break;

case 5:

if(fu16_set_num_down>=100)

fu16_set_num_down-=100;

break;

case 6:

if(fu16_set_num_down>=10)

fu16_set_num_down-=10;

break;

case 7:

if(fu16_set_num_down>0)

fu16_set_num_down-=1;

break;

};

}

}

if( (gu8_time_count_free==1) && (fu8_Work_Mode == 1) )

{

gu8_time_count_free=0;

if(fu16_set_num_up>9999) fu16_set_num_up=9999;//4×ó9999

fu32_Displayup[0]=fu16_set_num_up/1000%10;//§,LCD1(×ó)--5

fu32_Displayup[1]=fu16_set_num_up/100%10;//°×,LCD2(×ó)---6

fu32_Displayup[2]=fu16_set_num_up/10%10;//,LCD3(×ó)----7

fu32_Displayup[3]=fu16_set_num_up/1%10;//,LCD4(×ó)-----8

if(fu16_set_num_down>9999) fu16_set_num_down=9999;//4×ó9999

fu32_Displaydown[0]=fu16_set_num_down/1000%10;//§,LCD1(×ó)--5

fu32_Displaydown[1]=fu16_set_num_down/100%10;//°×,LCD2(×ó)---6

fu32_Displaydown[2]=fu16_set_num_down/10%10;//,LCD3(×ó)----7

fu32_Displaydown[3]=fu16_set_num_down/1%10;//,LCD4(×ó)-----8

switch(fu8_Hidden_point)

{

case 0://up

fu32_Displayup[0]=10;

break;

case 1://up

fu32_Displayup[1]=10;

break;

case 2://up

fu32_Displayup[2]=10;

break;

case 3://up

fu32_Displayup[3]=10;

break;

case 4://up

fu32_Displaydown[0]=10;

break;

case 5://up

fu32_Displaydown[1]=10;

break;

case 6://up

fu32_Displaydown[2]=10;

break;

case 7://up

fu32_Displaydown[3]=10;

break;

};

LCD_YR1618A_VIEW(fu32_Displayup,fu32_Displaydown,fu32_num_123567p,fu32_num_col,fu32_num_s);

}

else if ( (gu8_time_count_free==2) && (fu8_Work_Mode == 1) )

{

gu8_time_count_free=0;

fu32_num_123567p[1] |= 1;

fu32_num_123567p[4] |= 1;

fu32_num_s |= S_DATA[1];

fu32_num_s |= S_DATA[3];

fu32_num_s |= S_DATA[0];

fu32_num_s &=~S_DATA[12];//S13_BATW,S14_BAT1,S15_BAT2,S16_BAT3

fu32_num_s &=~S_DATA[13];

fu32_num_s &=~S_DATA[14];

fu32_num_s &=~S_DATA[15];

if(fu16_set_num_up>9999) fu16_set_num_up=9999;//4×ó9999

fu32_Displayup[0]=fu16_set_num_up/1000%10;//§,LCD1(×ó)--5

fu32_Displayup[1]=fu16_set_num_up/100%10;//°×,LCD2(×ó)---6

fu32_Displayup[2]=fu16_set_num_up/10%10;//,LCD3(×ó)----7

fu32_Displayup[3]=fu16_set_num_up/1%10;//,LCD4(×ó)-----8

if(fu16_set_num_down>9999) fu16_set_num_down=9999;//4×ó9999

fu32_Displaydown[0]=fu16_set_num_down/1000%10;//§,LCD1(×ó)--5

fu32_Displaydown[1]=fu16_set_num_down/100%10;//°×,LCD2(×ó)---6

fu32_Displaydown[2]=fu16_set_num_down/10%10;//,LCD3(×ó)----7

fu32_Displaydown[3]=fu16_set_num_down/1%10;//,LCD4(×ó)-----8

LCD_YR1618A_VIEW(fu32_Displayup,fu32_Displaydown,fu32_num_123567p,fu32_num_col,fu32_num_s);

}

#endif

}

}

After compiling and burning, run the program. You can see the touch button returns and confirms, and the upper and lower 4-digit counters start counting.

See video

Summarize

Based on the official HAL library, rapid functional verification and development can be carried out, which is very efficient.

This post is from Domestic Chip Exchange

Latest reply

After looking at it, it would be better if the code was commented as a review post, so as to make it easier for others who want to learn. if(fu16_set_num_down>9999) fu16_set_num_down=9999;//4×ó9999 fu32_Displaydown[0]=fu16_set_num_down/1000%10;//§,LCD1(×ó)--5 fu32_Displaydown[1]=fu16_set_num_down/100%10;//°×,LCD2(×ó)---6 fu32_Displaydown[2]=fu16_set_num_down/10%10;//,LCD3(×ó)----7 fu32_Displaydown[3]=fu16_set_num_down/1%10;//,LCD4(×ó)-----8 It is best to modify the garbled characters like the above. float ff_getTempHum[2]; uint16_t fu16_num_up, fu16_num_down; uint32_t fu32_Displayup[4]={0},fu32_Displaydown[4]={0},fu32_num_123567p[7]={0},fu32_num_col[2]={0},fu32_num_s=0; uint8_t fu8_Tkey_state = 0xff, fu8_Work_Mode=0; uint16_t fu16_set_num_up=0,fu16_set_num_down=0; uint8_t fu8_Hidden_point=0;// uint8_t ret = 0; For a writing format like this, we should also establish the format for the original poster. It is best to post code using code blocks. Don't simply copy and paste, this way the post may be rated higher. I hope your next post will be more exciting.   Details Published on 2022-9-26 23:04
 
 

6821

Posts

11

Resources
2
 

After looking at it, it would be better if the code was commented as a review post, so as to make it easier for others who want to learn.

if(fu16_set_num_down>9999) fu16_set_num_down=9999;//4×ó9999

fu32_Displaydown[0]=fu16_set_num_down/1000%10;//§,LCD1(×ó)--5

fu32_Displaydown[1]=fu16_set_num_down/100%10;//°×,LCD2(×ó)---6

fu32_Displaydown[2]=fu16_set_num_down/10%10;//,LCD3(×ó)----7

fu32_Displaydown[3]=fu16_set_num_down/1%10;//,LCD4(×ó)-----8

It is best to modify the garbled characters like the above.

float ff_getTempHum[2];

uint16_t fu16_num_up, fu16_num_down;

uint32_t fu32_Displayup[4]={0},fu32_Displaydown[4]={0},fu32_num_123567p[7]={0},fu32_num_col[2]={0},fu32_num_s=0;

uint8_t fu8_Tkey_state = 0xff, fu8_Work_Mode=0;

uint16_t fu16_set_num_up=0,fu16_set_num_down=0;

uint8_t fu8_Hidden_point=0;//

uint8_t ret = 0;

For a writing format like this, we should also establish the format for the original poster.

It is best to post code using code blocks.

Don't simply copy and paste, this way the post may be rated higher.

I hope your next post will be more exciting.

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list