logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

pic16f84 jak preprogramowac standardowe opuznienie na subroutine

tomqad 31 Paź 2016 00:20 1248 1
REKLAMA
  • #1 16029389
    tomqad
    Poziom 11  
    Posty: 22
    Ocena: 18
    oryginalny program wyglada tak taki dostałem od nauczyciela mam z nim zrobic

    Rewrite the delay section of the program as a subroutine with annotations. Also include a flowchart of the overall program and explain the advantage a subroutine might have over keeping the delay section within the main program.


    1. ; File CHASER.ASM
    2. ; Blinks LEDs on outputs (Port B) in a rotating pattern.
    3. ; Reverses direction if port A, Bit 0, is high.
    4. processor 16f84
    5. include <p16f84.inc>
    6. __config _RC_OSC & _WDT_OFF & _PWRTE_ON
    7. ; Give names to 2 memory locations (registers)
    8. J equ H’1F’ ; J = address hex 1F
    9. K equ H’1E’ ; K = address hex 1E
    10. ; Program
    11. org 0 ; start at address 0
    12. ; Set Port B to output and initialize it.
    13. movlw B’00000000’ ;
    14. tris PORTB ;
    15. movlw B’00000001’ ;
    16. movwf PORTB ;
    17. bcf STATUS,C ;
    18. ; Main loop. Check Port A, Bit 0, and rotate either left or right through the carry register.
    19. mloop:
    20. btfss PORTA,0 ;
    21. goto m1
    22. rlf PORTB,f ;
    23. goto m2
    24. m1:
    25. rrf PORTB,f ;
    26. m2:
    27. ; Add a delay
    28. movlw h’32’ ;
    29. movwf J ;
    30. jloop: movwf K ;
    31. kloop: decfsz K,f ;
    32. goto kloop
    33. decfsz J,f ;
    34. goto jloop
    35. movlw 02h ;
    36. ;Possibly change LED direction
    37. xorwf PORTA,0;
    38. goto mloop ;
    39. end ;



    tak to pozmieniałem czy jest ktos to wstanie posprawdzać




    File CHASER.ASM
    ; Blinks LEDs on outputs (Port B) in a rotating pattern.
    ; Reverses direction if port A, Bit 0, is high.
    processor 16f84
    include <p16f84.inc>
    __config _RC_OSC & _WDT_OFF & _PWRTE_ON
    ; Give names to 2 memory locations (registers)
    J equ H’1F’ ; J = address hex 1F
    K equ H’1E’ ; K = address hex 1E
    ; Program
    org 0 ; start at address 0
    ; Set Port B to output and initialize it.
    movlw B’00000000’ ; put binary ’00000000’ in the working register
    tris PORTB ; copy W to port B control register
    movlw B’00000001’ ; put binary ’00000001’ in the working register
    movwf PORTB ; copy the Wreg to PORTB
    bcf STATUS,C ; clear the carry bit
    ; Main loop. Check Port A, Bit 0, and rotate either left or right through the carry register.
    mloop:
    btfss PORTA,0 ; ; skip next instruction if bit=1
    goto m1
    rlf PORTB,f ; rotate port B bits to left
    goto m2
    m1:
    rrf PORTB,f ; rotate port B bits to right
    m2:
    ; add a Delay
    call Delay ; call subroutine to slow the LED
    movlw 02h; copy the 02h into working register
    ;Possibly change LED direction
    xorwf PORTA,0; Toggle the LED
    goto mloop ;
    ;Here is Subroutine
    Delay
    movlw h’32’ ; w := 32 hex
    movwf J ; J := w
    jloop: movwf K ; K := w
    kloop: decfsz K,f ; K := K-1, skip next if zero
    goto kloop ; repeat kloop if delay is not zero
    decfsz J,f ; J := J-1, decrement register skip next if zero
    goto jloop ; repeat jloop if delay is not zero
    Return ;When finished return to main, return from call, location of nex


    end ; program ends here
    A subroutine is a section of code, or program, than can be called as and when you need it. Subroutines are used if we are performing the same function more than once, for example creating a delay. The advantages of using a subroutine are that it will be easier to alter the value once inside a subroutine rather than, say, ten times throughout your program, and also it helps to reduce the amount of memory in our program occupies inside the PIC.

    The advantages of breaking a program into subroutines :
    • Decomposing a complex programming task into simpler steps: this is one of the two main tools of structured programming, along with data structures
    • Reducing duplicate code within a program
    • Enabling reuse of code across multiple programs
    • Dividing a large programming task among various programmers, or various stages of a project
    • Hiding implementation details from users of the subroutine

    Linkia


    Rewrite the delay section of the program again using a built-in Timer0 function with annotations. Also explain with aid of a diagram how the timer function counts the delay and the advantage a function might have over keeping the delay section in the main program



    ; File CHASER.ASM
    ; Blinks LEDs on outputs (Port B) in a rotating pattern.
    ; Reverses direction if port A, Bit 0, is high.
    Clock : XTAL 4 MHz
    processor 16f84
    include <p16f84.inc>
    __config _RC_OSC & _WDT_OFF & _PWRTE_ON

    ; Program
    org 0 ; start at address 0
    ; Set Port B to output and initialize it.
    Movlw ;configure Timer0 with
    movlw B’00000000’ ; put binary ’00000000’ in the working register
    tris PORTB ; copy W to port B control register
    movlw B’00000001’ ; put binary ’00000001’ in the working register
    movwf PORTB ; copy the Wreg to PORTB
    bcf STATUS,C ; clear the carry bit

    ; Main loop. Check Port A, Bit 0, and rotate either left or right through the carry register.
    mloop:
    btfss PORTA,0 ; ; skip next instruction if bit=1
    goto m1
    rlf PORTB,f ; rotate port B bits to left
    goto m2
    m1:
    rrf PORTB,f ; rotate port B bits to right
    m2:
    BTFSS INTCOM ,T0IF ; wait here until Timer0 count rolls over
    GOTO MainLoop ; loop for ??????
    BCF INTCON, T0IF ; bit (flag)must be cleared in software
    movlw 02h; copy the02h into working register
    ;Possibly change LED direction
    xorwf PORTA,0; Toggle the LED
    goto mloop ;
    end ; program ends here
    prosze o pomoc

    Moderowany przez ANUBIS:

    Zakres wiedzy podlegający ocenie, więc musi to być praca samodzielna. Chcąc pomocy od innych, pokaż wkład swojej pracy. Forum nie zastępuje zajęć/wykładów, podręcznika lub innej, podobnej tematycznie literatury. Rozwiązywanie zadań akademicko-szkolnychAby zobaczyć materiał na tym forum musisz być zalogowany 3.1.17.Nie wysyłaj pytań bardzo podstawowych, na które odpowiedzi można znaleźć w instrukcji obsługi lub ogólnie dostępnych źródłach. Nie prezentuj postawy, że mi się należy. Dbaj o poziom pytań i dyskusji. Dziękujemy.

  • REKLAMA
  • #2 16029467
    Aszk
    Poziom 12  
    Posty: 5
    Ocena: 6
    Piszemy opóźnienie.
REKLAMA