Question

I'm going to do my best to explain exactly what my problem is. I'm currently taking an embedded systems class and I'm really struggling with this portion of the project. I have a small STM32 board with a simple LCD screen connected to it. I have a function already written that will take a single char and write it to the LCD. Now, I often use that function to write char's but there is one scenario in which I need to write an int between 0 and 99 to the screen. The int variable is always changing because it is based on the value in a timer when a user presses the button on the board. I have been stumped by this for hours and I could really use some help. I have emailed my teacher but he isn't replying. Any help is greatly appreciated.

Also, the LCD_write function is already provided to me by my teacher so I can't just create a version of it that will accept an int.

If I haven't given enough detail just let me know.

Was it helpful?

Solution

You just need to convert your int to two chars:

char ch0 = i % 10 + '0'; // convert least significant digit to char
char ch1 = i / 10 + '0'; // convert most significant digit to char

Note: this assumes that you can guarantee that the int is always in the range 0..99.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top