Easy way to do multiple write statements ?


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Easy way to do multiple write statements ?

    Quote Originally Posted by Jerson View Post
    Assuming that each of the hours and minutes are bytes and PWM value is a word, the write command will fill up 6 bytes on each pass. So, the code would become
    Code:
       address =$50
       for counterd = 0 to 15
           write (address + (counterD*6)),lightsetHR(counterD),lightsetMN(counterD),lighto ffHR(counterD),lightoffMN(counterD),fadeset(counte rD)
       next counterD
    OR you could also do this
    Code:
      address =$50
      for counterd = 0 to 15
         write (address),lightsetHR(counterD),lightsetMN(counterD),lighto ffHR(counterD),lightoffMN(counterD),fadeset(counte rD)
         address = address+6  ' account for the data already filled into the storage
      next counterD
    Guys, I need a little help in a similar vein.

    I'm working on a slightly different program using similar variables only this time I save 48 word variables, which results in 96 lines of code for both WRITE and READ statements. The word variables are
    CH1_Max, CH1_on_Time, CH1_off_Time, so I have

    Code:
    read 40,CH1_on_Time.lowbyte          
    read 41,CH1_on_Time.highbyte
    read 42,CH2_on_Time.lowbyte          
    read 43,Ch2_on_Time.highbyte
    Rather than have 96 lines of code is there a simple way to do this with a FOR / NEXT loop similar to above

    I did try

    Code:
    for n = 8 to 38 step 2
    READ n, ch(n)_max.lowbyte
    next n
    
    
    for n = 9 to 39 step 2
    READ n, ch(n)_max.highbyte
    next n
    But this just threw up errors when I tried compiling (I'm using PBP 2.60c)

    Any suggestions ?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Easy way to do multiple write statements ?

    the "EXT" modifier make this a breeze , see if you can follow this example



    Code:
      
        amps         Var Word   ext    ;chg mA
        volts        Var Word   ext    ;chg V
        kp           var word   ext
        kd           var word   ext
        ki           var word   ext
        f_0        var byte   ext
        f_1        var byte   ext
        f_2        var byte   ext
        f_3        var byte   ext
        setpoint     var word   ext   ;out volts
        cl           var word   ext   ;current limit
        flgs         VAR byte   ext
        drive        var word   ext   ;current pwm value
        a_cal        var word   ext
        v_cal        var word   ext
        bat_r        Var byte   ext    ;bits 0:3 is batt being charged , 4:7  batt connected flg
        data_blk        var byte[26]
     
    asm
    volts    = _data_blk   ;01
    amps     = _data_blk+2 ;23
    flgs     = _data_blk+4 ;4
    drive    = _data_blk+5 ; 56
    F_0      = _data_blk+7
    F_1      = _data_blk+8
    F_2      = _data_blk+9
    F_3      = _data_blk+10
    setpoint = _data_blk+11 ;1112
    bat_r    = _data_blk+13   
    ki       = _data_blk+14 ;1415
    cl       = _data_blk+16   
    kp       = _data_blk+18   
    kd       = _data_blk+20   
    a_cal    = _data_blk+22  
    v_cal    = _data_blk+24 ;2425
    
    endasm
    to save

    Code:
    for n =0 to 25
    write n, [data_blk[n]]
    next n
    to read
    Code:
    for n =0 to 25
    read n, [data_blk[n]]
    next n
    to just save vars f_0 to f_3

    Code:
    for n =7 to 10 
    write n, [data_blk[n]]
    next n
    or even better

    Code:
    for n =0 to 3 
    write n, [f_0[n]]
    next n
    Last edited by richard; - 7th March 2016 at 22:47.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Easy way to do multiple write statements ?

    Richard,

    what is the difference in using EXT ant this one?

    Code:
    data_blk  var byte [25]
    f_0       var data_blk[7]
    Ioannis

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Easy way to do multiple write statements ?

    ioannis


    data_blk var byte [25] this reserves 25 bytes for our data

    f_0 var data_blk[7] would definitely point to the correct byte but if you add or delete or rearrange or modify any vars in the array you have to go back and make sure the index is corrected , its easy to make a mistake and forget

    whereas :-

    using
    f_0 var byte ext the assembler does all the work and we still get an index-able byte sized pointer to use

Similar Threads

  1. Darrels interrupts and multiple SOUND statements, will it work?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 26th January 2015, 07:42
  2. Programming multiple pics with multiple programs
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 3rd April 2013, 17:47
  3. Multiple IF THEN Statements: PIC16F84A
    By bob425 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th August 2012, 06:01
  4. SD Multiple Write?
    By jimbostlawrence in forum General
    Replies: 1
    Last Post: - 21st October 2011, 17:45
  5. Multiple IF-THEN statements
    By DavidK in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th June 2007, 18:28

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