assigning register bits to an array?


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1

    Default assigning register bits to an array?

    My question is, can i assign different registers and some of their individual bits to a single array ? ( or similar process?)

    Some background. im using a 16f917 and driving a 3 1/2 numeric display- this being on a mechaatronics demo board. I'm writing to the lcd segment registers LCDDATA0 to LCDDATA11 in order to map the individual elements of the display. However for example in order to drive all elements in the first numeric i'm using


    lcddata2.6=1 'seg a
    lcddata2.7=1 'seg b
    lcddata8.7=1 'seg c
    lcddata11.6=1 'seg d
    lcddata8.6=1 'seg e
    lcddata5.6=1 'seg f
    lcddata5.7=1 'seg g

    and then doing all the above again to show a different number (ie to show '2' the pattern for segments a-g is 1101101, to show '3' the pattern is 1111001) etc

    to my mind there must be a better (more elegant) way than a seperate call for every single segment but as the assignments of LCDDATA addresses to LCD segments seems to be scattered almost randomly I cannot see how to map these in a more meaningful way

    Any ideas?

    Alastair

    ps whats a tag?

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Usual way is to use a lookup table to display the numerical representation of your number.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    if you mean 'lookup '3' and get code '1111001' then i'm good with that but i do'nt get how that helps writing to the specific lcddata registers and the individual bits as above.

    Picbasic manual suggests that QUOTE - "All of the PICmicro registers, including the ports, can be accessed just like any other byte-sized variable in PICBASIC PRO™. " but can variables be defined in an array, table etc

    It's the code ( in this case displaying '0' ) that i'm trying to change:-

    LCDDATA2.6 = 1
    LCDDATA2.7 = 1
    LCDDATA8.7 = 1
    LCDDATA11.6 = 1
    LCDDATA8.6 = 1
    LCDDATA5.6 = 1
    LCDDATA5.7 = 0

    'cos to display 10 numbers (0-9) as above requires 10 repeats of the above code, and of course the other two 7-seg display requires a further 20 code blocks of the above.

    Any suggestions for cutting all of that down would be appreciated

    alastair

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Let's see the code in context as to how you are using it, The little bit you posted I cannot make heads or tails of it. Basically you assign a port to the displays and your number to a variable . . . Index var byte . . then from the manual . . ..
    Code:
     LOOKUP2 Index,[value, value, value . . .],var
    var is where the segment patterns are stored, then port = var . . . value is the segment pattern of each number. Use the DIG statement to select each individual digit to cycle through the lookup loop.
    Last edited by Archangel; - 17th January 2009 at 18:14.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5


    Did you find this post helpful? Yes | No

    Thumbs down

    Thanks Joe S for sticking with this !

    Mabye a little more detail on the mechaatronics demo board. Its pre-wired to drive directly an on-board 3 1/2 digit 7 segment numeric display via the SEG pins . The right hand charactor segments are labeled 1a,1b,1c,1d,1e,1f,1g. the middle charactor segments are labled 2a,2b,2c -- etc through to the left hand third charactor 3g.
    The fourth charactor is only a '1' and is labled 4b and 4c.
    Also on the display are numerous logos ie battery,negative sign,speaker,diode,Volts,Amps etc (like a cheap multimeter digital display)

    (i hope the below formats properly)


    ---3a-- --2a-- --1a--
    | | | | | | |
    4b 3f 3b 2f 2b 1f 1b
    | | | | | | |
    ---3g-- ---2g-- --1g--
    | | | | | | |
    4c 3e 3c 2e 2c 1e 1c
    | | | | | | |
    ---3d--- ---3d--- --1d--

    Now these are mapped onto the 16f917 registers LCDDATA0 through to LCDDATA11 in what seems almost at random. To give you a small flavour ( if this formats correctly) of the first four registers:-

    LCDDATA0 LCDDATA1 LCDDATA2 LCDDATA3
    bit0 A - s1 V
    bit1 RC - - BATT
    bit2 DH - - RH
    bit3 3a 3b - 3f
    bit4 - - - -
    bit5 - - 2b -
    bit6 2a - 1a 2f
    bit7 - - 1b -

    where -=not connected, and A,RC,DH,BATT,RH,s1 are some of the logos mentioned above

    this mapping continues all the way to register LCDDATA11

    As for my code. This is very initial playing with the demo board, no actual programs yet, just seeing how it works. 'Hello world' stuff on the display

    So appart from initial initialisation of the LCDSE0,LCDSE1 and LCDSE2 registers to allow for using the pins as lcd direct drive (SEG0 to SEG23 on the pic16917 pins) - Thats all im doing so far. Each code line sets just one bit in a LCDDARA register which maps to one lcd display element ie

    LCDDATA2.6 = 1 switches on lcd element 1a
    LCDDATA2.7 = 0 switches off lcd element 1b

    by doing this one by one Im able to swith on/off all elements in the diplay, and so in my code displayed above :-
    " lcddata2.6=1 'seg a
    lcddata2.7=1 'seg b
    lcddata8.7=1 'seg c
    lcddata11.6=1 'seg d
    lcddata8.6=1 'seg e
    lcddata5.6=1 'seg f
    lcddata5.7=1 'seg g "
    im switching on all the elements in the 1st charactor 7-segment display.

    My real problem is therefore that these display elements are spread all over the LCDDATA registers and im creating charactor displays by manipulating register bits one by one.

    Im therefore trying to cut down on the above by trying to see if i can group the sets of register bits in some way in array or table etc,


    for example :- ( in pseudocode 'cos i dont know if it can be done in picbasic)

    CHR0 var byte(lcddata2.6,lcddata2.7,lcddata8.7,lcddata11.6, lcddata8.6,lcddata5.6,lcddata5.7)

    if this can be done ( my original question) then i can feed the byte patterns to VAR CHR0 (directly or by lookup table) to change the Right hand numeric display charactor as needed.


    I hope the above explains things

    Alastair

  6. #6


    Did you find this post helpful? Yes | No

    Default

    The below re-done cos i am not allowed to edit the post above - changed cos the formatting changes when displayed in the forum.

    Thanks Joe S for sticking with this !

    Mabye a little more detail on the mechaatronics demo board. Its pre-wired to drive directly an on-board 3 1/2 digit 7 segment numeric display via the SEG pins . The right hand charactor segments are labeled 1a,1b,1c,1d,1e,1f,1g. the middle charactor segments are labled 2a,2b,2c -- etc through to the left hand third charactor 3g.
    The fourth charactor is only a '1' and is labled 4b and 4c.
    Also on the display are numerous logos ie battery,negative sign,speaker,diode,Volts,Amps etc (like a cheap multimeter digital display)

    (i hope the below formats properly)


    ---3a-- --2a-- --1a--
    | | | | | | |
    4b 3f 3b 2f 2b 1f 1b
    | | | | | | |
    ---3g-- ---2g-- --1g--
    | | | | | | |
    4c 3e 3c 2e 2c 1e 1c
    | | | | | | |
    ---3d--- ---3d--- --1d--

    (edited cos the above doesnt show correctly in the forum - think of 1888 with the top cross bar of the '8' s being ( from left to right) 3a,2a,1a then in normal 7 segment labeling a to g for each segment)


    Now these are mapped onto the 16f917 registers LCDDATA0 through to LCDDATA11 in what seems almost at random. To give you a small flavour ( if this formats correctly) of the first four registers:-

    LCDDATA0 bit0 = A, LCDDATA0 bit1 =RC, ALCDDATA0 bit2 = DH, ALCDDATA0 bit3 = 3a ALCDDATA0 bit4 = *,ALCDDATA0 bit5 = *, ALCDDATA0 bit6 = 2a, LCDDATA0 bit7 = *

    LCDDATA1 bit0 = *, LCDDATA0 bit1 =*, ALCDDATA0 bit2 = *, ALCDDATA0 bit3 = 3b ALCDDATA0 bit4 = *,ALCDDATA0 bit5 = *, ALCDDATA0 bit6 = *, LCDDATA0 bit7 = *

    LCDDATA2 bit0 = s1, LCDDATA0 bit1 =*, ALCDDATA0 bit2 = *, ALCDDATA0 bit3 = *, ALCDDATA0 bit4 = *,ALCDDATA0 bit5 = 2b, ALCDDATA0 bit6 = 1a, LCDDATA0 bit7 = 1b

    ( just edited above cos the table layout didnt work out of edit mode, its easier to see in a table)

    where *=not connected, and A,RC,DH,BATT,RH,s1 are some of the logos mentioned above

    this mapping continues all the way to register LCDDATA11

    As for my code. This is very initial playing with the demo board, no actual programs yet, just seeing how it works. 'Hello world' stuff on the display

    So appart from initial initialisation of the LCDSE0,LCDSE1 and LCDSE2 registers to allow for using the pins as lcd direct drive (SEG0 to SEG23 on the pic16917 pins) - Thats all im doing so far. Each code line sets just one bit in a LCDDARA register which maps to one lcd display element ie

    LCDDATA2.6 = 1 switches on lcd element 1a
    LCDDATA2.7 = 0 switches off lcd element 1b

    by doing this one by one Im able to swith on/off all elements in the diplay, and so in my code displayed above :-
    " lcddata2.6=1 'seg a
    lcddata2.7=1 'seg b
    lcddata8.7=1 'seg c
    lcddata11.6=1 'seg d
    lcddata8.6=1 'seg e
    lcddata5.6=1 'seg f
    lcddata5.7=1 'seg g "
    im switching on all the elements in the 1st charactor 7-segment display.

    My real problem is therefore that these display elements are spread all over the LCDDATA registers and im creating charactor displays by manipulating register bits one by one.

    Im therefore trying to cut down on the above by trying to see if i can group the sets of register bits in some way in array or table etc,


    for example :- ( in pseudocode 'cos i dont know if it can be done in picbasic)

    CHR0 var byte(lcddata2.6,lcddata2.7,lcddata8.7,lcddata11.6, lcddata8.6,lcddata5.6,lcddata5.7)

    if this can be done ( my original question) then i can feed the byte patterns to VAR CHR0 (directly or by lookup table) to change the Right hand numeric display charactor as needed.


    I hope the above explains things

    Alastair

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  3. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  4. Replies: 14
    Last Post: - 26th September 2007, 05:41
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

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