• AVR Freaks

Hot!Ask for Some Help regarding PIC16 series

Author
Tom35
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2020/07/25 15:53:45
  • Location: 0
  • Status: offline
2020/07/27 16:21:26 (permalink)
0

Ask for Some Help regarding PIC16 series

Hi there,
I am new to the forum. I am currently doing an electrical engineering course which has some electronic parts. One part is about explaining the test result of a program. I find this quite difficult as I have never done this before and I am never going to use it in my job so I would just need help understand the changes happen in the program if the delay loop is changed from 0X32 to 0X02 in order to speed up the process. How the values stored in SFR and variable registers after the change can be explained?
This is the program:
 
; blinks LEDs on outputs in a rotating pattern, with input option to reverse direction
;Set microprocessor as 16F84
INCLUDE <P16F84.INC>
; Setup processor configuration
__config _RC_OSC & _WDT_OFF & _PWRTE_ON
; label 2 symbols as memory addresses for counting loops
J equ 1F
K equ 1E
 
SETUP:
org 0 ;
BANKSEL TRISB;
clrf TRISB;
bcf STATUS , RP0 ;
bcf STATUS , RP1 ;
movlw 0x01 ;
movwf PORTB ;
bcf STATUS,C ;
 
ROTATE:
btfss PORTA,0 ;
goto RR
rlf PORTB,f ;
goto DELAY
RR: rrf PORTB,f ;
 
DeLAY:
movlw 0x32 ;
movwf J ;
jloop: movwf K ;
kloop: decfsz K,f ;
goto kloop
decfsz J,f ;
goto jloop
 
DIRECTION:
movlw 0x02 ;
xorwf PORTA,0;
goto ROTATE ;
end ;
 
Thanks for your help.

#1

8 Replies Related Threads

    MrAureliusR
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2014/06/25 19:55:32
    • Location: Toronto, Ontario, Canada
    • Status: offline
    Re: Ask for Some Help regarding PIC16 series 2020/08/03 07:52:34 (permalink)
    0
    This is in the wrong forum -- this is the forum for the 32-bit devices. PIC16 devices are 8-bit microcontrollers.

    I <3 PIC32MX
    #2
    dan1138
    Super Member
    • Total Posts : 4168
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Ask for Some Help regarding PIC16 series 2020/08/03 08:47:34 (permalink)
    0
    DeLAY:
            movlw   0x4             ; Total loops for K > 1 & J > 1: (K-1)+(J-1)*(K)
            movwf   J               ; Total loops for K = 1 & J > 1: ( 0 )+(J-1)*(1)
    jloop:  movwf   K               ; Total loops for K = 0 & J > 1: (255)+(J-1)*(256)
    kloop:  decfsz  K,f             ; Total loops for K > 1 & J = 1: (K-1)+(   0   )
            goto    kloop           ; Total loops for K = 1 & J = 1: ( 0 )+(   0   )
            decfsz  J,f             ; Total loops for K = 0 & J = 1: (255)+(   0   )
            goto    jloop           ; Total loops for K > 1 & J = 0: (K-1)+(255*K)
                                    ; Total loops for K = 1 & J = 0: ( 0 )+(256)-1
                                    ; Total loops for K = 0 & J = 0: (256)*(256)-1

    <EDIT>
    Verified in simulation.
    post edited by dan1138 - 2020/08/04 10:40:15
    #3
    1and0
    Access is Denied
    • Total Posts : 11770
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Ask for Some Help regarding PIC16 series 2020/08/03 10:23:10 (permalink)
    5 (1)
    Tom35
    DeLAY:
            movlw   0x32
           movwf   J
    jloop:  movwf   K
    kloop:  decfsz  K,f
            goto    kloop
            decfsz  J,f
            goto    jloop




    That delay takes
     
    Instruction Cycles = 2 + {[1 + (3 * WREG - 1) + 3] * WREG - 1}
     
    #4
    dan1138
    Super Member
    • Total Posts : 4168
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Ask for Some Help regarding PIC16 series 2020/08/03 10:27:42 (permalink)
    0
    1and0
    That delay takes
     
    Instruction Cycles = 2 + {[1 + (3 * WREG - 1) + 3] * WREG - 1}

    Oh! Just go and give him the correct answer while the old guy struggles for an hour. :)
    #5
    1and0
    Access is Denied
    • Total Posts : 11770
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Ask for Some Help regarding PIC16 series 2020/08/03 10:36:07 (permalink)
    4 (1)
    dan1138
     
    Oh! Just go and give him the correct answer while the old guy struggles for an hour. :)

    I haven't derived such calculations in years -- need to make sure my gray matter still working. ;)  Normally I'd just use the Simulator Stopwatch.
     
    #6
    dan1138
    Super Member
    • Total Posts : 4168
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Ask for Some Help regarding PIC16 series 2020/08/03 10:54:10 (permalink)
    0
    1and0
    dan1138
    Oh! Just go and give him the correct answer while the old guy struggles for an hour. :)

    I haven't derived such calculations in years -- need to make sure my gray matter still working. ;)  Normally I'd just use the Simulator Stopwatch.

    May have an issue if WREG is ever zero.
    #7
    1and0
    Access is Denied
    • Total Posts : 11770
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Ask for Some Help regarding PIC16 series 2020/08/03 11:01:54 (permalink)
    0
    dan1138
     
    May have an issue if WREG is ever zero.

    For zero, use WREG = 256. ;)
     
    #8
    1and0
    Access is Denied
    • Total Posts : 11770
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Ask for Some Help regarding PIC16 series 2020/08/04 06:44:43 (permalink)
    0
    For completeness ;)
    DeLAY:
            movlw   K

     
    N = K & 0xFF;
    if (N == 0) N = 256;
    Tcy = 3*N*N + 3*N + 1;
     
    post edited by 1and0 - 2020/08/04 06:48:52
    #9
    Jump to:
    © 2021 APG vNext Commercial Version 4.5