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

PIC interfacing with 74595 and 7 segment

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



Joined: 28 Dec 2012
Posts: 21

View user's profile Send private message

PIC interfacing with 74595 and 7 segment
PostPosted: Mon Mar 11, 2013 4:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 11, 2013 5:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 11, 2013 6:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 11, 2013 9:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 12, 2013 2:28 am     Reply with quote

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: 19538

View user's profile Send private message

PostPosted: Tue Mar 12, 2013 2:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 12, 2013 3:14 am     Reply with quote

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 Embarassed
thanks for your help Smile
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