i.
Run the software AVR Studio 5.1
ii.
Click on the New Project
iii. Choose AVRGCC C Executable Project C/C++
Put the file name and location. Click ok.
Put the file name and location. Click ok.
iv.
Now choose ATMEGA32 in the Device selection
list. Click Ok.
v.
A .c file page is open as below
vi.
Write your code here as below.
i. Look
at top 3 lines carefully that describes crystal oscillator frequency (here 16
MHz)
ii. Include
basic header files such as avr/io.h, util/delay.h
iii. DDR
makes data direction for a given port (say in ATMEGA32 ports A,B,C or D). 1
implies output and 0 input. 0xFF has 8 no. of one. Thus DDRD=0xFF makes all 8
port pins of PORT D as output.
iv. PORT
instruction makes the value of the port pins. PORTD=0x01 means all port pins of
PORTD assigned logic 0 except PD0 0 pin. That is PD0 is assigned 1.
vii.
Another instruction PIN gives the status
value of any port pins. Used in conditional statements as below,
In the above statement PORTD^=1<<PD0 implies PORTD pin values are
modified by the bitwise XOR operation with 00000001. i.e. logically PORTD=PORTD
XOR 00000001
viii.
After writing codes click on the Build->Build
Solution or press F7. This instruction generates an equivalent .HEX file under
a sub folder called debug.
ix.
If the codes are correctly written then build
solution provides the message below,
x.
Now hex file is ready to load on your target
board through programmer as below,
Look
the HEX file location selected under Flash memory.
xi.
Reasons to choose Fusebits as hFuse C9 and
lFuse FF is given below,
i. Hfuse
is chosen by default values in table 104 of ATMEGA32 datasheet except
1.
The bit no. 6 Enable JTAG which is
unprogrammed by putting 1.
2.
The bit no. 4 Oscillator options which is programmed
by putting 0.
ii. Lfuse
is chosen by default values in table 105 of ATMEGA32 datasheet except bit nos.
5-0.
iii. From
Table 5 last line is chosen. i.e. CKSEL0=1 and SUT1..0=11
iv. Also
Table4 shows the capacitor selections between 12-22pf and CKSEL3..1=111
v. We
also get the crystal and capacitor connections as below,
No comments:
Post a Comment