This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Program to print decimal no. 13 on LCD

hi friends i am trying to print all the decimal no's on LCD but i am able to print till 9 only after that i am getting : ; so on

Parents
  • Either make use of sprintf() to convert your number into a string of one or more characters. Then loop through the full length of the string and emit the characters one-by-one.

    Or convert the number by repetetively extracting the smallest digit and reducing the number by a factor 10. Emit the digits in reverse order.

    void lcd_print_num(unsigned num) {
        char queue[MAX_QUEUE_DEPTH];
        unsigned queue_pos = 0;
    
        while (num > 0) {
            queue[queue_pos++] = (num % 10) + '0';
            num /= 10;
       }
        if (queue_pos == 0) queue[queue_pos++] = '0';
    
        while (queue_pos) {
            lcd_print_character(queue[--queue_pos]);
        }
    }
    

Reply
  • Either make use of sprintf() to convert your number into a string of one or more characters. Then loop through the full length of the string and emit the characters one-by-one.

    Or convert the number by repetetively extracting the smallest digit and reducing the number by a factor 10. Emit the digits in reverse order.

    void lcd_print_num(unsigned num) {
        char queue[MAX_QUEUE_DEPTH];
        unsigned queue_pos = 0;
    
        while (num > 0) {
            queue[queue_pos++] = (num % 10) + '0';
            num /= 10;
       }
        if (queue_pos == 0) queue[queue_pos++] = '0';
    
        while (queue_pos) {
            lcd_print_character(queue[--queue_pos]);
        }
    }
    

Children
No data