In this post I shall demonstrate the usage of Programmers Notepad ,as an IDE to create programs and burn on the target IC.Also ,the creation of Make file will be explained.
These two programs are installed by default along with WINAVR tool chain installation.(Learn to install WINAVR tool chain here ) The Programmers Notepad (PN) acts as an Integrated Development Environment (IDE) where you write your C code,compile it (called “Make All”) & burn it on to the target AVR chip.
A MAKE file tells the compiler what commands to run, what files to compile and link, the sort of output to create, and can also do other things such as programming the chip.
Makefiles have the name Makefile without any extension , and are processed by a program called make. WINAVR has a tool called MFILE (with a magic lamp Icon).It makes life easier , creating the Make file.As they do not have an extension ,make file can not be open by any default program.You can use Notepad to open it.
Keep in handy these items before starting the actual programming :
AVR Dude programmer, a Breadboard, ,Jumper Wires,LEDs,
ATMega16 AVR IC, 6PIN RMC wire with Berg pins
Place the 40 pin AVR IC on breadboard and connect the AVRDude to the ISP pins of AVR Ic starting from pin6 to pin 11.The AVR chip will source its power from the USB connector itself.No separate power supply is required.
Every AVR IC has a set of 6 pins used for In System Programming (ISP),by which you can load your .hex file on to the Target IC without removing the IC from the existing Circuit.
Fig1. Actual Hardware Setup Fig2. Connection between ISP header & AVR pins
Connect these six pins (MOSI,MISO,SCK,RESET,VCC & GND) to the respective pins of header of UsbDude as seen above in Fig2. As you cannot use the 10 pin header on the breadboard, use a 6 pin RMC wire to connect .Connect 2 LEDs ,one at Pin22 (PortC 0) & another at Pin23 (PortC 1) through a 330E current limiting resistor.
Plug in the six pin RMC wire from AVR Dude to the respective pins of AVR IC (pins 6 through 11).Connect the AVRDude to the PC using A-B USB wire.If the driver for USBASP is already installed (if not download it here),Windows recognizes the hardware .
To start programming ,create an empty folder in your C: drive ,say LED_TEST.In this folder we shall store all our programs for this project.
Open up Programmers Notepad & from the drop down where you see “ Plain Text “ select C/C++ .This enables Syntax highlighting while writing your C code.
Type in the following code :
#include <avr/io.h> // header file that enables AVR peripherals
#include <util/delay.h> // header file to use time delayint main (void) //main program starts here
{
DDRC = 0b0000011; /* declaring Data Direction Register C ,pin0 & pin1as Output pins , 1 is for Output & 0 for Input */
while(1) //Never ending loop starts here
{
PORTC = 0b00000011; /* PORTC pins 0 & 1 are made HIGH to makeLEDs glow */
_delay_ms(500); // 500 milli sec delay
PORTC = 0b00000000; // PORTC pins 0 & 1 made LOW
_delay_ms(500); // LEDs off for 500 millisec
}}
Click File & Save As blink_led.c inside the folder you created in C: drive. Do not forget to save the file with extension .c
Now fire up the MFile program
Select from Menu Makefile & make following settings :
MCU type –> ATMega –> ATMega16 (the AVR IC we are using)
Output format –> ihex
Port –> usb
Programmer –> under this we have to select “usbasp” .But it is not in the list.Select any one from the list,say STK500V2 ,and then click “Enable Editing of Makefile”.
Now you can edit the yellow highlighted statement to usbasp
Before saving the mfile ,you have to include your Program name in the Makefile.Scroll down the Make file to locate “TARGET = main “ and change this to
TARGET = blink_led
blink_led is the name of the C file we created earlier.Do not include the .c extension here.
Save this Makefile inside the LED_TEST folder we created.As the Makefile does not have an extension , we cannot assign a default program to open it.However,Notepad can be used to open it.
Watch this support video for this session :
For further details contact :