This is another digital input output of ATMega32. In this example I use a single Port of PORTC accepting the digital input from button, and output the control to DC motor.
I use L293 for controlling the direction, and also driving the motor at higher voltage and higher current at +12 V.
Three input buttons are Forward, Stop and Backward. Motor is controlled by PC0 and PC1 pin on the same port. |
Source Code:
/*
* controllingMotorStartStop.c
*
* Created: 4/25/2020 8:00:39 PM
* Author : aki-technical
*/
#include <avr/io.h>
#define F_CPU 16000000UL
#include "util/delay.h"
//Test the PINC7
#define forward (PINC&0b10000000)
//Test the PINC6
#define stop (PINC&0b01000000)
//Test the PINC5
#define backward (PINC&0b00100000)
//OUTPUT DATA FOR MOTOR
#define run_forward 0b11100001
#define run_backward 0b11100010
#define stop_running 0b11100000
int main(void)
{
DDRC=0b00011111; //PINC7.5 INPUT
PORTC=0b11100000; //PC7.5 SET TO HIGH
/* Replace with your application code */
while (1)
{
if (forward==0)
{
PORTC=stop_running;
_delay_ms(250);
PORTC=run_forward;
}
else if (stop==0)
{
PORTC=stop_running;
_delay_ms(250);
PORTC=stop_running;
}
else if (backward==0)
{
PORTC=stop_running;
_delay_ms(250);
PORTC=run_backward;
}
}
}
Back to main tutorial page ATMega32 tutorials in C with Atmel Studio 7.
if i want to change the speed of the motor, what should i do?
ReplyDeleteUse PWM https://aki-technical.blogspot.com/2020/06/using-adc-of-atmega32-to-adjust-pwm.html
DeleteThis is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog.. Wohnmobilvermietung Freiburg
ReplyDeleteThanks You
Delete