Fill in the blanks. Written in C. A switch is connected to Port A pin 0. Based o
ID: 3582510 • Letter: F
Question
Fill in the blanks. Written in C.
A switch is connected to Port A pin 0. Based on the sequence table, write a C program to monitor the status of the switch and perform the following: (a) If output from the switch is at logic 0, the stepper motor moves counterclockwise (b) If output from the switch is at logic 1, the stepper motor moves clockwise #define F_CPU 8000000UL #include "avr/io.h" #include "util/delay.h" int main () {DDRA = DDRB = while () {if ((PINA&I;)== 0) {PORTB = 0x33; delay_ms(100); PORTB =; delay_ms(100); PORTB =; delay_ms(100); PORTB =; delay_ms(100);} else {PORTB = 0x33; delay_ms(100); PORTB =; delay_ms(100); PORTB =; delay_ms(100); PORTB =; delay_ms(100);}}Explanation / Answer
Dear Student,
Here is the complete program...
program...
#define F_CPU 8000000UL
#include "avr/io.h"
#include "util/delay.h"
int main()
{
DDRA=0x00 //Make port A as an input port
DDRB=0xff //Make port B as an output port
while(1)
{
if(PINA & 0x00) == 0) // if pin0 of PORTA is 0 moves counterclock wise
{
PORTB = 0x33;
delay_ms(100);
PORTB = 0x99;
delay_ms(100);
PORTB = 0xcc;
delay_ms(100);
PORTB = 0x66;
delay_ms(100);
}
//if pin0 of Port A is 1 then moves counterclockwise
else // rotate stepper motro counterclockwise
{
PORTB = 0x33;
delay_ms(100);
PORTB = 0x66;
delay_ms(100);
PORTB = 0xcc;
delay_ms(100);
PORTB = 0x99;
delay_ms(100);
}
}
}
Kindly Check and Verify...Thanks...!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.