Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Math help?

Status
Not open for further replies.

Mike - K8LH

Well-Known Member
Hi guys,

Am I doing this simple two step 16 bit math operation correctly? I'll simulate it as soon as I wake up...

Code:
;
;  CCP1CONbits.CCP1M0 = 0;
;  CCPR1L += (20000-Pulse)%256;
;  CCPR1H += (20000-Pulse)/256;
;
;  pulse is lo so setup CCP1 to go hi on pulse "off-time" match
;
Pulse_Lo
        bcf     CCP1CON,CCP1M0  ; setup CCP1 to go hi next int    |B0
        movf    PulseLo,W       ; W = Pulse%256                   |B0
        sublw   low  d'20000'   ; W = 20000%256 - Pulse%256       |B0
        skpc                    ; borrow? no, skip, else          |B0
        decf    CCPR1H,f        ; borrow from CCPR1H              |B0
        addwf   CCPR1L,f        ; CCPR1L += (20000-Pulse)%256     |B0
        skpnc                   ; carry? no, skip, else           |B0
        incf    CCPR1H,f        ; carry into CCPR1H               |B0
        movf    PulseHi,W       ; W = Pulse/256                   |B0
        sublw   high d'20000'   ; W = 20000/256 - Pulse/256       |B0
        addwf   CCPR1H,f        ; CCPR1H += (20000-Pulse)/256     |B0
;
 
Also should have mentioned that if you've got an easier and/or better way to do it (fewer instructions, more intuitive, etc.), please pass it along. I suck at math (grin).
 
Nigel Goodwin said:
Personally I tend to disapprove of using those macros, it only confuses beginners.
You're certainly entitled to your opinion but I believe promoting the use of meaningless _config lines in example "tutorial" programs and providing example keypad code that could short PIC output pins when more than one key is pressed, all for the sake of not confusing beginners, is not cool.

The Skip Carry (skpc) and Skip No Carry (skpnc) pseudo instructions are much more intuitive than the equivalent btfss STATUS,C and btfsc STATUS,C instructions, respectively. And the 12/14 bit "branch" pseudo instructions bz, bnz, bc, bnc, etc., are real instructions on the 16 bit core devices.
 
Last edited:
blueroomelectronics said:
I think the pseudo instructions make the core more readable.

That's because you come from the Parallax assembler :D which was basically a collection of such macros.

Although I would agree that they do make it more readable.
 
I wonder if it doesn't make sense to denote macros in the name- like "skpc_m" -to make the code clearer?
 
Actually they're part of MPASM. They are what they are. You don't need to define them; just use them.

I've attached the Firefly 16F88 version of both the main instruction & pseudo commands (omitting the silly b (branch)) Don't have the cycle times worked out though.
 

Attachments

  • 16F instruction set.pdf
    35.3 KB · Views: 247
Last edited:
Nowadays

For the 18F family their use seems to be discouraged. Nowhere I saw them mentioned in connection with the 18F.

Never used them, thanks God.
 
atferrari said:
For the 18F family their use seems to be discouraged. Nowhere I saw them mentioned in connection with the 18F.

Never used them, thanks God.

The 18F are teriffic chips, a little intimidating at first but in fact eaiser to program than the 16F & 12F chips.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top