Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Doubt asm 16 bits 16F877

Status
Not open for further replies.

aless2056

Member level 1
Member level 1
Joined
May 11, 2020
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
338
Guys, I'm starting with assembly programming and I have a lot of doubt on how to deal with 16 bits, 2 bytes.

I have the code below, how this code would be if the variables Process, Setpoint and PWM were to have an example number up to 1024, instead of 256.

Code:
CLRWDT

    MOVF    PROCESS_KW,W
    SUBWF    SETPOINT,W
    BTFSC    STATUS,Z
    GOTO    EXIT
  

    MOVLW    .5
    SUBWF    PROCESS,W
    BTFSS    STATUS,C
    MOVLW    .0
    SUBWF    SETPOINT,W
    BTFSC    STATUS,Z
    GOTO    EXIT
    BTFSS    STATUS,C
    GOTO    PWM_DEC
                      

    MOVLW    .5
    ADDWF    PROCESS,W
    SUBWF    SEPOINT,W
    BTFSC    STATUS,Z
    GOTO    EXIT
    BTFSC    STATUS,C
    GOTO    PWM_INC
    GOTO    EXIT


PWM_DEC

    MOVLW    .0
    XORWF    PWM,W
    BTFSC    STATUS,Z
    GOTO    EXIT
  
    DECF    PWM,F
    GOTO    EXIT


PWM_INC

    MOVLW    .255
    XORWF    PWM,W
    BTFSC    STATUS,Z
    GOTO    EXIT
  
    INCF    PWM,F
    GOTO    EXIT

EXIT
 
Last edited by a moderator:

Hi,

Most necessary: read the datasheet. It even contains example code in assembly.

And the manufacturer provides a lot of additional information.

Klaus
 

My question is how to deal with subtraction, addition and comparison with 16bit on the PIC16F877, with 8 bit, I have no doubt, but with a number that uses 16bit complicates.
 

Hi,

This is most basic. If you do an internet search you will find million of explanations, examples, code, even videos.

Basically:
A is a 16 bit value, divided into 8 bits it is AH, AL
B ... BH, BL

First add AL + BL .....and get RL ... but additionally get Carry.
Then add AH + BH + Cy and get RH and Carry.

It's very similar to calculating by hand.

Klaus
 

I assume you are using such an old chip for a reason -otherwise there are plenty of newer chips available that are very low priced and more capable. For example the direct replacement for your chip is the PIC16F18877 that has an ADDWFC (add with carry) that will make life a LOT easier for you.
If you want to see some sample code for your chip, write a trivial program in C that does an addition of 2 16-bit integers, compile that using the XC8 compiler (its free) for the PIC16F877 and tell it to output the generated code listing. (For a comparison, do the same for the PIC16F8877!)
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top