Question

Use HCS12 assembly language only - not C code Using CodeWarrior to create a new project...

Use HCS12 assembly language only - not C code

Using CodeWarrior to create a new project that uses assembly language. Write an assembly program that turns on the red LED at the beginning. It switches to off 2 seconds later and switches back to on after three more seconds. (That is, it stays on for 2 seconds and off for 3 seconds.) This switching process lasts forever. Use a loop (or nested loops) for each of the 2/3-second delay where the loop body of the inner-most loop should contain only multiple instances of the NOP instruction. Use trial-and-error in adjusting the loop iterations to achieve the delay. Write down instructions in the (nested) loops of your program, identify the number of clock cycles needed for each instruction in the loops, and calculate the total number of cycles to get the amount of delay. Use that information to calculate the clock speed of the CPU in MHz, given that the clock speed is an integer in MHz.

Hint: You may use the DBNE instruction for the loop control. In order to find out the number of clock cycles for a particular HCS12 CPU instruction, you may either get it from the data sheet or use the Full Chip Simulation in CodeWarrior, in case you have trouble determining the proper machine code version from the data sheet.

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

int ledPin1 = 5; // the number of the LED pin
int ledState1 = LOW; // ledState used to set the LED
unsigned long previousMillis1 = 0; // will store last time LED was updated
long OnTime1 = 2000; // milliseconds of on-time
long OffTime1 = 2000; // milliseconds of off-time

int ledPin2 = 6; // the number of the LED pin
int ledState2 = LOW; // ledState used to set the LED
unsigned long previousMillis2 = 0; // will store last time LED was updated
long OnTime2 = 5000; // milliseconds of on-time
long OffTime2 = 1000; // milliseconds of off-time

