Question

Can anyone explain this code? I get the gist of it, but having someone explain this...

Can anyone explain this code? I get the gist of it, but having someone explain this code would be helpful

;*****************************************************************
;   Data section   
;*****************************************************************
   ORG DATA  

;*****************************************************************
;    Main program section   
;*****************************************************************
   ORG CODE  
Main:
LDS #STACK
LDAA #%00000100
STAA DDRT
  
LDAA #$80
STAA TSCR1
LDAA #$07
STAA TSCR2
BSET TIOS, %00000100
LDAA #$10
STAA TCTL2
CLI
LDAA #$04
STAA TIE
  
  
Here
NOP
BRA Here

;*****************************************************************
;    Subroutine section
;*****************************************************************
;*****************************************************************
;    Interrupt ISR
;*****************************************************************

TC2_ISR

LDD TCNT
ADDD #30000
STD TC2
BSET TFLG1,%0000100
RTI
  

;*****************************************************************
;    Interrupt Vectors
;*****************************************************************
ORG $FFDE
DC.W TC2_ISR
  
   ORG $FFFE
   DC.W Main   ;Reset Vector

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • PT2 used as a output.
  • Timer channel 2 is used to generate ISR

;*****************************************************************
; Data section   
;*****************************************************************
ORG DATA

;*****************************************************************
; Main program section   
;*****************************************************************
ORG CODE
Main:
LDS #STACK   //initialize stack pointer
LDAA #%00000100 //put 00000100 into A
STAA DDRT //to make PT2 as output and other pin as input
  
LDAA #$80 //put $80 into A,if you use $90, then NO need for "BSET   TFLG1, %00000100" in ISR Routine
STAA TSCR1 //enable timer
LDAA #$07 //put $07 into A
STAA TSCR2 //set Prescaler=128
BSET TIOS, %00000100 //set Channel 2 as output channel,toggle PT2 Pin
LDAA #$10 //put %00010000 into A
STAA TCTL2 //store %00010000 to TCTL2 so that OM2=0,and OL2=1,make PT2 pin toggle everytime when there is a match between TC2 and TCNT
CLI //Enable IRQ
LDAA #$04 //put $04 into A
STAA TIE //CH2 interrupt Enable
  
  
Here
NOP
BRA Here //Keeps looping to "Here" Forever

;*****************************************************************
; Subroutine section
;*****************************************************************
;*****************************************************************
; Interrupt ISR
;*****************************************************************

TC2_ISR //Timer Channel 2 (TC2) interrupt vector

LDD TCNT //Load D with TCNT(load current timer count to D)
ADDD #30000 //stores to TCTL3 (Toggle D once every 30000 timer pulses)
STD TC2 //Store D to TC2
BSET TFLG1,%0000100 //Clear the Channel 2 Timer flag for next round (writing HIGH will clear it)
RTI //return from interrupt
  

;*****************************************************************
; Interrupt Vectors
;*****************************************************************
ORG $FFDE
DC.W TC2_ISR
  
ORG $FFFE
DC.W Main //Reset Vector.CPU wakes here and it is sent to start of the code at stack Pointer which is initialize in main

Add a comment
Know the answer?
Add Answer to:
Can anyone explain this code? I get the gist of it, but having someone explain this...
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
  • b. The program code below involves IO. The first line of an interrupt (IRQ) service routine is also shown. Describe...

    b. The program code below involves IO. The first line of an interrupt (IRQ) service routine is also shown. Describe the purpose of each line of code and insert suitable comments EQU $1003 EQU $1007 EQU $4FFF IRQVECT EQU SFFF2 PORTC DDRC STACK ORG $1000 START SEI #STACK LDS LDD #INTSERV STD IRQVECT #S0F LDAA STAA DDRC PORTC STAA CLI More code ORG $2000 INTSERV LDAB PORTC [8 marks b. The program code below involves IO. The first line of...

  • I am having an issue with this practice problem. I understand the concept of given step,...

    I am having an issue with this practice problem. I understand the concept of given step, but I am lost to figure out how to setup in the main program in CodeWarrior software. Using the HCS12 Microcontrollers and Embedded Systems, 1st Edition, I was able to understand the instruction appendix, but I was not able to construct it in the main program. I need help to solve these steps and it is due today. Modify the Main program section of...

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