Project 1 - Controlling a DC motor using PWM and monitoring its Running status
Explanation:
- Header Files and Definitions:
- The code starts by including necessary header files for AVR programming (avr/io.h and util/delay.h).
- #define statements set the CPU frequency (F_CPU) and define the pins and ports for the LCD.
- LCD Functions:
- Functions (LCD_Command, LCD_Char, LCD_Init, LCD_String, LCD_Clear) are provided to interact with an LCD using 4-bit mode.
- These functions handle sending commands, characters, initialization, displaying strings, and clearing the LCD.
- Motor Control Functions:
- Functions (motor_clockwise, motor_anticlockwise, motor_stop) are defined for controlling a motor connected to pins PA0 and PA1.
- These functions manipulate the motor control pins to run the motor clockwise, anticlockwise, or stop it.
- Main Function:
- The main function initializes PWM and motor pins, sets up the LCD, and enters an infinite loop (while(1)).
- Inside the loop, it runs the motor clockwise for 2 seconds, stops the motor for 0.5 seconds, and then runs the motor anticlockwise for 2 seconds.
- During each operation, it displays the corresponding direction on the LCD and clears the display before the next operation.
- PWM Setup:
- The code assumes an 8-bit PWM setup with a 50% duty cycle (OCR1A = 128).
- Note for ATmega32:
- The LCD pins D4 to D7 are connected to B4 to B7, and adjustments are made in the code to reflect this configuration.
- Loop Continuity:
The program runs indefinitely due to the while(1) loop, continuously rotating the motor and updating the LCD display with the motor's direction.