Writing to high/low variable pairs?


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce!


    .... I found the relevant part, but I don't understand it.

    I see these code snips...

    Code:
    @Timer1 = TMR1L
    Timer1  VAR  WORD EXT
    and "re-loading the timer is just as simple as..."

    Code:
    T1CON.0 = 0  ; stop timer
    Timer1 = Timer1 + TimerConst
    T1CON.0 = 1  ; turn timer back on
    and "another example"

    Code:
    @Capture = CCPR1L
    Capture   VAR  WORD EXT


    In the first example...

    @Timer1 = TMR1L
    Timer1 VAR WORD EXT

    "@" is a straight ASM line, apparently defining "Timer1" to equal TMR1L. Though this says nothing for what TMR1H should be called. The second line Timer1 VAR WORD obviously defines Timer1 as a variable for PBP - and the EXT has something to do with not doing something with it until it compiles - I didn't understand what that post was getting at.


    I'm also again seeing in the above post the inter-changing of various forms of hex numbering. I see "1234h" as well as "$1234" and again, I don't understand why you would use the hex in the first place as it's difficult to read - and again my question, is there some way to just write the value you want "12,385" in your code and have PBP turn it into binary or hex as required when compiling? The need to have to "hex" all your integers seems like a complicated additional step and I don't understand what it needs to be done.

    Thanks.
    Last edited by kevj; - 1st September 2007 at 06:13.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you don't understand Darrels' EXT explanation, you might want to come back to it at some
    point, and re-read it. It can be confusing if you don't get it.

    However, what you're trying to do doesn't require you to work in binary. You can just create
    a word sized variable, perform whatever math you need to on it, and then load it into Timer1
    high & low bytes.

    TimerConst VAR WORD

    This gives you a 16-bit variable. Now you can do things like TimerConst = 9612. TimerConst
    = TimerConst * 5. Now TimerConst = 48060. PBP automatically stores the result for you as
    two 8-bit binary values.

    Everything is stored as binary since the PIC internal structure is 8-bit registers.

    To load TimerConst into Timer1 low & high bytes you use TMR1L = TimerConst.LowByte, and
    TMR1H = TimerConst.HighByte.

    You can't do something like TMR1H:L=48060 since you're dealing with two 8-bit file registers
    for TMR1L and TMR1H. And you're dealing with two 8-bit values for TimerConst.

    It takes two separate operations. Load the low byte of TimerConst into TMR1L. Then load
    the high byte of TimerConst into TMR1H.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  5. WORD vs BYTE variable lengths
    By bartman in forum General
    Replies: 0
    Last Post: - 28th November 2005, 21:16

Members who have read this thread : 0

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