Docsity

Embedded Systems Programming Assignment: Chasing Lights Program - Prof. Stephen Kuyath, Assignments of Electrical and Electronics Engineering

Partial preview of the text

Download Embedded Systems Programming Assignment: Chasing Lights Program - Prof. Stephen Kuyath and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

Embedded Systems Programming

ETEE 3285

Topic HW3: Coding, Compiling, Simulating

Assignment „

Write the

Chasing Lights Program

in C

Use Codevision AVR to compile the programand remove all syntax errors

Simulate the program in AVR Studio, identifyall logic errors {

If logic errors are found, go back to CodevisionAVR and make the necessary changes

Then turn off the leftmost LED and turn onthe next one to its right

LED Sequence

Then shift the on LED to the right again

LED Sequence

LED Sequence

And again

LED Sequence

And again

LED Sequence

And again

LED Sequence

Then start over at the leftmost LED (andcontinue forever)

First Program

Many inexperienced C programmers will write aprogram as shown „

Assuming a 1 is on and a 0 is offvoid main(void){

DDRB = 0xFF;

// PortB is all outputs

PORTB = 0x00;

// turn off all the lights

while(1)

// do forever..

PORTB = 0b10000000;PORTB = 0b01000000;PORTB = 0b00100000;PORTB = 0b00010000;PORTB = 0b00001000;PORTB = 0b00000100;PORTB = 0b00000010;PORTB = 0b00000001; } void main(void){ }

DDRB = 0xFF;

// PortB is all outputs

PORTB = 0x00;

// turn off all the lights

while(1)

// do forever..

PORTB = 0b10000000;PORTB = 0b01000000;PORTB = 0b00100000;PORTB = 0b00010000;PORTB = 0b00001000;PORTB = 0b00000100;PORTB = 0b00000010;PORTB = 0b00000001; } }

While this will work, there are better solutionsThis is what I call a “brute force” program – itis inelegant.

First Program

Many inexperienced C programmers will write aprogram as shown „

Assuming a 1 is on and a 0 is offvoid main(void){

DDRB = 0xFF;

// PortB is all outputs

PORTB = 0x00;

// turn off all the lights

while(1)

// do forever..

PORTB = 0b10000000;PORTB = 0b01000000;PORTB = 0b00100000;PORTB = 0b00010000;PORTB = 0b00001000;PORTB = 0b00000100;PORTB = 0b00000010;PORTB = 0b00000001; } void main(void){ }

DDRB = 0xFF;

// PortB is all outputs

PORTB = 0x00;

// turn off all the lights

while(1)

// do forever..

PORTB = 0b10000000;PORTB = 0b01000000;PORTB = 0b00100000;PORTB = 0b00010000;PORTB = 0b00001000;PORTB = 0b00000100;PORTB = 0b00000010;PORTB = 0b00000001; } }

While this will work, there are better solutionsThis is what I call a “brute force” program – itis inelegant.Let’s enter it in Codevision

Open New Project

Click on File -> New

Open New Project

Click on Project andthen OK

Code Wizard

Here you can change thechip and the clock speed

Ports

You can also initializethe ports