...
This presentation is the property of its rightful owner.
Sponsored Links
1 / 25

Κλήσεις συναρτήσεων και προγραμματισμός με μηχανές καταστάσεων PowerPoint PPT Presentation


  • 51 Views
  • Uploaded on
  • Presentation posted in: General

Κλήσεις συναρτήσεων και προγραμματισμός με μηχανές καταστάσεων. Functions , Subroutines and Interrupts. Όταν καλείται μια υπορουτίνα - συνάρτηση

Download Presentation

Κλήσεις συναρτήσεων και προγραμματισμός με μηχανές καταστάσεων

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


6166288


Functions subroutines and interrupts

Functions, Subroutines and Interrupts

  • -

  • (Scratch Registers) R12-R15 -.

  • R4-R11 (stack).


Functions subroutines and interrupts1

Functions, Subroutines and Interrupts


Functions subroutines and interrupts2

Functions, Subroutines and Interrupts

  • Listing 6.1: Subroutine from substk0.s43, which now saves and restores

  • R4 correctly.

  • ; Subroutine to give delay of R12 *0.1s

  • ; Parameter is passed in R12 and destroyed

  • ; R4 used for loop counter , stacked and restored

  • ;-----------------------------------------------------------------------

  • DelayTenths:

  • push.w R4 ; Stack R4: will be overwritten

  • jmp LoopTest ; Start with test in case R12 = 0

  • OuterLoop:

  • mov.w #DELAYLOOPS ,R4 ; Initialize loop counter

  • DelayLoop: ; [clock cycles in brackets]

  • dec.w R4 ; Decrement loop counter [1]

  • jnz DelayLoop ; Repeat loop if not zero [2]

  • dec.w R12 ; Decrement number of 0.1s delays

  • LoopTest:

  • cmp.w #0,R12 ; Finished number of 0.1s delays?

  • jnz OuterLoop ; No: go around delay loop again

  • pop.w R4 ; Yes: restore R4 before returning

  • ret ; Return to caller


Functions subroutines and interrupts3

Functions, Subroutines and Interrupts


6166288

-

  • ( )

  • RAM

  • (stack).


6166288

  • Listing 6.2: Subroutine from substk1.s43, whose delay loop uses two local

  • variables on the stack.

  • ; Subroutine to give delay of R12 *0.1s

  • ; Parameter is passed in R12 and destroyed

  • ; Space for two loop counters is created on stack , after which

  • ; 0(SP) is innermost (little) loop , 2(SP) is big loop counter

  • ;-----------------------------------------------------------------------

  • ; Iterations of delay loop for about 0.1s (6 cycles/iteration ):

  • BIGLOOPS EQU 130

  • LITTLELOOPS EQU 100

  • ;-----------------------------------------------------------------------

  • DelayTenths:

  • sub.w #4,SP ; Allocate 2 words (4 bytes) on stack

  • jmp LoopTest ; Start with test in case R12 = 0

  • OuterLoop:

  • mov.w #BIGLOOPS ,2(SP) ; Initialize big loop counter

  • BigLoop:

  • mov.w #LITTLELOOPS ,0(SP) ; Initialize little loop counter

  • LittleLoop: ; [clock cycles in brackets]

  • dec.w 0(SP) ; Decrement little loop counter [4]

  • jnz LittleLoop ; Repeat loop if not zero [2]

  • dec.w 2(SP) ; Decrement big loop counter [4]

  • jnz BigLoop ; Repeat loop if not zero [2]

  • dec.w R12 ; Decrement number of 0.1s delays

  • LoopTest:

  • cmp.w #0,R12 ; Finished number of 0.1s delays?

  • jnz OuterLoop ; No: go around delay loop again

  • add.w #4,SP ; Yes: finished , release space on stack

  • ret ; Return to caller


6166288

-


