Disable CLK Pre-scaler in AVR to use 8MHz Internal Oscilator

Just wanted to share this small piece of information that can help many . If you want to Run your AVR at 8MHz from the internal oscillator you need to disable the CLK/8 Fuse. You can do this by burning new fuse values. This can also be done in you main function as well. Below is a piece of code that will change the pre-scaler to zero.

// set the clock speed to "no pre-scaler" (8MHz with internal osc or
// full external speed)
// set the clock prescaler. First write CLKPCE to enable setting of clock the
// next four instructions.
CLKPR=(1< 

Hope this will help!

 

function to return binary equivalent of an int in a string format

On request of Shamas Akhtar Awan :
This is the function to return a string of binary equivalent of an int. The function takes in an integer value and returns a string of 0′s and 1′s of binary equavalet of that integer.

char * int2binarystr(int value) {
    char binstr[23];// adjust the size of the string to your needs
    int i,b;
    b=value;
    i=0;
    while(b>0)
    {
        binstr[i]=b%2;
        b=b/2; i++;
    }
    binstr[i]=00;
    return binstr; // returns the string
}

You can use this in your code as needed. One example is to write to uart the string

Uart0_write_text(int2binarystr(20)); // writes the string conataing the binary equavalent of 20 to uart