Saturday, June 6, 2009

PARALLEL PORT PROGRAMMER FOR ATMEGA 16/32


PARALLEL PORT PROGRAMMER FOR
ATMEGA 16/32

In-system programmer means we can design a programmer circuit using simple parallel port interfacing such that our controller can be directly burned with the program while in the designed system or circuit board.

Following pins of Atmega16 is used in programmer circuit-

Pin NO.

Description

6

MOSI (SPI Bus Master Output/Slave Input

7

MISO (SPI Bus Master Input/Slave Output)

8

SCK (SPI Bus Serial Clock)

9

Reset

10

Vcc

11

Ground

Table-Atmega16 Pins

• SCK – Port B, Pin 7

SCK: Master Clock output, Slave Clock input pin for SPI channel. When the SPI is enabled as a Slave, this pin is configured as an input regardless of the setting of DDB7.When the SPI is enabled as a Master; the data direction of this pin is controlled by DDB7. When the pin is forced by the SPI to be an input, the pull-up can still be controlled by the PORTB7 bit.

• MISO – Port B, Pin 6

MISO: Master Data input, Slave Data output pin for SPI channel. When the SPI is enabled as a Master, this pin is configured as an input regardless of the setting of DDB6. When the SPI is enabled as a Slave, the data direction of this pin is controlled by DDB6. When the pin is forced by the SPI to be an input, the pull-up can still be controlled by the PORTB6 bit.

• MOSI – Port B, Pin 5

MOSI: SPI Master Data output, Slave Data input for SPI channel. When the SPI is enabled as a Slave, this pin is configured as an input regardless of the setting of DDB5. When the SPI is enabled as a Master, the data direction of this pin is controlled by DDB5. When the pin is forced by the SPI to be an input, the pull-up can still be controlled by the PORTB5 bit.

• RESET-Pin 9

Reset Input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running.

• VCC -Pin 10

Digital supply voltage(+5V).

•GND-Pin-11

Ground.

Parallel Port-

Parallel Port interfacing is the simplest method of interfacing. Parallel Port’s are standardized under the IEEE 1284 standard first released in 1994. It has data transfer speed up to 1Mbytes/sec. Parallel port is basically the 25 pin Female connector (DB-25) in the back side of the computer (Printer Port). It has 17 input lines for input port and 12 pins for output port. Out of the 25 pins most pins are Ground and there is data register (8 bit), control register (4 bit) and status register (5 bit).



Following Pins are used in parallel port-

Pin No.

Description

7,8,9

Data pins

10

Status pin

19

Ground

Table- Parallel Port Pins

Interfacing -

In programmer circuit pins of parallel port which are above described has to interface with pins of ATmega16 microcontroller which are responsible for in-system programming. The parallel port can be interfaced directly with microcontroller. To avoid reverse current we can use Schottkey diodes as safety precaution for pc motherboard.

Following pins of Parallel Port and ATmega16 are to be interfaced-

Parallel Port

Atmega16

Pin 7

Reset (Pin 9)

Pin 8

SCK (Pin8)

Pin 9

MOSI (Pin6)

Pin 10

MISO(Pin7)

Pin 19

Ground(Pin11)

Interface Connections


Fig-Circuit Diagram of ATmega16 Programmer


Fig. The Snapshot


SOFTWARES USED:

WinAVR– WinAVR is open source package in which we use two sub-programs

Programmers Notepad & Mfile.

Version- 2.0.8.718-basic

Creator- Simon Steele

Purpose- 1. To write code.

2. To compile coding.

3. To generate Hex Code.

4. To burn Hex code.

The next tutorial will make you aware with how to install and use WinAVR for compiling and burning the program.

For a very good Tutorial on AVR USB Programmer, follow this link:

http://www.embedautomation.com/lectureseries

Regards:

Aditya Sharma

(http://robozeal.blogspot.com)

Installing and Using WinAVR for Parallel Port Programmer

Installing and Using WinAVR for

Parallel Port Programmer

After successfully designing the Parallel port programmer in our previous tutorial, now we will be learning how to install and work on the software for programming the MCU.

WinAVR– WinAVR is package in which we use two sub-programs

Programmers Notepad & Mfile.

Name - Programmers Notepad & Mfile

Version- 2.0.8.718-basic

Creator- Simon Steele

Purpose- 1. To write code.

2. To compile code.

3. To generate Hex File.

4. To burn Hex File.

Installing WinAVR:

1. Download WinAVR setup from this link:-

http://sourceforge.net/project/showfiles.php?group_id=68108

2. Install WinAVR into C:\ WinAVR-20090313

3. Now go to Start-->Run-->(cmd.exe), i.e. go to command prompt.

4. Go to the following directory C:\WinAVR-20090313\bin.

5. Type this command “install_giveio” and press ENTER.

6. You should get the “Success” message as shown in the snapshot below.

5. Check the status by the command “status_giveio”.

6. Installation of WinAVR is complete now.


Screenshot of Command Prompt Window (CLick To Enlarge)


Screenshot of Programmers Notepad (CLick To Enlarge)

Steps for Compiling and Burning Process-

1. Open Programmers Notepad [WinAVR] from “StartàAll programs à WinAVR-20090313”, write the code. Save the program into a specified folder whose name is same as the File name.

2. Open MFile [WinAVR] from “StartàAll programs à WinAVR-20090313” apply following steps-

I. Select Microcontroller type which is Atmega16 or Atmega32 whichever you are using.


(CLick To Enlarge)

II. Select output format as “ihex”.

III. Select Debug format as “avr-ext-COFF (AVR Studio 4.07+, VMLAB3.10+).


(CLick To Enlarge)

IV. Select programmer option as “bsd”.

V. Select output port as lpt1 because we are using Parallel port (0X378 is the address of Parallel port).

VI. Save As the file as Mfile format in the same folder where the program file is saved. Name of the Mfile should me kept Makefile only; don’t change it to any other name.

VII. Reopen the saved Mfile in Notepad.exe and correct F_CPU to 1 MHz and write the target name same as Program file name. Save the Mfile.


(CLick To Enlarge)

3. Open programmer Notepad select Tools à[WinAVR] Make All option to compile and create hex code Hex code.

4. After successful compilation the hex file is saved automatically into the same folder in which the program file and the Makefile are already saved.

5. Connect parallel port of burner to the CPU of your PC and select Tools à[WinAVR] Program option to burn Hex code.

6. Below is the snapshot of the output window which displays all the actions being taken and their status.


(CLick To Enlarge)

COMMON ERRORS ENCOUNTERED

First Error

avrdude: AVR device not responding

avrdude: initialization failed, rc=-1

Double check connections and try again, or use -F to override

this check.

avrdude done. Thank you.

make.exe: *** [program] Error 1

Second Error:

avrdude: Device Signature=0xffffff.

avrdude: Yikes! Invalid device Signature.

Double check connections and try again, or use -F to override

this check.

avrdude done. Thank you.

make.exe: *** [program] Error 1

TROUBLESHOOTING

1. First check whether your parallel port is working or not using lpt.exe.

2. See bios settings. Better set for bidirectional mode, but spp and ecp modes will also work. See the address of the parallel port (0x378).

3. You connected reset pin to external Vcc or GND ( disconnect it)

4. External power supply may be off.

5. Parallel port cable may be not fitted properly.

6. See whether u interchanged MISO and MOSI.

7. See for short-ckt between pins.

8. See for any loose connection in wires using Continuity tester of multimeter.

9. Ground of power supply and parallel port should be short circuited.

Enjoy working with AVR now…

Regards:

Aditya Sharma

http://robozeal.blogspot.com

Thursday, June 4, 2009

Alternate Flashing of 8 LEDs using 8051



Alternate Flashing of 8 LEDs using 8051




Assembly Program:

ORG 0

MOV A, #55H

AGAIN: MOV P0, A

ACALL DELAY

CPL A

SJMP AGAIN

DELAY: MOV R2, #7

HERE1: MOV R1, #255

HERE2: MOV R0, #255

HERE3: DJNZ R0, HERE3

DJNZ R1, HERE2

DJNZ R2, HERE1

RET

END


Delay Calculation:

Crystal used- 4 MHz

Machine cycle frequency = (Crystal Frequency) / (Clocks per machine cycle)

= 4/12

= 0.3333 MHz

Time Period of Machine Cycle = 1/0.33

= 3.003us (microseconds)

No. of machine cycles = 1(for MOV A, #55H) + 1(for MOV P0, A)

= 2 cycles

Total Delay = 7 * 255 * 255 * 2 * 3.003

= 2733781.05us

= 2.73 seconds

Thus the LEDs will show alternate blinking after every 2.73 seconds; the delay can be adjusted as per the requirement by just varying the values of registers R0, R1 or R2.

Why alternate blinking?

Initially value at P0 = #55h

55h in binary- 0 1 0 1 0 1 0 1.

Thus LEDs status is-

LED 1- 0(low) : GLOW

LED 2- 1(high) : OFF

LED 3- 0(low) : GLOW

LED 4- 1(high) : OFF

LED 5- 0(low) : GLOW

LED 6- 1(high) : OFF

LED 7- 0(low) : GLOW

LED 8- 1(high) : OFF


After delay of 2.7 seconds CPL A is executed

Now Value at P0 = #AAh

AAh in binary- 1 0 1 0 1 0 1 0

Thus LEDs status is-

LED 1- 1(high) : OFF

LED 2- 0(low) : GLOW

LED 3- 1(high) : OFF

LED 4- 0(low) : GLOW

LED 5- 1(high) : OFF

LED 6- 0(low) : GLOW

LED 7- 1(high) : OFF

LED 8- 0(low) : GLOW


Regards:

Aditya Sharma (heloitsadi)

http://robozeal.blogspot.com