Project 1 - Controlling a DC motor using PWM and monitoring its Running status
MAGNA
1. Program to display the numbers from 00 to 99 in seven segment display
#include <avr/io.h>
#define F_CPU 16000000L
#include <util/delay.h>
char seg[10]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F}; //hexadecimal code to display each numbers
int main(void)
{
DDRA=0XFF;
DDRC=0XFF; //Set port A and port C as outputs
int i=0; //initialize the variables to zero
int j=0;
PORTA=seg[i]; //initialize the port A with the zeroth segment as present in the hexadecimal encoding
PORTC=seg[j];
for(i=0;i<10;i++) //outer loop to display the starting numbers from 0 to 9
{
PORTA=seg[i];
for(j=0;j<10;j++) //inner loop to display the numbers from 0 to 9
{
PORTC=seg[j]; //assign the output to port C
_delay_ms(500); //delay of 500 ms
}
}
}