View previous topic :: View next topic |
Author |
Message |
amit78
Joined: 17 Jul 2009 Posts: 21 Location: Kolkata, India
|
Problem lighting seven segment LED type common cathode |
Posted: Mon Aug 31, 2009 7:56 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
wireless
Joined: 02 Nov 2003 Posts: 16 Location: London England
|
|
Posted: Mon Aug 31, 2009 8:27 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
amit78
Joined: 17 Jul 2009 Posts: 21 Location: Kolkata, India
|
Problem lighting seven segment LED type common cathode |
Posted: Tue Sep 01, 2009 12:10 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|