|
|
Moving from simple a LED glow program to LED blink. But even that won't be a big deal unless you automate the task of recursive compile and upload commands.
This tutorial is aimed at writing a LED blinking program coupled with automating the task of compiling and programming the chip using gnu Makefile.
1. First we start off with writing the LED blink program. There are two ways to do it - use a timer or a delay function. We will take the simpler route for the time being - delay function.
The #define F_CPU 16000000UL specifies the clock frequency used. The lib util/delay contains the source code for the function _delay_ms(delay_in_ms).Thus the function call _delay_ms(1000) will introduce a delay of one second in the toggling of PORTB resulting in the blinking effect.
2. Next we have to compile and upload either using the tedious method in the previous blog or automate it using make which we are about to see.
3. Save this file as Makefile. The file name is case sensitive. The make compiler searches for this file if you type make at the terminal.
Makefile is basically made of two things target and dependencies for that target.Here is the Makefile used for atmega32.
In out case the targets are exec ; compile ; clean.If you type just make then the 'exec:' part of Makefile will get executed.If you type make compile the 'compile:' part will get executed and similarly for make clean.
Now coming to the dependencies part.
The dependency for 'exec:' is compile because if the make command is executed before the make compile then there wont be a hex file to flash the chip. Hence the compile dependency on exec.
The dependency of compile is obviously on the source file $(TARGET). TARGET is the variable containing the source file name without the extension. The touch compile generates a compile file in the same directory having the same timestamp. The make compiler checks the difference between the timestamps of source file and compile file. If the source file is older than the compile file than recompilation is not needed. If the compile file is older than recompilation is needed. The timestamp of a file is changed either by using the touch command or by editing the file in an editor.
Time stamp of ledblink.c is greater. Hence the ledblink.c file has been changed and needs compilation.
Now if we see the timestamp.
We can now use touch ledblink.c to change the timestamp of ledblink.c to current time which makes it new as compared to compile.
Thus the following steps should do the trick
No comments:
Post a Comment