Question

I need this in assembly language please. Use Dragon12-Light (or Dragon12-Plus2) Evaluation Board and the CodeWarrior...

I need this in assembly language please. Use Dragon12-Light (or Dragon12-Plus2) Evaluation Board and the CodeWarrior IDE to develop the following programs.The first one is to write a program that implements an 8 bit up counter on the 8 LEDs. Increment the counter every second.The second one is to write a program that generates a noise of 500Hz on the speaker on your board.Thank you so much!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code for the implementation of 8 bit up counter on the 8 LED,

/* source: https://www.electroschematics.com/9809/arduino-8-bit-binary-led/ */
int button = 2;                 // pin to connect the button
int presses = 0;                // variable to store number of presses
long time = 0;                  // used for debounce
long debounce = 100;    // how many ms to "debounce"
const byte numPins = 8; // how many leds
int state;                              // used for HIGH or LOW
 // pins to connect leds
byte pins[] = {5, 6, 7, 8, 9, 10, 11, 12};

void setup()
{
        /* we setup all led pins as OUTPUT */
        for(int i = 0; i < numPins; i++) {
                pinMode(pins[i], OUTPUT);
        }
        pinMode(button, INPUT);
        /* use pin 2 which has interrupt 0 on Arduino UNO */
        attachInterrupt(0, count, LOW);
}

void loop()
{
        /* convert presses to binary and store it as a string */
        String binNumber = String(presses, BIN);
        /* get the length of the string */
        int binLength = binNumber.length();     
        if(presses <= 255) { // if we have less or equal to 255 presses
                // here is the scary code
                for(int i = 0, x = 1; i < binLength; i++, x+=2) { 
                        if(binNumber[i] == '0') state = LOW;
                        if(binNumber[i] == '1') state = HIGH;
                        digitalWrite(pins[i] + binLength - x, state);
                }       
        } else {
                // do something when we reach 255
        }
}

/* function to count the presses */
void count() { 
        // we debounce the button and increase the presses
        if(millis() - time > debounce)       presses++;
        time = millis();
}
Add a comment
Know the answer?
Add Answer to:
I need this in assembly language please. Use Dragon12-Light (or Dragon12-Plus2) Evaluation Board and the CodeWarrior...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT