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 CCS Technical Support

Decemical to 7-segments Convertion

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



Joined: 09 Jul 2004
Posts: 40
Location: Europe

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

Decemical to 7-segments Convertion
PostPosted: Mon Nov 29, 2004 2:13 pm     Reply with quote

I write example funct to write decemical int32 word to 9 LED 7-segments
displ. but maybe it is not so correct (maybe it can be more optimiz.)

Code:

void digit_select(int8 d)
{
switch (d) {
 case 1: PORTC=0b01111111; break;
 case 2: PORTC=0b10111111; break;
 case 3: PORTC=0b11011111; break;
 case 4: PORTC=0b11101111; break;
 case 5: PORTC=0b11110111; break;
 case 6: PORTC=0b11111011; break;
 case 7: PORTC=0b11111101; break;
 case 8: PORTC=0b11111110; break;
           }
}

void segment_select(int8 s,boolean point)
{
int8 plus=0;
if(point==TRUE) plus=128;
switch (s) {
 case 0: PORTD=0b11000000+plus; break;
 case 1: PORTD=0b11111001+plus; break;
 case 2: PORTD=0b10100100+plus; break;
 case 3: PORTD=0b10110000+plus; break;
 case 4: PORTD=0b10011001+plus; break;
 case 5: PORTD=0b10010010+plus; break;
 case 6: PORTD=0b10000010+plus; break;
 case 7: PORTD=0b11111000+plus; break;
 case 8: PORTD=0b10000000+plus; break;
 case 9: PORTD=0b10010000+plus; break;

          }
}

void output_int32_to_LED(unsigned int32 D1,int8 sel,boolean zer)
{
   unsigned int delay=5;
   char icount;
   char zero_detect=0;

// *********************************** Send Ten Millions
   icount=0;
   while(D1>9999999)
      {
   D1 = D1 - 10000000;
   icount++;
         zero_detect=1;
      }
if(icount!=0 || zero_detect==1 || zer==TRUE)
  {
   digit_select(8);
   segment_select(icount,FALSE);
   delay_ms(delay+h);
      led_n=8;
  }
// *********************************** Send Millions
   icount=0;
   while(D1>999999)
      {
   D1 = D1 - 1000000;
   icount++;
   zero_detect=1;
      }
if(icount!=0 || zero_detect==1 || zer==TRUE)
  {
   digit_select(7);
   segment_select(icount,FALSE);
   delay_ms(delay+g);
      led_n=7;
  }
// *********************************** Send Hungreds Thousands
   icount=0;
   while(D1>99999)
      {
   D1 = D1 - 100000;
   icount++;
   zero_detect=1;
      }
if(icount!=0 || zero_detect==1 || zer==TRUE)
  {
   digit_select(6);
   segment_select(icount,FALSE);
   delay_ms(delay+f);
      led_n=6;
  }
// *********************************** Send Ten Thousands
   icount=0;
   while(D1>9999)
      {
   D1 = D1 - 10000;
   icount++;
  zero_detect=1;
      }
if(icount!=0 || zero_detect==1 || zer==TRUE)
  {
   digit_select(5);
   segment_select(icount,FALSE);
   delay_ms(delay+e);
      led_n=5;
    }
// *********************************** Send Thousands
   icount=0;
   while(D1>999)
      {
   D1 = D1 - 1000;
   icount++;
   zero_detect=1;
      }
if(icount!=0 || zero_detect==1 || zer==TRUE)
  {
   digit_select(4);
   segment_select(icount,FALSE);
   delay_ms(delay+d);
      led_n=4;
  }
// *********************************** Send Hungreds
   icount=0;
   while(D1>99)
      {
   D1 = D1 - 100;
   icount++;
   zero_detect=1;
      }
if(icount!=0 || zero_detect==1 || zer==TRUE)
  {
   digit_select(3);
   segment_select(icount,FALSE);
   delay_ms(delay+c);
      led_n=3;
  }
// *********************************** Send Tens
   icount=0;
   while(D1>9)
      {
   D1 = D1 - 10;
   icount++;
  zero_detect=1;
      }
if(icount!=0 || zero_detect==1  || zer==TRUE)
  {
   digit_select(2);
   segment_select(icount,TRUE);
   delay_ms(delay+b);
      led_n=2;
  }
// *********************************** Send last Unit's
   digit_select(1);
   segment_select(D1,FALSE);
//   delay_ms(delay+a);
      led_n=1;

}



Maybe somebody help?
Guest








PostPosted: Tue Nov 30, 2004 8:13 am     Reply with quote

visti this site....

http://c.snippets.org/snip_lister.php?fname=str27seg.c
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