View previous topic :: View next topic |
Author |
Message |
syeda amna
Joined: 28 Dec 2012 Posts: 21
|
PIC interfacing with 74595 and 7 segment |
Posted: Mon Mar 11, 2013 4:49 am |
|
|
Hi
I m trying to interface a 7 segment with PIC using 74595. I dont know where is the problem. I just want to display a number. plzz help me how to accomplish this task.
Code: |
#INCLUDE <18F452.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=40000000)
#include <74595.c>
#define LATCH PIN_B0
#define CLOCK PIN_B1 //SH_CP
#define DATA PIN_B2
void main() {
int8 x=0;
int8 y;
int8 a = 0110000; // 1
output_low( LATCH );
output_low( CLOCK );
for(x=0;x<7;x++){
y=bit_test(a,x);
if(y==1){
output_high( DATA );
}
else
output_low( DATA );
output_high( CLOCK );
output_low( CLOCK );
}
//STCP or LATCH will shift the data out when toggled
output_high( LATCH );
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Mar 11, 2013 5:25 am |
|
|
You should really look at the files in the EXAMPLES folder that CCS supplies.In there is a a working program using the 74595 .
Once you have that 'up and running', expand the code to send '7-segment' data to the '595 that represents 0-1-2....9.
You could also search the forums here to see what others have done as you are not the first to ask for '595 help.
hth
jay |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Mon Mar 11, 2013 6:38 am |
|
|
One obvious problem--
int8 a = 0110000;
should be
int8 a = 0b01100000;
or
int8 a = 0b00110000;
Not clear which, because you've only put 7 bits in the byte.
And with a processor running at 40MHz, are the data lines changing too fast for the external component?
And, after this routine runs once, where is the program going to go?
Edited to say, the formatting here is atrocious, but as far as I can tell, the { and } marks are not balanced. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Mon Mar 11, 2013 9:43 am |
|
|
You're not the first to do this project.
You've already been told, there are loads of examples from CCS, on the forum and google.
Your code won't compile, so we can't test it as is.
I try to arrange that each closing } is immediately below its opening {.
I've done this to your code and get this:- Code: | #INCLUDE <18F452.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=40000000)
#include <74595.c>
#define LATCH PIN_B0
#define CLOCK PIN_B1 //SH_CP
#define DATA PIN_B2
void main()
{
int8 x=0;
int8 y;
int8 a = 0110000; // 1
output_low( LATCH );
output_low( CLOCK );
for(x=0;x<7;x++)
{
y=bit_test(a,x);
if(y==1)
{
output_high( DATA );
}
else
output_low( DATA );
output_high( CLOCK );
output_low( CLOCK );
}
//STCP or LATCH will shift the data out when toggled
output_high( LATCH );
}
}
|
Can you see now why the compiler complains?
Mike |
|
|
syeda amna
Joined: 28 Dec 2012 Posts: 21
|
|
Posted: Tue Mar 12, 2013 2:28 am |
|
|
John P wrote: | One obvious problem--
int8 a = 0110000;
should be
int8 a = 0b01100000;
or
int8 a = 0b00110000;
Not clear which, because you've only put 7 bits in the byte.
And with a processor running at 40MHz, are the data lines changing too fast for the external component?
And, after this routine runs once, where is the program going to go?
Edited to say, the formatting here is atrocious, but as far as I can tell, the { and } marks are not balanced. |
really an obvious mistake:oops:
thanks for your help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Mar 12, 2013 2:46 am |
|
|
40MHz, is _not_ a legal crystal speed for the PIC.
This part supports a maximum oscillator frequency of 25MHz. To work at 40Mhz, you have to use a 10MHz crystal, and the PLL, _or_ an external oscillator.... Classic 'read the data sheet'.
Mike has pointed out the other major problems....
Best Wishes |
|
|
syeda amna
Joined: 28 Dec 2012 Posts: 21
|
|
Posted: Tue Mar 12, 2013 3:14 am |
|
|
Ttelmah wrote: | 40MHz, is _not_ a legal crystal speed for the PIC.
This part supports a maximum oscillator frequency of 25MHz. To work at 40Mhz, you have to use a 10MHz crystal, and the PLL, _or_ an external oscillator.... Classic 'read the data sheet'.
Mike has pointed out the other major problems....
Best Wishes |
Yes. It was my silly mistake
thanks for your help |
|
|
|