Modelling of Motors : 649479 - Assignment

Added on - 29 Apr 2020

  • 10

    pages

  • 1504

    words

  • 2

    views

  • 0

    downloads

Showing pages 1 to 3 of 10 pages
// led_blink.c- Motor Program 1#define F_CPU 14745600#include <avr/io.h>#include <inttypes.h>#include "../libnerdkits/delay.h"#include "../libnerdkits/lcd.h"// PIN DEFINITIONS://// PC4 -- LED anodeint main() {// Port C bit 3,4 and 5 as outputDDRC |= (1<<PC4) | (1<<PC3) |(1<<PC2) ;// loop keeps looking foreverwhile(1) {// turn on green Motor (PC2) and turn off othersPORTC |= (1<<PC2);PORTC &= ~((1<<PC4) | (1<<PC3) );//delay for 4000 milliseconds to let the Motor stay ondelay_ms(4000);// turn on amber Motor (PC3) and turn off othersPORTC &= ~((1<<PC4) | (1<<PC2) );PORTC |= (1<<PC3);
//delay for 2000 milliseconds to let the Motor stay ondelay_ms(2000);// turn on red Motor (PC4) and turn off othersPORTC &= ~((1<<PC3) | (1<<PC2) );PORTC |= (1<<PC4);//delay for 3000 milliseconds to let the Motor stay ondelay_ms(3000);// switch of all MotorsPORTC &= ~((1<<PC4) | (1<<PC3) | (1<<PC2) );}return 0;}// led_blink.c- Motor Program 2#define F_CPU 14745600#include <avr/io.h>#include <inttypes.h>#include "../libnerdkits/delay.h"#include "../libnerdkits/lcd.h"
// PIN DEFINITIONS://// PC4 -- LED anodeint main() {// Port C bit 2,3 and 4 as outputDDRC |= (1<<PC4) | (1<<PC3) |(1<<PC2) ;// loop keeps looking foreverwhile(1) {// turn on red motor (PC4) and turn off othersPORTC |= (1<<PC4);PORTC &= ~((1<<PC2) | (1<<PC3) );//delay for 3000 milliseconds to let the red motor to stay ondelay_ms(3000);// turn off all motors for 1 secPORTC &= ~((1<<PC2) | (1<<PC3) | (1<<PC4));//delay for 1000 milliseconds to let all motors offdelay_ms(1000);// turn on green Motor (PC2) and turn off othersPORTC &= ~((1<<PC4) | (1<<PC3) );PORTC |= (1<<PC2);//delay for 3000 milliseconds to let motor stay ondelay_ms(3000);
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document