Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start Here: This for-loop calls functions to ground one row of cathodes only during each iteration, and then supplies power to all three columns of

Start Here: This for-loop calls functions to ground one row of cathodes only during each iteration, and then supplies power to all three columns of anodes. This program uses a LOOK-UP TABLE to set which anodes and which cathodes should be on, and uses a counter variable n to cycle through the two tables in unison.

The program builds and runs, but does not meet the functional goal. It has three logic errors.

// STRIPE PROGRAM

#include

#include

#include

// ... Please copy over the same hardware dependencies from Part One...

const uint8_t font[1][5][3] =

{

{ {0, 0, 1},

{0, 1, 0},

{1, 0, 0},

{0, 0, 0},

{0, 0, 0}}};

void init_io(){

clock_prescale_set(clock_div_1);

DDRB = 0x07; // Three pins wired: Anodes.

DDRD = 0x1F; // Five pins wired: Cathodes.

PORTB = 0x00; // Anodes are active-high. Make them inactive.

PORTD = 0x1F; // Cathodes are active-low. Make them inactive.

}

uint8_t cathode(uint8_t row){

return (1<

}

uint8_t anode(uint8_t row){

return (1<<2)*font[0][row][1] | (1<<1)*font[0][row][1] | (1<<0)*font[0][row][0];

}

int main(){

init_io();

while(1){

for (uint8_t n=0; n < 5; n++){

// (TODO: You'll add a line RIGHT HERE later)

PORTD = cathode(n);

PORTB = anode(n);

for (uint32_t k = 0; k < 23456; k++); //delay-loop; TODO: change limit

}

}

}

Think of what you see in terms of electronics -- Only one horizontal row is supposed to be lit; that's the job of the function "cathode". Think -- what C makes one bit low? WRITE A BETTER CATHODE FUNCTION HERE (DELIVERABLE):

uint8_t cathode(uint8_t row){

}

The stripe (which appears dark instead of light at first) is supposed to start in the upper right -- the font table clearly says so. But it runs from the upper left. Left-to-right is the job of the anode(...) function. Just a few keystrokes are wrong. FIX anode(...) HERE (DELIVERABLE):

uint8_t anode(uint8_t row){

}

Please reduce the max-count in the delay loop in main( ) as low as possible. (It's labeled with a TODO in the code.) When you run it, you'll see a double-thickness, flicker-fused, steady-glowing stripe.

Add this line (PORTB = 0x00;) where the code says "// TODO: add a line". This makes "Version 2".

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

What are the advantages of a sole proprietorship and a partnership?

Answered: 1 week ago