cancel
Showing results for 
Search instead for 
Did you mean: 

I want to program a 0 to 99 counter with 7 segments but I don't know where I wrote wrong in my code.Thank you for your help.

eab.11
Associate

//////////////////refresh pin

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,GPIO_PIN_RESET);

HAL_Delay(10);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,GPIO_PIN_RESET);

HAL_Delay(10);

/////////////////////out put

HAL_GPIO_WritePin(GPIOA,0x00ff,GPIO_PIN_RESET);

HAL_GPIO_WritePin(GPIOA,digit[i],GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOA,digit[j]<<4,GPIO_PIN_SET);

HAL_Delay(1000);

////////////////////counter

i++;

if(i==10){

j++;

i=0;

if(j==10){

i=0;

j=0;

}

unsigned char digit[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

This discussion is locked. Please start a new topic to ask your question.
4 REPLIES 4
waclawek.jan
Super User

We don't know where you wrote wrong in your code, either, as we don't even see your code.

Anyway, debug as usually. And separate the problem to pieces: first, write a simple program which counts into a variable in memory; and then write a simple program which displays any chosen number to the 7-segments. Then put them together.

JW

eab.11
Associate

this is my code but i don't find mistake.

//////////////////refresh pin

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,GPIO_PIN_RESET);

HAL_Delay(10);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,GPIO_PIN_RESET);

HAL_Delay(10);

/////////////////////out put

HAL_GPIO_WritePin(GPIOA,0x00ff,GPIO_PIN_RESET);

HAL_GPIO_WritePin(GPIOA,digit[i],GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOA,digit[j]<<4,GPIO_PIN_SET);

HAL_Delay(1000);

////////////////////counter

i++;

if(i==10){

j++;

i=0;

if(j==10){

i=0;

j=0;

}

unsigned char digit[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

Pavel A.
Super User

There are 7 segments, not 4

Identify exactly which pins connect to with elements, or which displays

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..