Help with assembly to C problem

Discussion in 'Programmer's Corner' started by Hest, Nov 7, 2012.

  1. Hest

    Thread Starter New Member

    Nov 7, 2012
    2
    0
    Hello

    I'm working with microprocessors and using hi-tech C for my programs.

    I have an assembly program that I would like to re-make into C. The assembly code is for a PIC12f629 for modelcars with lights and blinking LED's.
    I could just use it as it is, but I'd like to learn more my self and make some changes to it.

    Because the code is too large, I have put it here instead http://dl.dropbox.com/u/3995146/einsatz.txt

    Here is a little code snip that explains my question.

    In the code he has got this
    Code ( (Unknown Language)):
    1.  
    2. R_CNT_F1    equ  30h          ; Counter for FLASH1
    3. R_FLAG_F1   equ  31h          ; FLAGS for FLASH1
    4.  
    Code ( (Unknown Language)):
    1.  
    2. T_FLASH1    equ d'245' ; (1..255) duration of long off-time for FLASH1
    3. T_BREAK1    equ d'45'   ; (1..255) duration of short off-time for FLASH1
    4.  
    Code ( (Unknown Language)):
    1.  
    2. movlw T_FLASH1      ; Time between 2 Flashes (long time)
    3. btfss R_FLAG_F1,0    ; if short off-Time needed (Strobo double-flash)
    4. movlw T_BREAK1      ; Time between 2 Flashes (short time)
    5. subwf R_CNT_F1,W  ; if R_CNT_F1 < T_FLASHx / T_BREAKx
    6. btfss STATUS,C       ; .. then
    7. return                    ; return
    8.  
    I can understand the most of the assembly code, but I can't figure out where this program is getting it's timing from and where those 245 and 45 comes in. I know what they mean, but not what counts it.

    I have been trying to figure out exactly how the program counts the time/ticks and decides what pin to turn on or off and when it resets and starts over. It's not timer0 because thats too fast and I don't think it's timer1 either as it's used for PWM and I can't see any other counters.

    I hope someone can guide me in the right direction so I can find out what is going on and maybe explain to me what exactly happends in the code.
     
  2. xainnasir

    New Member

    Nov 8, 2012
    26
    2
    245 and 45 are actually the input values u r giving to ur variables .... in c define some variable and then assign them any value which is in ur case 245 and 45
     
  3. Hest

    Thread Starter New Member

    Nov 7, 2012
    2
    0
    I figured that out. What I'm looking for is what he uses to count to those numbers, thats whats bugging me. I'm not sure it's timer0, because that would be way to fast and I can't figure out what else is counting.
     
  4. stahta01

    Member

    Jun 9, 2011
    133
    21
    From this code

    Code ( (Unknown Language)):
    1.  
    2. ; ***** create 2ms slot *****
    3.  loop_0 ;        
    4.  movlw b'00010100'              ; check mode ;        
    5.  movwf R_MODE  
    6.  #ifndef test        
    7.  movf TMR1H,F          
    8.  btfsc STATUS,Z                 ; if TMR1H <> ZERO          
    9.  goto loop        
    10.  clrf TMR1H                     ; .. then reset to ZERO        
    11. ; *** every 2 ms ***
    12.  #endif
    13.  
    I would timer 1 is being used; not as an interrupt,
    but, as a counter that is reset in software.

    Tim S.
     
    Last edited: Nov 20, 2012
Loading...