• AVR Freaks

Hot!dsPIC programming

Author
amctech
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2019/02/20 09:58:46
  • Location: 0
  • Status: offline
2019/08/07 00:10:42 (permalink)
0

dsPIC programming

Hello,
I created a unit of bools and few variables based on it as follows:


typedef union {
    uns16 host_port;
    struct {
        uint16_t b0 : 1, b1 : 1, b2 : 1, b3 : 1, b4 : 1, b5 : 1, b6 : 1, b7 : 1, b8 : 1, b9 : 1, b10 : 1, b11 : 1, b12 : 1, b13 : 1, b14 : 1, b15 : 1;
    };
} host_port;
host_port host_a;
host_port host_b;
host_port host_c;
And now I am going to create some arrayof Booleans like this:
  uint16_t hp[24] = {
            host_a.b15, 
            host_b.b8, 
            host_b.b9, 
            host_c.b5, 
            host_c7, 
…}
Then I an trying to pass some values to the array variables:
hp[num] = (uint16_t) val;
but it does not work.
What is a right approach to a problem solving?
#1

7 Replies Related Threads

    Rolando A.
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2017/07/04 01:02:21
    • Location: 0
    • Status: offline
    Re: dsPIC programming 2019/08/07 00:29:00 (permalink)
    0
    What do you want to do? Seems should be an easier way to do it...
    #2
    amctech
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2019/02/20 09:58:46
    • Location: 0
    • Status: offline
    Re: dsPIC programming 2019/08/07 00:33:41 (permalink)
    0
    I want to change switch(num) that is working, by array arr[num]=value.
    #3
    Rolando A.
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2017/07/04 01:02:21
    • Location: 0
    • Status: offline
    Re: dsPIC programming 2019/08/07 01:25:27 (permalink)
    0
    how about changing the uint16_t hp array to a host_port hp array ? 
    #4
    amctech
    New Member
    • Total Posts : 19
    • Reward points : 0
    • Joined: 2019/02/20 09:58:46
    • Location: 0
    • Status: offline
    Re: dsPIC programming 2019/08/07 01:42:09 (permalink)
    0
    Then I get problems of casting:
     hp[num] = (?)val;
    #5
    du00000001
    Just Some Member
    • Total Posts : 3184
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC programming 2019/08/07 01:48:25 (permalink)
    0
    This approach cannot be brought to work: there's nothing like a "bit address" that could be stored in an array.
    (The bit definitions in structs/unions "work" differently: I recommend to risk an eye on the machine code generated to get an impression of the difference.)
    post edited by du00000001 - 2019/08/07 01:51:15

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    Rolando A.
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2017/07/04 01:02:21
    • Location: 0
    • Status: offline
    Re: dsPIC programming 2019/08/07 01:48:49 (permalink)
    0
    create extra host_port variables, use these variable as place holders for uint16_t and then assign it to any element in the host_port array.
     
    Will that work?
    #7
    ric
    Super Member
    • Total Posts : 24333
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: dsPIC programming 2019/08/07 02:24:13 (permalink)
    0
    As already pointed out, you can store the address of a whole port, you can NOT store an address for a single bit. There isn't one.
    To access bits indirectly, you have to use bitwise AND and OR operators with bit masks.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5