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

Problem lighting seven segment LED type common cathode

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



Joined: 17 Jul 2009
Posts: 22
Location: Kolkata, India

View user's profile Send private message

Problem lighting seven segment LED type common cathode
PostPosted: Mon Aug 31, 2009 7:56 am     Reply with quote

Hi All,

I was trying to light up LEDs using PIC18F452. I wanted to display values 0 to 9 on one seven segment LED.

My problem is digit 6 not lighting properly. I used the following code to do this:
Code:

#include <18F452.h>

#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock=4000000)

//Pin values for common Cathode 7 segment LED
#define ZERO  0x3F
#define ONE   0x06
#define TWO   0x5B
#define THREE 0x4F
#define FOUR  0x66
#define FIVE  0x6D
#define SIX   0x7D
#define SEVEN 0x07
#define EIGHT 0x7F
#define NINE  0x6F
#define POINT 0x80

void main()
{
    int8 i;

    set_tris_d(0x00);
    output_d(0xFF);
   
    while(true)
    {
       for(i = 0; i < 10, i++)
       {
          output_d(0x00);
           
          DisplaySegment(i);
          delay_ms(100);
       }
    }
}

void DisplaySegment(int8 val)
{
   switch(val)
   {
      case 0:
          output_d(ZERO);
         break;
      case 1:
         output_d(ONE);
         break;
      case 2:
         output_d(TWO);
         break;
      case 3:
         output_d(THREE);
         break;
      case 4:
         output_d(FOUR);
         break;
      case 5:
         output_d(FIVE);
         break;
      case 6:
         output_d(SIX);
         break;
      case 7:
         output_d(SEVEN);
         break;
      case 8:
         output_d(EIGHT);
         break;
      case 9:
         output_d(NINE);
   }   
}


When I am using the LED of type common anode all the values from 0 to 9 are displaying correctly with same circuit. Could you please tell me where I have done wrong?
Code:

//Pin values for common Anode 7 segment LED
#define ZERO  0xC0
#define ONE   0xF9
#define TWO   0xA4
#define THREE 0xB0
#define FOUR  0x99
#define FIVE  0x92
#define SIX   0x82
#define SEVEN 0xF8
#define EIGHT 0x80
#define NINE  0x90
#define POINT 0x7F


Thanks & Regards,
Amit
wireless



Joined: 02 Nov 2003
Posts: 16
Location: London England

View user's profile Send private message

PostPosted: Mon Aug 31, 2009 8:27 am     Reply with quote

Hi Amit
When you say the "same hardware" I assume you are connecting the common cathode pin to ground(VSS)- it would have been high for the common anode display. Also, you must have current limiting resistors, of say 470ohms, in series with each segment.

Your code looks fine but probably not the simplest way of achieving the decimal to 7segment decoder function.

You could simply generate an array with the segment values, i.e. your define values, then use the index i to fetch the segment value from the array and then put this value into the output_d() function.

Good luck.
Terry
amit78



Joined: 17 Jul 2009
Posts: 22
Location: Kolkata, India

View user's profile Send private message

Problem lighting seven segment LED type common cathode
PostPosted: Tue Sep 01, 2009 12:10 am     Reply with quote

Thanks for your quick response. I have sorted out problem. I am very much sorry to say that I made mistake in my circuit. Also I have implemented your coding suggestion.

Thanks and Regards,
Amit
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