Challenge

Project 1 - Controlling a DC motor using PWM and monitoring its Running status

Magna Electronics Bangalore

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

char seven_seg[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67}; //Common Cathode //Configuration

int main(void)
{
DDRB = 0XFF; //Set PortB as output
DDRD = 0XFF; //Set PortD as output
while (1)
{
for(int i=0;i<10;i++)
{
PORTB = seven_seg[i]; //Displaying the digits(0-9) acc to char array
for(int j=0;j<10;j++)
{
if(j==9) //If 9th digit is encountered reset to 0
{
PORTD = seven_seg[j];
_delay_ms(500);
PORTD = seven_seg[0];
}
else
{
PORTD = seven_seg[j];
_delay_ms(500);
}
}
}
}
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.