Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Programming Code

Status
Not open for further replies.

jameschia

New Member
I am using MPLAB, HI TECH compiler for a project.
This project require me to display some word on LCD and I got some question in the following code:

/* write a number of integer to the LCD */
void lcd_number(unsigned int no, char base, char digit)
{
char i,di[10];
for(i=0;i<=9;i++)
di=0;
i=0;
do
{
di=no%base;
no=no/base;
i++;
}
while(no!=0);
for(i=digit;i>0;i--)
{
if(di[i-1]<=9)
lcd_write(i-1,'0');
else
lcd_write(i-1-10,'A');
}
}


what is the purpose of "lcd_write(i-1,'0');" and "lcd_write(i-1,'A');"?
what does the 'O' and 'A' stand for?
why do it use 'O' and 'A', but not straight away display the digit in that variable?
any idea?
 
Here is the same code but indented and commented,
Code:
/* write a number of integer to the LCD */
void lcd_number(unsigned int no, char base, char digit){
    char i,di[10];
    for(i=0;i<=9;i++)			//clear array di
        di[i]=0;
    i=0;
    do{
        di[i]=no%base;			//generate digits
        no=no/base;
        i++;
    }while(no!=0);
    for(i=digit;i>0;i--){		//display digits backward
        if(di[i-1]<=9) 
            lcd_write(i-1,'0');		//display "0" to "9"
        else
            lcd_write(i-1-10,'A');	//display "A" to "F"
    }
}

I'm guessing that '0' and 'A' are the base character. So if di[x] = 0 to 9 it displays "0" to "9" and if it's 10 to 15 it displays "A" to "F".

HTH.

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top