Project 1 - Controlling a DC motor using PWM and monitoring its Running status
MAGNA
CODE
#include <avr/io.h>
#define F_CPU 16000000L
#include <util/delay.h>
// storing the hex value of the number which has to be displayed in the 7-segment display in a array
unsigned char seven_seg[10] = {0X3F, 0X06, 0X5B, 0X4F, 0X66, 0X6D, 0X7D, 0X07, 0X7F, 0X6F};
int main(void)
{
DDRC |= 0XFF; // SET PORT C AS OUTPUT
DDRA |= 0XFF; // SET PORT B AS OUTPUT
unsigned int i=0; // variables used for accessing the values from the array
unsigned int j=0;
while (1)
{
PORTA = seven_seg[i]; // assigning the port-A with first value of array
PORTC = seven_seg[j]; // assigning the port-C with first value of array
for (i=0; i<10; i++)// loop for incrementing i and accesing the array
{
PORTC = seven_seg[i];// left hand side number in a two digit number
for (j=0; j<10; j++)
{
PORTA = seven_seg[j];// right hand side number in a two digit number
_delay_ms(500);
}
}
}
}
