Answered You can hire a professional tutor to get the answer.

QUESTION

Photos - Screenshot 2019-02-22 02.png X Photos - Screenshot 2019-02-22 02.png See all photos Add to a creation Edit amp; Create v Share . See all...

We are going to use a set of relays to turn a motor forward and backward when a push button is pressed.

Waiting for an Event

When we want to wait for an event, like the press of a pushbutton, we can use a while loop as follows.

while ((PORTD & 0x80) == 0x80);

The loop condition reads the switch. Since there is no loop body, the above statement just repeatedly checks the loop condition.

Since the switch is connected to VCC, HIGH, when it is not pressed, the port will always read a 1. When the SW pushbutton is pressed, this value is no longer 0x80, and the condition becomes false. 

1.     Build the following circuit. You will use the "P" button of the "Component Mode" to get SPDT relay and a simple DC Motor from the electromechanical sub family. You will get the Push Button for the mechanical sub family.

1.     Observe that the coil relays are connected PIN0 and PIN1 of PORTD. That is to say those 2 pins will need to be programmed as output pin. 

2.     Observe that the push button is connected to PIN7 of PORTD. That is to say, PIN will need to be programmed as an input pin.

3.     As a result, immediately under main(), replace the instruction

DDRD = 0xFF;

by

DDRD = 0b01111111;

4.     Remove all instructions under the infinite while(1) loop and replace them by the following 4 instructions.

while(1)

{

Wait for the pushbutton to be pressed by using the instruction described in the INTRODUCTION above.

PORD = 0x00; //to make spin in one direction.

Wait for the pushbutton to be pressed by using the instruction described in the INTRODUCTION above.

PORD = 0x03; //to make spin in the other direction.

}

5.     Provide a screen capture of your "Source Code" panel to show your codes.

6.     Compile your project and Provide a screen capture of your "VSM Studio Output" panel to show that you have compiled your code successfully.

7.     Run the simulation and click on the push button. The motor should run in one direction. Take a screen capture of the circuit in that condition and paste it in the coversheet.

8.     Click on the push button again. The motor should run in the other direction. Take a screen capture of the circuit in that new condition and paste it in the coversheet.

Photos - Screenshot 2019-02-22 02.05.31.pngXPhotos - Screenshot 2019-02-22 02.05.39.pngSee all photosAdd to a creationEdit & Create v Share. . .See all photosAdd to a creation(ECET330_WK7_Lab - Proteus 8 Professional - Source CodeFile Project Build Edit Debug System HelpXP Debug ] . of# Schematic Capture X 51 Source Code XProjectsmain.c x- @ATMEGA328P(U1)= =ifndef F_CPUECET330 WK7 Lab - Proteus 8 Professional - Schematic CaptureFile Edit View Tool Design Graph Debug Library Template System Help- 5 XE- Source Filesc main.c# define F_CPU 16000000UL // clock speed is 16MHz#include <avr/io.h>#include <utudelay.h>int main(void)#Schematic Capture X " Source Code X7 8{DORD = 0b01111111 ; // declared port D as outputwhile(1) // initialize infinite while loopwhile ((PORTD & 0x80) == 0x80): # Wait for the pushbutton to be pressedPORTD - 0x00; /to make spin in one direction.while ((PORTD & 0x80) -- 0x8f for the pushbuPILPORTD - 0x03; #to make spin in the other direction.ATMEGA328P1/ while loop andCRYSTAL803// main ondLEL-TELLOWMOTORBELLRL1 \10 08 <u+K PBTOCIAPOINTYPEZ/SS/CC1B/PCINT2OUTXDIFCINTUPCINT3265628DX1T8PORKINCRYSTALPCZACCaPON28 882299952 8oost+PCGIADCS SOLDGINTYRESETIPCINT14VSM Studio Outputavr-gcc.exe -Wall -gdwarf-2 -fsigned-char -MD -MP -DF_CPU=1000000 -01 -mmcu=atmega328p -0 "main.o" -c "./main.c"avr-gcc.exe -mmcu=atmega328p -0 "./Debug.elf" "main.o"avr-objcopy -O ihex -R eeprom "/Debug.elf" "/Debug.hex"I1 Mess.. Root sheet 1GO00.0-3500.0 thavr-objcopy -jeeprom --set-section-flags= eeprom="alloc, load" --change-se-section-ima .eeprom=Compiled successfully.--no-change-warnings -O ihex "./Debug.elf"-/Debug.eep" II exit o4 11 Message.. ReadyHi9 4 $ CX N P W OExcel 20162:33 AMDO EMOhp9XNP 3FOE2/22/2019
Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question