6166288

  • Listing 6.3: Subroutine and calling code from substk2.s43, where the stack is used

  • for passing the parameter and for local variables.

  • InfLoop: ; Loop forever

  • push.w #5 ; Push delay parameter on to stack

  • call #DelayTenths ; Call subroutine: don't forget the #!

  • incd.w SP ; Release space used for parameter

  • xor.b #LED1 ,& P2OUT ; Toggle LEDjmp InfLoop ; Back around infinite loop

  • ;-----------------------------------------------------------------------

  • ; Subroutine to give delay of n*0.1s

  • ; Parameter n is passed on stack

  • ; Space for two loop counters created on stack. After this:

  • ; 0(SP) is innermost (little) loop counter

  • ; 2( SP) is big loop counter

  • ; 4(SP) is return address

  • ; 6(SP) is parameter n passed on stack

  • ;-----------------------------------------------------------------------

  • ; Iterations of delay loop for about 0.1s (6 cycles/iteration ):

  • BIGLOOPS EQU 130

  • LITTLELOOPS EQU 100

  • ;-----------------------------------------------------------------------

  • DelayTenths:

  • sub.w #4,SP ; Allocate 2 words (4 bytes) on stack

  • jmp LoopTest ; Start with test in case R12 = 0

  • OuterLoop:

  • mov.w #BIGLOOPS ,2(SP) ; Initialize big loop counter

  • BigLoop:

  • mov.w #LITTLELOOPS ,0(SP) ; Initialize little loop counter

  • LittleLoop: ; [clock cycles in brackets]

  • dec.w 0(SP) ; Decrement little loop counter [4]

  • jnz LittleLoop ; Repeat loop if not zero [2]

  • dec.w 2(SP) ; Decrement big loop counter [4]

  • jnz BigLoop ; Repeat loop if not zero [4]

  • dec.w 6(SP) ; Decrement number of 0.1s delays

  • LoopTest:

  • cmp.w #0,6(SP) ; Finished number of 0.1s delays?

  • jnz OuterLoop ; No: go around delay loop again

  • add.w #4,SP ; Yes: finished , release space on stack

  • ret ; Return to caller


6166288

-


6166288

-


State machines uml

(State Machines) UML

  • (tasks), .

  • (State machines) .

  • There is a formal foundation for state machines, which is often based on the unified modeling language (UML)

  • More complicated systems may be designed using state charts, which are hierarchical extensions of state machines and share some ofthe properties of object-oriented languages.


6166288


6166288

Switch case and State diagram programming

for (j = 1; j < 12 ; j++)

{

// Build packet

txBuffer[0] = 17; // Pkt length (not inc. len byte)

txBuffer[1] = j; // Pkt address

for(i=0;i<16;i++) // Copy the string

txBuffer[2+i] = kTableStr[i];

switch (j)

{

case 1://unit 1

txBuffer[16] = '0'; // Table #, first digit

txBuffer[17] = '1';

break;

case 2://unit 2

txBuffer[16] = '0'; // Table #, first digit

txBuffer[17] = '2';

break;

case 3://unit 3

txBuffer[16] = '0'; // Table #, first digit

txBuffer[17] = '3';

break;

case 14://unit 14

txBuffer[16] = '0'; // Table #, first digit

txBuffer[17] = 'E';

break;

case 15://unit 15

txBuffer[16] = '0'; // Table #, first digit

txBuffer[17] = 'F';

break;

}

break switch

default case

T Switch case o int char !


6166288


6166288

Listing 8.18: Interrupt service routine for channel 0 of Timer_A from butstmc1.c.

The state machine lights the LED while the button is pressed

#pragma vector = TIMERA0_VECTOR

__interrupt void TA0_ISR (void) // Acknowledged automatically

{

static enum {

LedOff ,

LedOn

} LedState = LedOff; // State variable , initialized

Monitor = ON;

switch (LedState) {

case LedOff: // LED currently off

if (Button == ON) { // Button pressed?

LED = ON; // Yes: light LED

LedState = LedOn; // Change state

} else {

// No action needed

}

break;

case LedOn: // LED currently on

if (Button == OFF) { // Button released?

LED = OFF; // Yes: extinguish LED

LedState = LedOff; // Change state

}

break;

default: // Should never happen

LedState = LedOff; // Reset to initial state

break;

}

Monitor = OFF;

}


6166288


6166288

Chronos State diagram programming


6166288

Chronos State diagram programming

  • IAR visualSTATE6.3

  • Download: http://supp.iar.com/Download/SW/?item=VS-EVAL

  • Choronos example projects: http://www.iar.com/website1/1.0.1.0/1867/1/#chronosproject


Quantum leaps

Quantum Leaps

QP-nano is a generic, portable, ultra-lightweight,

event-driven infrastructure designed specifi-cally for low-end 8- and 16-bit MCUs, such as 8051, PICmicro, AVR, 68H(S)08, MSP430, M16C/R8C, Cypress PSoC. RTOS


6166288

www.quantum-leaps.com/downloads/


  • Login