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 to implement table lookup in this procedure?

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



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

how to implement table lookup in this procedure?
PostPosted: Fri Feb 17, 2006 1:09 pm     Reply with quote

My question is now how to implement this segment table in the below code= the bold text

It displays now only segments, but not correct numbers (0,1,2,3,4,5,6,7,8,9)

Code:

// Segment table (In hex: d.p.=80,g=40,f=20,e=10,d=08,c=04,b=02,a=01)
byte const seg_table[10] = {
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F }; // 0,1,2,3,4,5,6,7,8,9

void saa1064_write_num(int8 addr,int8 control,int16 num) {
int1 leading=true;
int8 led_data[4];
int8 j;
int16 temp16;

for(j=0;j<3;j++) {
temp16=num/10;
led_data[j]=num-(temp16*10);
num=temp16;
}
led_data[3]=num;

for(j=3;j>0;j--) {
if (leading && led_data[j]==0)
led_data[j]=SEGMENT_CHAR_BLANK;
else
leading=false;
}

i2c_start();
i2c_write(addr);
i2c_write(SAA1064_REG_CONTROL);
i2c_write(control);

for(j=0;j<=3;j++)
i2c_write(led_data[j]);

i2c_stop();
}
[/b]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 17, 2006 2:31 pm     Reply with quote

1. Create an array of digits that you want to display.
Each value in the digit array will be an integer from 0 to 9.

2. Use the digit array values as an index into the segment table.
Get the segment value that corresponds to the digit value.
This is why it is called a "look-up table".

3. When you get the segment values for all the digits, then
send them to the SAA1064.
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 17, 2006 2:34 pm     Reply with quote

PCM programmer wrote:
1. Create an array of digits that you want to display.
Each value in the digit array will be an integer from 0 to 9.

2. Use the digit array values as an index into the segment table.
Get the segment value that corresponds to the digit value.
This is why it is called a "look-up table".

3. When you get the segment values for all the digits, then
send them to the SAA1064.


Then is must change this code in the proc, but how??
Code:
for(j=0;j<3;j++) {
temp16=num/10;
led_data[j]=num-(temp16*10);
num=temp16;
}
led_data[3]=num;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 17, 2006 2:42 pm     Reply with quote

Can I tell you something about your style of using this forum ?
Your style disappoints most people.
That's why your posts sink down the list with no answers.

The problem is that you don't want to do any work.
You don't even try to solve the problem yourself, in any way.
As soon as you get a "live one" (someone who answers your post)
you immediately turn around and "dump code" on the person.
It's clear that you have not even looked at the code or thought
about a solution in any way.

We don't want to take your class for you, or do your work.

I gave you one more chance, when I answered you just now.
You disappointed me. I'm not going to do your work for you.
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 17, 2006 4:11 pm     Reply with quote

Sorry PCM programmer,

but i am new in c programming and uC's
It is not as easy as i thought.

But i will try it tomorrow, hopes i can get it to work Wink

UPDATE
This work with lookup table, but now zero blanking
Code:
// Segment table
byte const seg_table[10] = {
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F };  // 0,1,2,3,4,5,6,7,8,9

void saa1064_write_num(int8 addr,int8 control,int16 num) {
   int8 led_data[4];
   int8 j;
   int16 temp16;

   for(j=0;j<3;j++) {
      temp16=num/10;
      led_data[j]=seg_table[num-(temp16*10)];
      num=temp16;
   }
   led_data[3]=seg_table[num];

   i2c_start();
   i2c_write(addr);
   i2c_write(SAA1064_REG_CONTROL);
   i2c_write(control);
   for(j=0;j<=3;j++)
      i2c_write(led_data[j]);
   i2c_stop();
}
Guest








PostPosted: Sun Feb 19, 2006 8:00 am     Reply with quote

Since its Sunday, I'll give you a hint. Read PCM Programmer's post again carefully, especially Points 1 and 2. You did not do what he suggested. In fact, you're kind of doing the opposite.

Remember, the index to seg_table must be an integer from 0-9.

r.b.
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Feb 19, 2006 9:20 am     Reply with quote

i have found it Smile Smile Smile
it works now, but it cost me several hours Embarassed
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