QuestionQuestion

The goal of the assignment is use GPIO and delays:
1. Design a delay subroutine to generate a waveform on PORTB.2 with 50% DC and 0.5 sec period.
2. Connect a switch to PORTD.2 (active high - turn on the pull up transistor) to poll for an event to turn on the led at PORTB.2 for 1 sec after the event.
3. Implement Task 1 using Timer 0. Count OVF occurrence if needed. Do not use interrupts.
4. Implement Task 1 using TIMER0_OVF_vect interrupt mechanism.
5. Implement Task 2 using INT0 interrupt mechanism.

Submission:
The following are required for successful completion of the design assignment:
a. AVR ASM code that has been compiled and working for all four tasks. Verify the period and duty cycle of the waveforms in simulation and emulation.
b. AVR C code that has been compiled and working for all four tasks. Verify the period and duty cycle of the waveforms in simulation and emulation.
c. The C code should be well documented with explanation of every instruction.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

; Replace with your application code
start:
    ldi r20, 0b00000100 ; load to r20 the mask to set pin 2 as output
out DDRB, r20 ; Set PIN 2 on port B to output and all others to input
loop:
ldi r20, 0b00000100 ; load to r20 the mask to set pin 2 to 1
out PORTB, r20 ; Set pin 2 to 1 on port B
call delay ; wait for 250ms
ldi r20, 0b00000000 ; load to r20 the mask to set pin 2 to 0
out PORTB, r20 ; Set pin 2 to 0 on port B
call delay ; wait for 250ms
    rjmp loop ; repeat the loop

delay:
; By default on Xplained mini is extenal clock
; On 5V it is at 16MHz
; On 3.3V it is 8MHz
; We have to do a 250ms delay
; On 16MHz 1 clock is 1/16MHz = 62.5ns
; It takes 16 clocks for 1us, if there is a loop which will take 16 clocks (1us) executed 250 times it is 250us.
; Doing this a 250 times, it will elapse 62.5ms
; And doing this 4 times, we will have our 250ms of delay
; There will be some inaccurancy due to setting the values after end of loops.

ldi r16, 4 ; load 4 to r16 - 1 clock
cycle1: ; 4 * 250 * 250us loop = 250ms
ldi r17, 250 ; load 250 to r17 - 1 clock
cycle2: ; 250 * 250us loop = 62.5ms
ldi r18, 250 ; load 250 to r18 - 1 clock
cycle3: ; 250us loop
dec r18 ; decement r18 - 1clock
nop ; no operation, just spend a clock cycle - 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
nop ; 1clock
brne cycle3 ; branch if r18 not 0 - 2 clocks, 1 if no branching
; in total 16 clocks or 1 us
; it will execute 250 times, so it will spend 250us
dec r17 ; decrement r17 - 1 clock
brne cycle2 ; branch if r17 not 0 - 2 clocks, 1 if no branching
; it will execute 250 times, so it will spend 250 * 250us = 62.5ms...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$53.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Electrical Engineering Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats