Yesterday 21:12
Forum: Proton Plus Compiler v3
Starter: Dave-S
Views: 0
Replies: 3
Yesterday 14:49
Forum: The Lounge
Starter: See_Mos
Views: 0
Replies: 6
Yesterday 13:24
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 28
+ Reply to Thread
Results 1 to 10 of 10

Thread: Assembler to Proton91 days old

  1. #1
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    260
    Thumbs Up
    Received: 8
    Given: 1
    Total Downloaded
    3.76 GB

    0 Not allowed!

    Default Assembler to Proton

    Hello everybody,
    How can I translate from Assembler into Proton?

    --------------------------------------------------------------------------
    iserv btfsc flags,0 ;1st capture flag set?
    goto cap2 ;yes, goto 2nd capture
    bsf flags,0 ;no, set 1st capture flag
    bcf pir1,2 ;clear ccp1 interrupt flag,
    ; enable second interrupt
    bcf ccp1con,0 ;second capture on falling edge
    movf ccpr1h,w ;get 1st capture high
    movwf one_hi ;store
    movf ccpr1l,w ;get 1st capture low
    movwf one_lo ;store
    retfie
    cap2 bsf status,rp0 ;bank 1
    bcf pie1,2 ;disable ccp1 interrupts
    bcf status,rp0 ;bank 0
    comf one_hi,f ;complement 1st capture high
    comf one_lo,f ;complement 1st capture low
    movf ccpr1h,w ;get 2nd capture high
    movwf msb2 ;store
    movf ccpr1l,w ;get 2nd capture low
    movwf lsb2 ;store
    dblplus movf one_lo,w ;fetch complement of 1st low
    addwf lsb2,f ;add low bytes, result in lsb2
    btfsc status,c ;carry set?
    incf msb2,f ;yes, add 1 to msb result
    movf one_hi,w ;fetch complement of 1st high
    addwf msb2,f ;add high bytes, result in msb2
    bsf flags,1 ;set "done" flag
    retfie
    -----------------------------------------------------------------------
    I have two retfie
    Thank you in advance ,
    Teo
    Last edited by teo; 20th August 2018 at 22:04.

  2. #2
    Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    379
    Thumbs Up
    Received: 68
    Given: 0
    Total Downloaded
    141.92 MB

    0 Not allowed!

    Default Re: Assembler to Proton

    I think that looks something like this...
    Code:
    Dim cap1 As Word
    Dim cap2 As Word
    Dim flags As Byte
    
    iserv:
    If flags.0 = 0 Then     ' 1st capture flag set?
        flags.0 = 1         ' no, set 1st capture flag
        PIR1.2 = 0          ' clear CCP1 interrupt flag, enable 2nd interrupt
        CCP1CON.0 = 0       ' second capture on falling edge
        cap1.Byte1 = CCPR1H
        cap1.Byte0 = CCPR1L
        Retfie
    EndIf
    
    capture2:
    PIE1.2 = 0			' disable CCP1 interrupts
    cap2.Byte1 = CCPR1H		' get 2nd capture high
    cap2.Byte0 = CCPR1L		' get 2nd capture lo
    
    ' subtract first capture from second and put result into cap2
    dblplus:
    cap2 = cap2 - cap1
    flags.1 = 1			' set 'done' flag
    Retfie

  3. #3
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    260
    Thumbs Up
    Received: 8
    Given: 1
    Total Downloaded
    3.76 GB

    0 Not allowed!

    Default Re: Assembler to Proton

    Hello,
    Thanks for the reply.
    The problem is I have two "retfies" and I do not know how to do this in Proton.
    So I think it's not good:
    Context Save
    ...........
    ...........
    Context Restore
    Context Save
    ...........
    ...........
    Context Restore
    Teo

  4. #4
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,556
    Thumbs Up
    Received: 61
    Given: 89
    Total Downloaded
    895.24 MB

    0 Not allowed!

    Default Re: Assembler to Proton

    You can use it just the same as tumbleweed posted. The first refie is in a conditional test block

    If you want to use Context save/restore then modify the code

    But Context save is not needed for this code as it uses no special working regs


    iserv:
    Context save
    If flags.0 = 0 Then ' 1st capture flag set?
    flags.0 = 1 ' no, set 1st capture flag
    PIR1.2 = 0 ' clear CCP1 interrupt flag, enable 2nd interrupt
    CCP1CON.0 = 0 ' second capture on falling edge
    cap1.Byte1 = CCPR1H
    cap1.Byte0 = CCPR1L
    goto InterruptExit
    EndIf


    capture2:
    PIE1.2 = 0 ' disable CCP1 interrupts
    cap2.Byte1 = CCPR1H ' get 2nd capture high
    cap2.Byte0 = CCPR1L ' get 2nd capture lo


    ' subtract first capture from second and put result into cap2
    dblplus:
    cap2 = cap2 - cap1
    flags.1 = 1 ' set 'done' flag
    InterruptExit:
    Context Restore
    Tim

  5. #5
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    260
    Thumbs Up
    Received: 8
    Given: 1
    Total Downloaded
    3.76 GB

    0 Not allowed!

    Default Re: Assembler to Proton

    Hi Tim,
    Thanks a lot for the answer.
    Teo

  6. #6
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    260
    Thumbs Up
    Received: 8
    Given: 1
    Total Downloaded
    3.76 GB

    0 Not allowed!

    Default Re: Assembler to Proton

    Hi Tim,Can you look a little over the program and translate my first part?
    Thousands of thanks,
    Teo


    ;=======PDCCP.ASM================================= ====
    list p=16f870
    __config h'3f71'
    radix hex
    ;------------------------------------------------------------
    ;timer 1 and ccp1 module - period measurement demo
    ; timer 1 free running
    ; capture at start and end of period pulse
    ;------------------------------------------------------------
    ; cpu equates (memory map)
    status equ 0x03
    porta equ 0x05
    portb equ 0x06
    portc equ 0x07
    intcon equ 0x0b
    pir1 equ 0x0c
    tmr1l equ 0x0e
    tmr1h equ 0x0f
    t1con equ 0x10
    ccpr1l equ 0x15
    ccpr1h equ 0x16
    ccp1con equ 0x17
    trisa equ 0x85
    trisb equ 0x86
    trisc equ 0x87
    pie1 equ 0x8c
    adcon1 equ 0x9f
    one_hi equ 0x20
    one_lo equ 0x21
    lsb2 equ 0x22
    msb2 equ 0x23
    flags equ 0x24 ;1st capture flag bit 0
    ; done flag bit 1
    ;------------------------------------------------------------
    ; bit equates
    c equ 0
    z equ 2
    rp0 equ 5
    ccp1 equ 2 ;ccp1 bit 2, port C
    ;------------------------------------------------------------
    org 0x000
    goto start ;skip over location pointed to by
    ; interrupt vector
    org 0x004
    goto iserv
    ;
    start bsf status,rp0 ;switch to bank 1
    movlw b'00000000' ;port B outputs
    movwf trisb
    movlw b'00000110' ;turn off A/D, port A
    movwf adcon1
    movlw b'00011111' ;port A inputs
    movwf trisa
    bsf trisc,ccp1 ;ccp1 pin input
    bcf status,rp0 ;switch back to bank 0
    movlw b'00000000' ;port B lines low
    movwf portb
    bcf intcon,7 ;disable global interrupts
    bcf intcon,6 ;disable peripheral interrupts
    bsf status,rp0 ;bank 1
    bcf pie1,0 ;disable timer 1 interrupts
    bcf pie1,2 ;disable ccp1 interrupts
    bcf status,rp0 ;bank 0
    bcf pir1,2 ;clear ccp1 interrupt flag
    clrf ccp1con ;ccp1 module off
    movlw b'00000000' ;tmr1 prescaler and tmr1 setup,
    movwf t1con ; tmr1 off
    clrf tmr1h ;clear timer 1 high
    clrf tmr1l ;clear timer 1 low
    bsf t1con,0 ;timer 1 on, free running
    movlw b'00000101' ;capture on rising edge, ccp1
    movwf ccp1con ; module on
    clrf flags ;clear 1st capture and done flags
    bsf intcon,7 ;enable global interrupts
    bsf intcon,6 ;enable peripheral interrupts
    bsf status,rp0 ;bank 1
    bsf pie1,2 ;enable ccp1 interrupts
    bcf status,rp0 ;bank 0
    ready btfss porta,0 ;ready?
    goto ready
    done btfss flags,1 ;done?
    goto done
    movf msb2,w ;get period high
    movwf portb ;display via port B LEDs
    disp_lo btfss porta,2 ;watch display low byte switch
    goto disp_lo
    movf lsb2,w ;get period low
    movwf portb ;display via port B LEDs
    circle goto circle ;done
    ;------------------------------------------------------------
    iserv btfsc flags,0 ;1st capture flag set?
    goto cap2 ;yes, goto 2nd capture
    bsf flags,0 ;no, set 1st capture flag
    bcf pir1,2 ;clear ccp1 interrupt flag,
    ; enable second interrupt
    bcf ccp1con,0 ;second capture on falling edge
    movf ccpr1h,w ;get 1st capture high
    movwf one_hi ;store
    movf ccpr1l,w ;get 1st capture low
    movwf one_lo ;store
    retfie
    cap2 bsf status,rp0 ;bank 1
    bcf pie1,2 ;disable ccp1 interrupts
    bcf status,rp0 ;bank 0
    comf one_hi,f ;complement 1st capture high
    comf one_lo,f ;complement 1st capture low
    movf ccpr1h,w ;get 2nd capture high
    movwf msb2 ;store
    movf ccpr1l,w ;get 2nd capture low
    movwf lsb2 ;store
    dblplus movf one_lo,w ;fetch complement of 1st low
    addwf lsb2,f ;add low bytes, result in lsb2
    btfsc status,c ;carry set?
    incf msb2,f ;yes, add 1 to msb result
    movf one_hi,w ;fetch complement of 1st high
    addwf msb2,f ;add high bytes, result in msb2
    bsf flags,1 ;set "done" flag
    retfie
    ;------------------------------------------------------------
    end
    ;------------------------------------------------------------
    ;at device programming time, select:
    ; memory unprotected
    ; watchdog timer disabled (default is enabled)
    ; standard crystal XT (using 4 MHz osc for test)
    ; power-up timer on
    ; brown-out reset enabled
    ; lvp disabled
    ; debug mode disabled
    ;================================================= ===========

  7. #7
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,833
    Thumbs Up
    Received: 161
    Given: 158
    Total Downloaded
    3.22 GB

    0 Not allowed!

    Default Re: Assembler to Proton

    What is this code for? perhaps it has high and low priority interupts?
    George

  8. #8
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    260
    Thumbs Up
    Received: 8
    Given: 1
    Total Downloaded
    3.76 GB

    0 Not allowed!

    Default Re: Assembler to Proton

    Hi George,
    The program determines the period of a rectangular signal applied to PORTC.2 (CCP1) using captured method.
    Thank you in advance,
    Teo

  9. #9
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,546
    Thumbs Up
    Received: 107
    Given: 29
    Total Downloaded
    2.69 GB

    0 Not allowed!

    Default Re: Assembler to Proton

    Hi Teo,
    You're re-inventing the wheel. My post in this thread does all that.
    http://www.protonbasic.co.uk/showthr...679#post513679
    Post 7 has the program. It is the Microchip paper converted to Proton.
    Cheers
    John

  10. #10
    Member teo's Avatar
    Join Date
    Sep 2010
    Posts
    260
    Thumbs Up
    Received: 8
    Given: 1
    Total Downloaded
    3.76 GB

    0 Not allowed!

    Default Re: Assembler to Proton

    Thank you very much,
    Teo

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Using Microchip assembler program in Proton
    By John Lawton in forum The Lounge
    Replies: 3
    Last Post: 19th January 2017, 20:00
  2. Assembler Macros
    By johngb in forum Proton 24
    Replies: 0
    Last Post: 22nd January 2015, 20:01
  3. Assembler
    By nullsoft in forum The Lounge
    Replies: 21
    Last Post: 11th February 2010, 10:02
  4. Need a little help in assembler, please...
    By pdgnr in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 1st June 2006, 08:42
  5. Help in assembler
    By pdgnr in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 28th March 2006, 10:02

Members who have read this thread : 45

Actions :  (Set Date)

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts