0% found this document useful (0 votes)
60 views5 pages

Tutorial No.: 4 Tutorial Name: DC-Motor Control

This document provides information on controlling a DC motor using an ATmega16 microcontroller and L293D motor driver. It includes a bill of materials listing the components needed, details on connecting the circuit, and the code to control two motors by toggling the output pins of port C to change the motor's direction of rotation. The code uses delays to demonstrate controlling each motor by alternating the pin states to turn the motor clockwise, counter-clockwise, and to stop rotation.

Uploaded by

M.Sadat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views5 pages

Tutorial No.: 4 Tutorial Name: DC-Motor Control

This document provides information on controlling a DC motor using an ATmega16 microcontroller and L293D motor driver. It includes a bill of materials listing the components needed, details on connecting the circuit, and the code to control two motors by toggling the output pins of port C to change the motor's direction of rotation. The code uses delays to demonstrate controlling each motor by alternating the pin states to turn the motor clockwise, counter-clockwise, and to stop rotation.

Uploaded by

M.Sadat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Tutorial No.

: 4
Tutorial Name: DC-Motor control



Content: page
1. Bill of Materials --------------------------------------------------- 3
2. Circuit connection------------------------------------------------- 4
2.1 Proteus components------------------------------------------4
3. Code----------------------------------------------------------------- 5

1-Bill of Materials:
# Name Quantity
1 ATmega16A-pu 40pin 1
2 Crystal Oscillator 8MHz 1
3 Resistance 10K 1
4 22pF Capacitor 2
5 DC-Motor 12V 1
6 L293D Motor driver (H-birdge) 1















2- Circuit Connection:











2.1 Proteus components:
1. ATmega16.
2. Resistance.
3. Capacitor.
4. Crystal.
5. Motor.
6. L293D motor driver.




3- Code:

#ifndef F_CPU
#define F_CPU 8000000UL // "set the clock to 8MHz"
#endif


#include <avr/io.h> //io.h is AVR ports Header file
#include <util/delay.h> //delay.h is Delay Function Header file
#include <avr/iom16.h> //iom16.h is atmega16 ports Header file

int main(void)
{
DDRC=0xff; // SET ALL PORTC pins as Output
PORTC=0x00; // Initialize PORTC to zero


while(1)
{
//Motor 'M1' control -------------------------------------------------------------

PORTC=(1<<PC0)|(0<<PC1); //Apply '1' on pin0 and '0' on pin1
_delay_ms(100); //Which make the motor "M1" rotate counter-clock wise

PORTC=(1<<PC0)|(1<<PC1); //Apply '1' on pin0 and '1' on pin1
_delay_ms(100); //Which make the motor "M1" stop rotating

PORTC=(0<<PC0)|(1<<PC1); //Apply '0' on pin0 and '1' on pin1
_delay_ms(100); //Which make the motor "M1" rotate clock wise

PORTC=(0<<PC0)|(0<<PC1); //Apply '0' on pin0 and '0' on pin1
_delay_ms(100); //Which make the motor "M1" stop rotating

//Motor 'M2' control--------------------------------------------------------------

PORTC=(1<<PC5)|(0<<PC6); //Apply '1' on pin5 and '0' on pin6
_delay_ms(100); //Which make the motor "M1" rotate clock wise

PORTC=(1<<PC5)|(1<<PC6); //Apply '1' on pin5 and '1' on pin6
_delay_ms(100); //Which make the motor "M1" stop rotating

PORTC=(0<<PC5)|(1<<PC6); //Apply '0' on pin5 and '1' on pin6
_delay_ms(100); //Which make the motor "M1" rotate counter-clock wise

PORTC=(0<<PC5)|(0<<PC6); //Apply '0' on pin5 and '0' on pin6
_delay_ms(100); //Which make the motor "M1" stop rotating

}
}

You might also like