CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How do I create a lookup table using arrays?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SlimG



Joined: 03 Dec 2004
Posts: 6

View user's profile Send private message

How do I create a lookup table using arrays?
PostPosted: Wed Dec 22, 2004 1:36 pm     Reply with quote

hi there, i am trying to create a lookup table that would display numbers between 0 and 360 on three multiplexed 7segment displays, using arrays.
any ideas or sample codes please? thanx
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 22, 2004 3:26 pm     Reply with quote

Here are two possiblities for representing how to light the segments. I didn't bother putting in the 1's vs 0's since I don't know how you are wired up so just fill in the table appropriately.

Code:
const int8 seg7[10][7] =
//g,f,e,d,c,b,a
{ 0,0,0,0,0,0,0, // 0
  0,0,0,0,0,0,0, // 1
  0,0,0,0,0,0,0, // 2
  0,0,0,0,0,0,0, // 3
  0,0,0,0,0,0,0, // 4
  0,0,0,0,0,0,0, // 5
  0,0,0,0,0,0,0, // 6
  0,0,0,0,0,0,0, // 7
  0,0,0,0,0,0,0, // 8
  0,0,0,0,0,0,0  // 9
};

In this example, I used a 2d array where each column element represents a single segment. This is pretty inefficient (70 bytes) but depending on how you are controlling the display, it may work better than the more straight forward version below.

Code:

const int8 seg7b[10] =
//   gfedcba
{ 0b00000000, // 0
  0b00000000, // 1
  0b00000000, // 2
  0b00000000, // 3
  0b00000000, // 4
  0b00000000, // 5
  0b00000000, // 6
  0b00000000, // 7
  0b00000000, // 8
  0b00000000  // 9
};

Here I only used 10 bytes and each byte would have its bits encoded to a particular segment LED.

To get the magic word for a number, you will take apart the number to find the 100's, 10's and 1's. You can tweak the display code for leading zero blank.

If you want a single table to hold all possible combinations, you can expand the second example to be either a 3 x 361 array of int8's or a 361 entry array of int32s and waste one byte of the 32-bit word. You may run into memory allocation problems with an array of this size, depending on the PIC chip you have selected.

Unless I had no other choice, I'd use a small table to represent the 10 combinations I need for a single digit and just make 3 passes through the table.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group