Log in

View Full Version : assigning register bits to an array?



bakerajatha
- 16th January 2009, 18:43
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?

Archangel
- 17th January 2009, 00:44
Usual way is to use a lookup table to display the numerical representation of your number.

bakerajatha
- 17th January 2009, 11:37
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

Archangel
- 17th January 2009, 19:10
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 . . ..
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.

bakerajatha
- 18th January 2009, 15:02
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

bakerajatha
- 18th January 2009, 15:19
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

jderson
- 18th January 2009, 16:47
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

bakerajatha
- 18th January 2009, 19:57
jderson

the demo board is made by Microchip Mechatronics Demonstration Kit
Part Number: DM163029
try http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023837&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/viewtopic.php?t=32774&highlight=16f917+lcd - i was just hoping my understanding and syntax was limited and theres some workaround in picbasic

good luck

alastair

bakerajatha
- 18th January 2009, 20:19
sorry, mapping on page 58

alastair

Archangel
- 18th January 2009, 21:23
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

bakerajatha
- 18th January 2009, 22:34
Ooooooh how I wish !!!!!! :rolleyes:

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

jderson
- 19th January 2009, 00:38
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

bakerajatha
- 19th January 2009, 12:36
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:D

bakerajatha
- 19th January 2009, 20:12
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