문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top