void setup()
{
  // set the digital pin as output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop()
{
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();

  if((ledState1 == HIGH) && (currentMillis - previousMillis1 >= OnTime1))
  {
   ledState1 = LOW; // Turn it off
   previousMillis1 = currentMillis; // Remember the time
   digitalWrite(ledPin1, ledState1); // Update the actual LED
  }
  else if ((ledState1 == LOW) && (currentMillis - previousMillis1 >= OffTime1))
  {
   ledState1 = HIGH; // turn it on
   previousMillis1 = currentMillis; // Remember the time
   digitalWrite(ledPin1, ledState1);   // Update the actual LED
  }
  
  if((ledState2 == HIGH) && (currentMillis - previousMillis2 >= OnTime2))
  {
   ledState2 = LOW; // Turn it off
   previousMillis2 = currentMillis; // Remember the time
   digitalWrite(ledPin2, ledState2); // Update the actual LED
  }
  else if ((ledState2 == LOW) && (currentMillis - previousMillis2 >= OffTime2))
  {
   ledState2 = HIGH; // turn it on
   previousMillis2 = currentMillis; // Remember the time
   digitalWrite(ledPin2, ledState2);   // Update the actual LED
  }
}

Add a comment
Know the answer?
Add Answer to:
Use HCS12 assembly language only - not C code Using CodeWarrior to create a new project...
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
  • Assume the memory display of the HCS12 shows 16 bytes starting at S0800 as follows SOBO0...

    Assume the memory display of the HCS12 shows 16 bytes starting at S0800 as follows SOBO0 80 53 05 28 36 89 00 FF FE 80 91 3E 77 AB 8F 7F Cavt the results of the following instructions SP S0805 pula A ?, SP SP S08OAL pula pshb A 7, SP -? SP S0805 pula A ? pulb B Idaa $O803 Idab $0804 aba A 7,8- SP $0805 psha pshb SP 7 Idx S0800 idab $0807 leax B.X X...

  • Design and implement a C Language program that measures the performance of given processors. There are...

    Design and implement a C Language program that measures the performance of given processors. There are several metrics that measure the performance of a processor. We will be using the following 3 measures: 1.CPI (clock cycles per instruction) = #clock cycles /#instructions 2.CPU execution time = #instructions x CPI x clock cycle time . cylce time = 1/CPU clock rate in hertz units 3.MIPS (mega instructions per second)= #instrucrions/ CPU X 1000000 Typically, processors’ performance is measured using a wide...

  • Consider the following assembly language code. The clock frequency is 4 MHz- and all initialization steps...

    Consider the following assembly language code. The clock frequency is 4 MHz- and all initialization steps have been done correctly (like setting up digital I/O, the oscillator configuration, etc.) Constants Bit Pattern EQU H'20' LoopCtr EQU H'21' Max Count EQU .23; Main program loop MainLoop CLRF BitPattern CALL Output BSF BitPattern, 1 CALL Output RRF BitPattern CALL Output BSF BitPattern, 1 CALL Output GOTO MainLoop Output MOVF BitPattern, W MOVWF PORTB MOVLW MaxCount MOVWF LoopCtr Loop NOP DECFSZ LoopCtr GOTO...

  • 4. In this problem you will use CodeWarrior to develop the code to implement a three-light...

    4. In this problem you will use CodeWarrior to develop the code to implement a three-light traffic signal. The program should do the following: a. Turn on a green LED attached to Port B bit 2 for 60 seconds, b. Turn off the green LED and turn on a yellow LED attached to Port B bit 1 for 30 seconds, c. Turn off the yellow LED and turn on a red LED attached to Port B bit 0 for 60...

  • Use HCS12 assembly language only! Write a program sequence to interface with seven-segment display and the RGB LED on th...

    Use HCS12 assembly language only! Write a program sequence to interface with seven-segment display and the RGB LED on the Dragon12- Light board. Your program should display digit '2' on the DIGI and blue light on the RGB LED the m should digplay digi 2 Write a program sequence to interface with seven-segment display and the RGB LED on the Dragon12- Light board. Your program should display digit '2' on the DIGI and blue light on the RGB LED the...

  • 4) Consider the following assembly language code: INSTRUCTIONS T01 T02 T03 T04 T05 T06 T07 T08...

    4) Consider the following assembly language code: INSTRUCTIONS T01 T02 T03 T04 T05 T06 T07 T08 T09 T10 T11 T12 T13 T14 (as a table) Loop: sll $t1, $s3, 2 add $t1, $t1, $s6 lw $t0, 0($t1) beq $t0, $s5, Exit addi $s3, $s3, 1 j Loop Exit: Use a pipeline with forwarding, hazard detection, and 1 delay slot for branches. The pipeline is the typical 5-stage IF, ID, EX, MEM, WB MIPS design. For the above code, complete the...

  • Using C code codewarrior how can I create a loop that it will display 1 through 9 with a delay...

    using C code codewarrior how can I create a loop that it will display 1 through 9 with a delay between each number /Exaple 1a Turn on every other seguent on 7-seg display #include chideth) #include /* derivative information */ #pragna LINK-INFO DERIVATIVE "nc9s12dg256b" /CONNon defines and nacros/ 0 #include "nain-asn h" /* interface to the assenbly nodule */ /*put your own code here / PLL init() 52 // set systen clock frequency to 24 MHz 28. DDREOxff DDRP 0xff...

  • Step 1. Write a program in assembly language (using macros) to print out the following messages...

    Step 1. Write a program in assembly language (using macros) to print out the following messages on the screen [20 marks]: Hello, programmers! Welcome to the world of, Linux assembly programming! Step 2. Write a C function to passed two numbers to the function and calculate the sum of all the numbers between them (both inclusive). [50 marks] a. Make a version with for loop b. Make a version with while loop c. Make a version with do.. while loop...

  • Using assembly language in microwoft visual studio write the following code with procedure with c...

    using assembly language in microwoft visual studio write the following code with procedure with correct number of Fib numbers Your program should detect the largest Fib number that can be calculated. Besides storing the result in an array, print them on the screen.

  • Write a simple program in arm, assembly language , using only Registers, to test if 371...

    Write a simple program in arm, assembly language , using only Registers, to test if 371 is an Armstrong number. The program written should only have instruction set from the Cortex m0+. And then put a 1 in a register to show it It is, or 0 if it isn’t. The second program is about the Armstrong numbers. You assume it will be a 3-digit number which will be entered through the data area. You can use a register so...

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
ADVERTISEMENT