NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Convert uint8_t to char

January 31, 2010
by saleem
saleem's Avatar

Hi,

I would like to display value from PORT PIN to LED Marquee - the function below accepts a char parameter:

//From Nerdkit LED Marquee sample void font_display(char c, uint8_t offset) {

char buf[7];

font_get(c, buf);

uint8_t width = buf[1];

uint8_t i, j;

for(i=0; i<ROWS; i++) 
{

    for(j=0; j<width; j++) 
    {

        if((offset + j) < COLS) 
        {

            if( (buf[2+j] & (1<<i)) != 0) {

                  ledarray_set(i,offset + j,1);

            } 
            else {

                ledarray_set(i,offset + j,0);

            }

        }

    }

 }

I read a value from Port like this:

uint8_t value = PIND (for example)

now I want to pass this value to font_display(value,1)

it doesn't work!

How can I cast uint8_t to char.

Thx

Saleem

January 31, 2010
by pbfy0
pbfy0's Avatar

I think just doing this would work.

font_display((char) (PINB + '0'));

you need to add '0' so you get the so if PINB's 0 you get the character 0 instead of the number 0 (ascii null)

February 01, 2010
by saleem
saleem's Avatar

Thanks pbfy0,

That worked.

Saleem

Post a Reply

Please log in to post a reply.

Did you know that our USB NerdKit comes with everything you need to get started with microcontrollers? Learn more...