assigning register bits to an array?


Closed Thread
Results 1 to 14 of 14
  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

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Hi Alistar-

    I too am getting ready to design a system using either the '914 or the '917. I am curious how this board of yours is wired. Can you provide a schematic of it? Why would it be wired "apparently at random". It is my understanding that there must be a pin on the PIC dedicated to every segment of the display, correct? I agree with you that being able to use an array some how should make programming easier. I will follow these posts with interest, and provide my experiences as I progress with my project (this week or next).

    Dave

  8. #8


    Did you find this post helpful? Yes | No

    Default

    jderson

    the demo board is made by Microchip Mechatronics Demonstration Kit
    Part Number: DM163029
    try http://www.microchip.com/stellent/id...&part=DM163029


    on page 50 of the demo users guide the connections are straight links, no buffering or interfacing.


    16f917


    pin name display

    37 com0 -- lcd pin1
    38 com1 -- 2
    19 com2 -- 3
    34 seg1 -- 4
    35 seg2 -- 5
    36 seg3 -- 6
    23 seg11 -- 7
    18 seg6 -- 8
    8 seg21 -- 9
    9 seg22 -- 10
    10 seg23 -- 11
    22 seg16 -- 12
    33 seg0 -- 13


    dunno why they made the pin assignments ( other than com1,2,3 which the display needs)
    page 19 shows the mapping of the segments onto LCDDATA registers depending on the COM/SEG pins

    if you get anywhere let me know. Via google i know that the CCS (whisper here when you say that) C compiler can do it,http://www.ccsinfo.com/forum/viewtop...ght=16f917+lcd - i was just hoping my understanding and syntax was limited and theres some workaround in picbasic

    good luck

    alastair

  9. #9


    Did you find this post helpful? Yes | No

    Default

    sorry, mapping on page 58

    alastair

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


    Did you find this post helpful? Yes | No

    Default

    That all looks VERY confusing ! The usual way to interlace 7 segment displays is to hook up all the "a" segments together, all the "b" segments to each other . . . and you use1 port per display unit to decide which display is illuminated. . . . I am beginning to see . . . you are using LCD on the demo board . . . pins scattered all over the micro controllers ports . . . look at this link:http://www.picbasic.co.uk/forum/showthread.php?t=3753
    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.

  11. #11


    Did you find this post helpful? Yes | No

    Default

    Ooooooh how I wish !!!!!!

    Anyway thanks for the link, for the moment its making my head hurt but ill work my way through that tomorrow, offhand unless there is a more direct route it maybe the way to go

    thanks
    Alastair

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Alistair

    After close examination and some digging, I find the LCD on this board (datasheet attached) is a 1/4 multiplexed display. This is done to keep the number of pins to a minimum, but boy, is it going to be fun to program! This is intriguing to me, because that infers I can use a 16f913 with this display.
    Now all I have to do is find a place to buy it!

    Dave
    Attached Images Attached Images

  13. #13


    Did you find this post helpful? Yes | No

    Default

    from the link posted by joe s i did some digging around and i came accreoo this little gem from Ingvar

    x var byte
    i var byte

    main:
    for i = 0 to 3
    ' a b c d
    ' 0 6 4 2
    LOOKUP i, [0,14,20,26], x
    porta.0[x]=1
    PAUSE 1000
    porta.0[x]=0
    PAUSE 300
    next i


    from this thread http://www.picbasic.co.uk/forum/showthread.php?t=4074

    Which is using a look up table to (undocumented feature) offset address a port bit off a register. they are talking about relays but i'm going to have a go for lcddata register bit addressing

    Thanks to all for your help

    Alastair

  14. #14


    Did you find this post helpful? Yes | No

    Default

    this works passing a bit pattern to individual bits as long as you know the bit offset from a register

    in my case using register LCDDATA

    ' lcd setup
    lcdcon = %11111111 'control register
    lcdse0 = %11111111
    lcdse1 = %11111111
    lcdse2 = %11111111 'choose all pins for lcd use
    lcdps = %00000000 'clock control, 0 is static


    i var byte
    x var byte
    set var byte


    main:
    'display charactor '0' on 1st segment
    for i= 0 to 6
    lookup i, [22,23,71,94,70,46,47], x '1st 7-segments offsets
    lookup i, [1,1,1,1,1,1,1,0],set 'set character '0'
    LCDDATA0.0[x] = set 'display it
    next i
    pause 500 'some time to see it

    'display charactor '4' on 1st segment
    for i= 0 to 6
    lookup i, [22,23,71,94,70,46,47],x '1st 7-segment
    lookup i, [0,1,1,0,0,1,1],set 'set character '4'
    LCDDATA0.0[x] = set 'display it
    next i
    pause 500 'some time to see it

    goto main

    -------------------------------------------------
    With this my origional question answered, thanks to all

    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 : 1

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