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 support@ccsinfo.com

need help with 74595. Very urgent, thx

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



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

need help with 74595. Very urgent, thx
PostPosted: Fri May 09, 2008 12:44 pm     Reply with quote

Code:
#include <16F877A.h>
#include <def_877a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)

#define     data        PIN_A0  // pin 14
#define     latch595    PIN_A1  // pin 12
#define     clk         PIN_A2  // pin 11





int8 led1,led2,led3,led4,led5,led6;
int8 const led7ac[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
int1 blink,blink_led1,blink_led2,blink_led3,blink_led4,blink_led5,blink_led6,led_off;
int8 count_display;


void latch(void);
void send595(int8 temp);
void display();



void main(){
   setup_adc(adc_off);
   setup_adc_ports(NO_ANALOGS);
   trisa=0x00;
   
    blink=0;blink_led1=0;blink_led2=0;blink_led3=0;blink_led4=0;blink_led5=0;blink_led6=0;led_off=0;
   count_display=20;
  led1=1;
   led2=2;
   led3=3;
   led4=4;
   led5=5;
   led6=8;
 
   while(1)
   {
   
      display();
   }
}


void send595(int8 temp) {
int8 i;
for(i=0;i<8;i++)
 {
  if((temp&0x80)!=0)
  output_high(data);    //bit 1
  else  output_low(data);   //bit 0
 delay_cycles(1);
  output_high(clk);
  delay_cycles(1);
  output_low(clk);
  temp=temp<<1;
 }
}

void latch(void)
{delay_cycles(1);
output_high(latch595);
delay_cycles(1);
output_low(latch595);
}


void display(){
      TRISB=0X00;TRISA=0X00;
      if(blink==0)goto normal;
      if(led_off==1) goto blink_off;
////////////////////////////////////////////////////////////////////////////////
normal:                             //////////NORMAL MODE//////////////////////
   PortB=led7ac[led1]; send595(0x01);latch();//on
   delay_ms(4); send595(0x00);latch();//off

   PortB=led7ac[led2]; send595(0x02);latch();//on
   delay_ms(4); send595(0x00);latch();//off

   PortB=led7ac[led3]; send595(0x04);latch();//on
   delay_ms(4);send595(0x00);latch();//off

   PortB=led7ac[led4]; send595(0x08);latch();//on
   delay_ms(4); send595(0x00);latch();//off

   PortB=led7ac[led5]; send595(0x10);latch();//on
   delay_ms(4); send595(0x00);latch();RA1=0;//off

   PortB=led7ac[led6]; send595(0x20);latch();
   delay_ms(4); send595(0x00);latch();//off

////////////////////////////////////////////////////////////////////////////////
if(count_display!=0) goto exit_display;
else{
      count_display=20;
      led_off=1;
    }
goto exit_display;
////////////////////////////////////////////////////////////////////////////////
blink_off:                          ///////////BLINK MODE//////////////////////

   PortB=led7ac[led1];
   if(blink_led1==1) {send595(0x00);latch();}//off if blink
   else {send595(0x01);latch();}//on if not
   delay_ms(4); send595(0x00);latch();//off

   PortB=led7ac[led2];
   if(blink_led2==1) {send595(0x00);latch();}//off if blink
   else {send595(0x02);latch();}
   delay_ms(4); send595(0x00);latch();//off

   PortB=led7ac[led3];
   if(blink_led3==1) {send595(0x00);latch();}//off if blink
   else {send595(0x04);latch();}//on if not
   delay_ms(4); send595(0x00);latch();//off

   PortB=led7ac[led4];
   if(blink_led4==1) {send595(0x00);latch();}//off if blink
   else {send595(0x08);latch();}
   delay_ms(4); send595(0x00);latch();//off

   PortB=led7ac[led5];
   if(blink_led5==1) {send595(0x00);latch();}//off if blink
   else {send595(0x10);latch();}//on if not
   delay_ms(4); send595(0x00);latch();//off

   PortB=led7ac[led6];
   if(blink_led6==1) {send595(0x00);latch();}//off if blink
   else {send595(0x20);latch();}
   delay_ms(4); send595(0x00);latch();//off

if(count_display==0){count_display=20;led_off=0;}

exit_display:
            count_display--;
       
}


I did some test. But it did not work. PLz help me


Last edited by HTAluvBeBeo on Sun May 11, 2008 9:42 am; edited 4 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 09, 2008 12:51 pm     Reply with quote

Use the CCS driver for the 74595:
Quote:
c:\program files\picc\drivers\74595.c


Example of how to use the driver:
Quote:
c:\program files\picc\examples\ex_expio.c


Topics on this forum that discuss how to use the driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=22789
http://www.ccsinfo.com/forum/viewtopic.php?t=28930
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Fri May 09, 2008 3:09 pm     Reply with quote

I am not allowed to use code library from ccs. It is a requirement of this project :( Poor me
Could you check my code please. That is only a couple of lines
THX so much
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 09, 2008 3:59 pm     Reply with quote

Quote:

#define data ra0 // pin 14
#define latch ra1 // pin 12
#define clk ra2 // pin 11

What is "ra0" ? That's not a CCS pin number.
You should use the pin constants listed in the 16F877A.H file.
Example:
Code:
#define DATA  PIN_A0
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri May 09, 2008 4:13 pm     Reply with quote

Code:
   trisa=0x00;
The CCS compiler has several modes for handling the I/O pins, default is standard_io mode. Read the CCS manual chapter on '#use standard_io' for more info on how this affects the TRIS register.

How did you connect the 74595 pins OE (13) and SCLR (10) ?
Which 74xx family are you using? LS, HC, HCT, etc?

What is the maximum clock frequency for this chip?
How many instructions per second does a 20MHz PIC perform?
From the answers to the above questions my guess is you can do with a lot less delay instructions.

Hint: check the logic level for the latch signal.
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Fri May 09, 2008 8:32 pm     Reply with quote

PCM: I wrote a definition file .h to define PINs of PIC
.............
#bit RA5 =0x05.5
#bit RA4 =0x05.4
#bit RA3 =0x05.3
#bit RA2 =0x05.2
#bit RA1 =0x05.1
#bit RA0 =0x05.0
..............
@Ckielstra:

OE is connected to gnd
SCLR is pulled up with 4k7 R
I am using 74HC595

Max F for the chip is 20Mhz
instruction for PIc : 5MHz
So I can remove many delay function

THX so much
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri May 09, 2008 8:54 pm     Reply with quote

HTAluvBeBeo wrote:
PCM: I wrote a definition file .h to define PINs of PIC
.............
#bit RA5 =0x05.5
#bit RA4 =0x05.4
#bit RA3 =0x05.3
#bit RA2 =0x05.2
#bit RA1 =0x05.1
#bit RA0 =0x05.0
These pin definitions are not compatible with the CCS output functions!!!

There are two methods to set an output:
1) as PCM suggested
Code:
#define DATA  PIN_A0
output_high(DATA);


2) or using your defines
Code:
#bit RA0 =0x05.0
#define DATA RA0 // pin 14
DATA = 1;

Mixing both methods will not work!

Both methods result in the same efficient assembly code being generated. Method 1 has the advantage that it is very easy to change your code to another processor as the required port address is not hard coded, you only have to change the processor include file.
HTAluvBeBeo



Joined: 23 Feb 2008
Posts: 35

View user's profile Send private message

PostPosted: Fri May 09, 2008 9:40 pm     Reply with quote

Thank you so so so much. You point out the right problem. I stimulated with proteus. It seems work well.
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