Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

home / homework help / questions and answers / engineering / electrical engineer

ID: 2990857 • Letter: H

Question

home / homework help / questions and answers / engineering / electrical engineering / using code warrior-hcs12g- mc9s12g128-open-source ...

Question

Report abuse  

USING CODE WARRIOR-HCS12G- MC9S12G128-OPEN-SOURCE BDM

Write a program to continuously turn all four green LEDs ON and OFF (toggle). There should be a one-second delay between each toggle.

Cut and paste the source code.

Show the delay calculation.

Run the program on the board by pressing the Reset button on the Tower. Describe the values of LEDs.

Write a program that displays values from 0 to 15 sequentially, with a 0.75-second delay in between each display. After the count value reaches 15 (i.e. all LEDs are ON), the program should stop.

Cut and paste the code.

Show the delay calculation.

Run the program on the board by pressing the Reset button on the Tower. Describe the values of LEDs.

Use BSET and BCLR instructions to Turn LED2 ON and OFF continuously with a 0.5-second delay between each change.

PLEASE MAKE SURE IT COMPILES. NO LINKS!

YOU CAN USE THE SAME SKELETON CODE FOR ALL THREE SECTIONS

THANKS

Cut and paste the source code.

Show the delay calculation.

Run the program on the board by pressing the Reset button on the Tower. Describe the values of LEDs.

Change the delay to 1ms and run the program

Explanation / Answer

;program that displays values from 0 to 15 sequentially

; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point

; Include derivative-specific definitions
       INCLUDE 'derivative.inc'

ROMStart EQU $4000 ; absolute address to place my code/constant data

; variable/data section

ORG RAMStart
; Insert here your data definition.
Cnt rmb 1
Cnt1 DC.B 16
Cnt2 rmb 1
Dummy rmb 1
DelayCnt1 DC.B 4
DelayCnt2 DC.B 250
DelayCnt3 DC.B 250
; code section
ORG ROMStart


Entry:
_Startup:
MOVB #16,Cnt1
ASR $20
MOVB #0,Cnt2
LDAA #$FF
   STAA DDRT ; Define Port T as an output
Loop2
   LDAA Cnt2
   ROLA
   ROLA
   ROLA
   ROLA
   ANDA #$F0
   STAA PTT ; Turns all LEDs ON
   INC Cnt2
  
MOVB #3, DelayCnt1
delayloop2
   MOVB #250, DelayCnt2
delayloop1
   MOVB #250,DelayCnt3
delayloop
   INC Dummy ;4
   DEC Dummy ;4
   INC Dummy ;4
   DEC Dummy ;4
   NOP ;1
   NOP ;1
   DEC DelayCnt3 ;4
   BNE delayloop ;3 total of 25 per loop
DEC DelayCnt2
BNE delayloop1
DEC DelayCnt1
BNE delayloop2
;total delay = 25*250*250*3 approx = 0.75s
  
   DEC Cnt1
   BNE Loop2
  
LDAA Cnt2
ROLA
   ROLA
   ROLA
   ROLA
   ANDA #$F0
   STAA PTT ; Turns all LEDs ON
Back BRA Back ; End of main
RTS ; result in D

;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector


;Turn all LED on and off

; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point

; Include derivative-specific definitions
       INCLUDE 'derivative.inc'

ROMStart EQU $4000 ; absolute address to place my code/constant data

; variable/data section

ORG RAMStart
; Insert here your data definition.
Cnt rmb 1
Dummy rmb 1
DelayCnt1 DC.B 4
DelayCnt2 DC.B 250
DelayCnt3 DC.B 250
; code section
ORG ROMStart


Entry:
_Startup:
LDAA #$FF
   STAA DDRT ; Define Port T as an output
Loop2
   LDAA #$F0
   STAA PTT ; Turns all LEDs ON

   MOVB #4, DelayCnt1
delayloop2
   MOVB #250, DelayCnt2
delayloop1
   MOVB #250,DelayCnt3
delayloop
   INC Dummy ;4
   DEC Dummy ;4
   INC Dummy ;4
   DEC Dummy ;4
   NOP ;1
   NOP ;1
   DEC DelayCnt3 ;4
   BNE delayloop ;3 total of 25 per loop
DEC DelayCnt2
BNE delayloop1
DEC DelayCnt1
BNE delayloop2
;total delay = 25*250*250*4 approx = 1s
  

   LDAA #$00
   STAA PTT ; Turns al LEDs OFF

   MOVB #4, DelayCnt1
delayloop21
   MOVB #250, DelayCnt2
delayloop11
   MOVB #250,DelayCnt3
delayloop01
   INC Dummy ;4
   DEC Dummy ;4
   INC Dummy ;4
   DEC Dummy ;4
   NOP ;1
   NOP ;1
   DEC DelayCnt3 ;4
   BNE delayloop01 ;3 total of 25 per loop
DEC DelayCnt2
BNE delayloop11
DEC DelayCnt1
BNE delayloop21
;total delay = 25*250*250*4 approx = 1s
   BRA Loop2

Back BRA Back ; End of main
RTS ; result in D

;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector


;Turn all LED2 on and off

; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point

; Include derivative-specific definitions
       INCLUDE 'derivative.inc'

ROMStart EQU $4000 ; absolute address to place my code/constant data

; variable/data section

ORG RAMStart
; Insert here your data definition.
Cnt rmb 1
Dummy rmb 1
DelayCnt1 DC.B 2
DelayCnt2 DC.B 250
DelayCnt3 DC.B 250
; code section
ORG ROMStart


Entry:
_Startup:
LDAA #$FF
   STAA DDRT ; Define Port T as an output
Loop2
  
   BCLR PTT,32 ;LED2 On
   MOVB #2, DelayCnt1
delayloop2
   MOVB #250, DelayCnt2
delayloop1
   MOVB #250,DelayCnt3
delayloop
   INC Dummy ;4
   DEC Dummy ;4
   INC Dummy ;4
   DEC Dummy ;4
   NOP ;1
   NOP ;1
   DEC DelayCnt3 ;4
   BNE delayloop ;3 total of 25 per loop
DEC DelayCnt2
BNE delayloop1
DEC DelayCnt1
BNE delayloop2
;total delay = 25*250*250*4 approx = 1s
  

bset PTT,32 ;LED2 off

   MOVB #2, DelayCnt1
delayloop21
   MOVB #250, DelayCnt2
delayloop11
   MOVB #250,DelayCnt3
delayloop01
   INC Dummy ;4
   DEC Dummy ;4
   INC Dummy ;4
   DEC Dummy ;4
   NOP ;1
   NOP ;1
   DEC DelayCnt3 ;4
   BNE delayloop01 ;3 total of 25 per loop
DEC DelayCnt2
BNE delayloop11
DEC DelayCnt1
BNE delayloop21
;total delay = 25*250*250*4 approx = 1s
   BRA Loop2

Back BRA Back ; End of main
RTS ; result in D

;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector