Wa0200
Wa0200
Objective
To use all the concepts learnt in lab course so far and apply to interface Stepper motor with Atmega32.
Requirements
● Proteus Professional
Lab Task
Using the concepts of AVRAtmega32, C programming and DC motor, interface a unipolar Stepper motor
with Atmega32.
Turn PD0 on for clockwise and PD1 on for anticlockwise direction. Verify your results using Proteus
simulation.
void main() {
PORTD |= (1<<0);
PORTD |= (1<<1);
DDRC = 0xFF;
while(1){
if((PIND&0x02)==0)
{
PORTC = 0x01;
Delay_ms(400);
PORTC = 0x02;
Delay_ms(400);
PORTC = 0x04;
Delay_ms(400);
PORTC = 0x08;
Delay_ms(400);
else{
PORTC = 0x08;
Delay_ms(400);
PORTC = 0x04;
Delay_ms(400);
PORTC = 0x02;
Delay_ms(400);
PORTC = 0x01;
Delay_ms(400);
}
sbit LCD_RS at PORTB0_bit;
sbit LCD_EN at PORTB1_bit;
sbit LCD_D4 at PORTB2_bit;
sbit LCD_D5 at PORTB3_bit;
sbit LCD_D6 at PORTB4_bit;
sbit LCD_D7 at PORTB5_bit;
void main() {
DDRD &=~ (1<<0);
PORTD |= (1<<0);
DDRD &=~ (1<<1);
PORTD |= (1<<1);
DDRC = 0xFF;
DDB1_bit=1; //this pin sets bit1 to the output
PORTB1_bit=0; //bit0 is reset to enable LCD. Must be declared.
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
if((PIND&0x02)==0)
{
Lcd_Out(1,2,"ANTICLOCKWISE"); // Write text in first row
Lcd_Out(2,2,"DIRECTION"); // Write text in second row
PORTC = 0x08;
Delay_ms(400);
PORTC = 0x04;
Delay_ms(400);
PORTC = 0x02;
Delay_ms(400);
PORTC = 0x01;
Delay_ms(400);
}
else{