# Using STM32F10x RTC to trigger some function

I am a new hand to STM32F1x and I am trying to do a project that really needs to use the RTC/TIM function.

What I am trying to do is to display a 20 second count-up timer on the LCD. Something that looks like:

TIMER: 12.34 s

So what I want to write in the program is:

var s =0
if "counted 1s "
{
drawchar (3, 1, s)
s++
}
if "counted 10s"
{
drawchar(3, 0, x)
x++
}


So the problem is what to write in order to get:

if (counted 1s);


Thank you very much and sorry, that I don't really have much knowledge on it.

Let me explain more, base on my little knowledge. What I know is like, when I press a button, I can do sth/ interrupt.

while(1){

LCD_DrawString(0, 0, name, 8);

}
}


Thats basically what I can do.

So, instead of pressing a button to draw sth, I would like to make it draw when the timer/RTC rising edge.

• What is your development environment? (library, IDE) – Bence Kaulics Nov 11 '16 at 9:23
• What did you try so far? – Batuu Nov 11 '16 at 9:29
• It is not clear, you want to count with 1 second resolution or 0.01 second resolution. – Bence Kaulics Nov 11 '16 at 9:33
• I use IAR embedded system workbench So far I dun know anything any RTC but i did use the TIM3 to generate a 100Hz impulse train. – Tse Kelvin Nov 11 '16 at 14:05
• Search for Timer examples using SPL. – Bence Kaulics Nov 11 '16 at 14:29

Configure and enable the hardware timer so that it provides an interrupt every 10 milliseconds. (Read the datasheet or find examples of how to do this.) In the timer's ISR, increment a counter so that the counter value represents the number of 10 ms periods that have occurred since the counter was reset. Draw the four digits from the counter value on the display and draw a decimal point between the middle digits. There's many different ways to do this. For example you could use sprintf to convert the counter value into a string and then call LCD_DrawString. Or you could repeatedly divide the counter value by 10 to extract a single digit and then call drawchar for each digit.