Challenge

Project 1 - Controlling a DC motor using PWM and monitoring its Running status

/* ADC.c
*
* Created: 19-04-2022 15:45:31
* Author : Preeti Mallikarjun
*/
#include <avr/io.h>
#define F_CPU 16000000L
#include <util/delay.h>
#define rs_high() PORTD |=(1<<0);//PD0
#define rs_low() PORTD &= ~(1<<0);
#define en_high() PORTD |= (1<<2);//PD2
#define en_low() PORTD &= ~(1<<2);
#define lcdport PORTB
void lcd_command(unsigned char cmd);
void lcd_data(unsigned char data);
void lcd_init();
void cursorpos(char x, char y);
void lcd_out(char x, char y, char *str);
int main(void)
{
//unsigned int volt=87;
DDRA=0XFF;
lcd_init();
while(1)
{
PORTA = 0x05; //00000001
lcd_out(1,1,"M1 CW ");
lcd_out(2,1,"M2 CW ");
_delay_ms(4000);
PORTA = 0x0A; //00000000
lcd_out(1,1,"M1AntiClockWise");
lcd_out(2,1,"M2AntiClockWise");
_delay_ms(4000);
PORTA = 0x09; //00000000
lcd_out(1,1,"M1 ClockWise ");
lcd_out(2,1,"M2AntiClockWise");
_delay_ms(4000);
PORTA = 0x00; //00000000
lcd_out(1,1,"M1 Stop ");
lcd_out(2,1,"M2 Stop ");
_delay_ms(4000);
}
}
void lcd_command(unsigned char cmd)
{
lcdport = cmd;
rs_low();
en_high();
_delay_ms(1);
en_low();
}
void lcd_data(unsigned char data)
{
lcdport = data;
rs_high();
en_high();
_delay_ms(1);
en_low();
}
void lcd_init()
{
lcd_command(0x38);_delay_ms(5);
lcd_command(0x01);_delay_ms(5);
lcd_command(0x0c);_delay_ms(5);
lcd_command(0x06);_delay_ms(5);
}
void cursorpos(char x, char y)
{
if( (x < 1 || x > 2) || (y < 1 || y > 16) )
{
x = 1;
y = 1;
}
if(x == 1)
lcd_command(0x80+y);
else
lcd_command(0xC0+y);
}
void lcd_out(char x,char y,char *str)
{
cursorpos(x,y);
while(*str)
{
lcd_data(*str);
str++;
}
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.