100% found this document useful (2 votes)
59 views

#Include #Define #Include Int Void: " Microp&Interf"

This document contains code to control a DC motor and LCD display using inputs from Port A of an AVR microcontroller. It initializes Ports B, C, and D for output and Port A for input. It then enters a loop where different motor directions are set by writing to Port C based on the input states on Port A, and corresponding text messages are displayed on the LCD.

Uploaded by

Lee yi kang
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
100% found this document useful (2 votes)
59 views

#Include #Define #Include Int Void: " Microp&Interf"

This document contains code to control a DC motor and LCD display using inputs from Port A of an AVR microcontroller. It initializes Ports B, C, and D for output and Port A for input. It then enters a loop where different motor directions are set by writing to Port C based on the input states on Port A, and corresponding text messages are displayed on the LCD.

Uploaded by

Lee yi kang
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/ 2

/*

* Relay_DCMotor.c
*
* Created: 1/4/2015 10:40:41 AM
* Author: User
*/

#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>

int main(void)
{
DDRC = 0xFF; //Port C as output
DDRA = 0x00; //Port A as input
PORTA = 0xFF; // Pull up Port A

while(1)
{
//TODO:: Please write your application code
if (PINA==0xFE)
{
PORTC = 0x01; //High output pin PC0
}
else if(PINA==0xFD)
{
PORTC = 0x02; //High output pin PC1
}
else
{
PORTC = 0x00; //reset Port C
}
}
}

/*
* Relay_DCMotor_LCD.c
*
* Created: 1/4/2015 12:03:38 PM
* Author: User
*/

#include<avr/io.h>
#define F_CPU 8000000
#include<util/delay.h>

#define LCD_DATA_PORT PORTB


#define LCD_CONT_PORT PORTD
#define LCD_RS PD0
#define LCD_RW PD1
#define LCD_EN PD2

#include<avr/lcd.h>
//#include<avr/adc.h>

int main(void)
{
DDRB=0xFF;
DDRC=0xFF;
DDRD=0x07;
DDRA=0x00;
PORTA=0xFF;

lcd_init();
/*LCD initialization*/

lcd_string_write(" MicroP&Interf");
/*String display in 1st row of LCD*/

lcd_command_write(0xc0);
/*Cursor moves to 2nd row 1st column of LCD*/

lcd_string_write(" Relay_DCM_LCD");
/*String display in 2nd row of LCD*/

_delay_ms(100);
_delay_ms(100);
//_delay_ms(500);
//_delay_ms(500);
/*Display stays for 2 second*/

lcd_command_write(0x01);
/*Clear screen*/

lcd_string_write("<<DC_MOTOR_MOV>>");
/*String display in 1st row of LCD*/

/*Start of infinite loop*/


while(1)
{
if (PINA==0xFE)
{
PORTC = 0x01; //High output pin PC0
lcd_command_write(0xc0); //*Cursor moves to 2nd row 1st column of LCD*/
lcd_string_write("-->>>M1_FWD_DIR!!"); //*String display in 2nd row of LCD*/
}

else if (PINA==0xFD)
{
PORTC = 0x02; //High output pin PC1
lcd_command_write(0xc0); //*Cursor moves to 2nd row 1st column of LCD*/
lcd_string_write("<<<--M1_REV_DIR!!"); //*String display in 2nd row of LCD*/
}
else
{
PORTC = 0x00; //reset Port C
lcd_command_write(0xc0); //*Cursor moves to 2nd row 1st column of LCD*/
lcd_string_write("###_M1_STOP_###"); //*String display in 2nd row of LCD*/
}
}
}

You might also like