Altering a variable in a loop.


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Altering a variable in a loop.

    From the manual....
    When BIT variables are created, PBP must reserve full BYTEs of RAM and then
    assign variable names to each bit within the BYTE containers. This is fine in most
    cases, but you may wish to control this yourself. To create a bit variable and
    control the BYTE it's assigned to, you can use aliasing to do it manually:
    my_flags VAR BYTE 'Create a container for bits
    flag0 VAR my_flags.0 'Assign an alias to bit-0
    flag1 VAR my_flags.1 'Assign an alias to bit-1
    This is exactly what PBP would do in the background, but it will assign its own
    name to the "container" BYTE variable. It's useful to take control and assign this
    name manually, especially when debugging in an environment that won't show
    individual bits in a watch window.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Aug 2012
    Location
    Comodoro Rivadavia - Patagonia Argentina
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Re: Altering a variable in a loop.

    Just like that mackrackit!!
    I, for example, in a project to implement a 10-bit ADC and the output of the pic, I had to generate a 10-bit DAC to simulate approximately the incoming analog signal, so I wrote this (similar to the example):

    Adc VAR WORD
    D0 VAR Adc.0
    D1 VAR Adc.1
    D2 VAR Adc.2
    D3 VAR Adc.3
    D4 VAR Adc.4
    D5 VAR Adc.5
    D6 VAR Adc.6
    D7 VAR Adc.7
    D8 VAR Adc.8
    D9 VAR Adc.9

    TRISA = %11111111
    TRISB = %00000000
    TRISD = %00000000

    ADCON1.7 = 1

    Inicio:
    ADCIN 0,Adc

    PORTD.0 = D0
    PORTD.1 = D1
    PORTD.2 = D2
    PORTD.3 = D3
    PORTD.4 = D4
    PORTD.5 = D5
    PORTD.6 = D6
    PORTD.7 = D7
    PORTB.0 = D8
    PORTB.1 = D9
    GoTo Inicio

    regards friends!!!
    Last edited by martintorres; - 15th September 2012 at 08:04.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Altering a variable in a loop.

    Or
    Code:
    PortD = ADC.LowByte   ' Or ADC.Byte0
    PortB.0 = ADC.8
    PortB.1 = ADC.9
    Or perhaps even
    Code:
    PortD= ADC.LowByte
    PortB = ADC.HighByte
    But the later will write "fill" the upper 6 bits of PortB with zeros (or whatever is in the upper 6 bits of the ADC variable) which may or may not be an actual problem.

    Neither of this has anything to do with the original question of course, sorry about that.

    /Henrik.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Altering a variable in a loop.

    Dave
    Always wear safety glasses while programming.

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