Center Justification for C - printf

No comments :

I was working on a project usig an avr controller and glcd for showning the user options menu. For the menu entries we were using sprintf function to create a string and then passing it to the glcd library functions. Inorder to align the printed text, I searched for the justification options availale with printf/sprintf functions.
After a lot of searching, I found that only left justification and right justification supported, so we have to use some tecniques or custom functions to align the text. Finally from a forum, I got a smart piece of code.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
void f(char *s) 
{ 
        printf("---%*s%*s---\n",10+strlen(s)/2,s,10-strlen(s)/2,""); 
} 
int main(int argc, char **argv) 
{ 
        f("uno"); 
        f("quattro"); 
        return 0; 
}

Read More

Portable WinAVR - Compile AVR code on PC where WinAVR is not installed

No comments :

from chip45

While searching a bootloader for my project board with atmega32, I have found lot of bootloader projects. But all those were projects/makefile made to compile with WinAVR or IAR. Since there was only Codevision avr available at my work PC, I was not able to install WinAVR. So I started searching for a method to compile the project without WinAVR istallation.
After searching lot I found that there is a portable version of WinAVR available here. It was described in WinAVR project page as written below.
You can try WinAVRTM out with Portable WinAVRTM, a version that doesn't require an install. And when you get hooked on WinAVRTM, you can put Portable WinAVRTM on a USB key and take it everywhere with you! School, work, the library, the dentist, and more!
 This portable version is available for download from chip45. Here I have uploaded my copy which I have donwloaded, in case it is not available at any time. But before uisng it we need to go through the quick start guide, because the folders and batch file to invoke the command line needs to be placed in the root and some files need to be edited.

Read More