Reputation: 75
Few days ago, I posted a question regarding the seven segment display with stm32(f401re). I have completed the coding part for the display to show particular four digit number that I provide as an input. I number I want to display is 1014.
Here is the code for the I created:
while (1)
{
/* USER CODE END WHILE */
num_display_func(1014);
/* USER CODE BEGIN 3 */
}
Here is the fucntion that is called :
void num_display_func(uint16_t numtodisplay){
int place_value = 1000;
int num = numtodisplay;
uint16_t active_pin = GPIO_PIN_9;
int count;
for(count = 0; count<4; count++){
uint8_t digit_extract = num/place_value; //dividing the num by 1000 to extract the first digit,1234/1000->1
num %=place_value;
place_value /=10;
HAL_GPIO_WritePin(GPIOA, active_pin, SET);
displayDigit(digit_extract);
HAL_GPIO_WritePin(GPIOA, active_pin, RESET);
active_pin <<= 1; //shift the pin by 1 to activate the second display
HAL_Delay(100);
}
}
displayDigit() is as follows:
void displayDigit(uint8_t number){
GPIOC->ODR |= GPIOx_SEGMENTS_MASK; //Clear the segment bits (Setting the bits to HIGH for common Anode config)
uint8_t digit = segmentCodes[number];
GPIOC->ODR &= (digit & GPIOx_SEGMENTS_MASK );
}
Here is the demo that shows the problem:
When I manually debug the code by setting breakpoint at the end of the function,
void displayDigit(uint8_t number)
every time the execution reaches the breakpoint, I see the change in display number.
But when I hit RUN, all the segments are blank and nothing appears on the display.
How to make the display show the number? Is there any delay that am I missing ?
Upvotes: 1
Views: 135
Reputation: 11
I think you should put your HAL Delay directly below your displayDigit Function. I think the Time between enabling the display and disabling it before switching to the next is to short.
I would try this order Enable digit 0 -> Set Pins for displaying the number -> Wait for x ms -> Disable digit 0 -> Enable Digit 1 -> Set Pins for displying the number .....
I think you realy shortly enable the display but thats too short to see it.
Upvotes: 1