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

cascade three 74hc595 with pic16f877a

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



Joined: 05 Dec 2004
Posts: 31

View user's profile Send private message

cascade three 74hc595 with pic16f877a
PostPosted: Wed Oct 03, 2018 8:00 pm     Reply with quote

I have three 74hc595d cascade with pic16f877a. The circuit part with 74hc595 is test with Arduino and is ok. The code is as follows:
Code:

#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=16000000)

void shiftOut(unsigned char val)
{
char j;

for(j = 0x80; j > 0; j = j >> 1)
 {
  if(val & j)
    output_high(pin_e0); // data pin
  else
    output_low(pin_e0);
 }

output_high(pin_e2);  //clock pin
output_low(pin_e2);
}


void main() {
int8 h;
int8 p;
int8 u;
int32 d=70000;

h=(char)((0xff0000 & d)>>16);
 
p=(char)((0x00ff00&d)>>8);

u=(char)(0x0000ff &d);

output_low(pin_e1); // latch pin
shiftout(h);
shiftout(p);
shiftout(u);
output_high(pin_e1);

while(1);
}


The problem is the result is not as expected. Can someone help me !!
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Oct 04, 2018 1:15 am     Reply with quote

Why not just use the supplied 74595 driver. Just define your pins, tell it you have three 595's (#define NUMBER_OF_74594 3), and the work is all done.

Your maths for the values to output seems 'odd'.
Why % 70000?.

FF0000 % 70000 will give 0xc9E0. Shifting this right 16, gives 0.

If you just want the bytes from the values, why not just use make8, or a union?.
lgeorge123



Joined: 05 Dec 2004
Posts: 31

View user's profile Send private message

cascade three 74hc595 with pic16f877a
PostPosted: Thu Oct 04, 2018 2:58 am     Reply with quote

I change the code as follows:

Code:
#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=16000000)
#include <74595.c>
#define EXP_OUT_ENABLE  PIN_E1
#define EXP_OUT_CLOCK   PIN_E2
#define EXP_OUT_DO      PIN_E0 
#define NUMBER_OF_74595 3
void main() {
int8 h;
int8 p;
int8 u;
int32 d=70000;
set_tris_e(0x00);
h=make8(d,0);
p=make8(d,1);
u=make8(d,2);
write_expanded_outputs(&h);
write_expanded_outputs(&p);
write_expanded_outputs(&u);

 

while(1);
}


the result is still not as expected .........
lgeorge123



Joined: 05 Dec 2004
Posts: 31

View user's profile Send private message

cascade three 74hc595 with pic16f877a
PostPosted: Thu Oct 04, 2018 3:12 am     Reply with quote

What I want to do is show 70000 as binary digit in three 74hc595 IC
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Oct 04, 2018 3:17 am     Reply with quote

He is not showing 70000, but I repeat my question of why he is using this value to get a remainder from the bytes he passes. It means he will get screwy values and I suspect this is the real reason the values aren't as expected....

For his first value it is almost always going to give 0, since only a number between 65536, and 70000 can actually give a bit in the 3rd byte, and this is only ever going to give a value of 0 or 1 to this chip.

Looks mathematically completely wrong....
lgeorge123



Joined: 05 Dec 2004
Posts: 31

View user's profile Send private message

cascade three 74hc595 with pic16f877a
PostPosted: Thu Oct 04, 2018 3:34 am     Reply with quote

Sorry , my d value in ccs c language is int32;
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Oct 04, 2018 5:33 am     Reply with quote

shouldn't the defines for the 74595 vars BEFORE the driver gets loaded ?
I'm thinking (with a 24hr headache) that the data is being sent to the pins the driver defaults to B0,B1,B2 not the E0,E1,E2 ??
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Oct 04, 2018 7:42 am     Reply with quote

You'd be expecting 0b00000001 on the top chip, 0b00010001 on the second, and 0b0111000 on the third.

And Temtronc is right you _must_ define the settings before you load the driver.
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Oct 04, 2018 7:54 am     Reply with quote

How it needs to be done:

Code:

#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=16000000)

#define EXP_OUT_ENABLE  PIN_E1
#define EXP_OUT_CLOCK   PIN_E2
#define EXP_OUT_DO      PIN_E0
#define NUMBER_OF_74595 3

#include <74595.c>

void main() 
{
   int32 d=70000;
   set_tris_e(0x00);

   write_expanded_outputs((int8 *)&d);
   //This automatically sends three bytes from d.
   //Since value is stored LSB first, this sends the low three bytes

   while(1)
      ;
}


The single call updates all three chips.
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