Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC16F877A interface with shift register 74HC595 and led

Status
Not open for further replies.
Hi,
I don't know C++, but check your compiler manual, it's sure to have some functions for SPI operation like the SPI_Write() or SPI_Read() in mikroC. Use that and read through the relevant section in the PIC reference manual and datasheet.

Hope this helps.
Tahmid.
 

Hi,
I don't know C++, but check your compiler manual, it's sure to have some functions for SPI operation like the SPI_Write() or SPI_Read() in mikroC. Use that and read through the relevant section in the PIC reference manual and datasheet.

Hope this helps.
Tahmid.

i try many times but can't get~
can you show me the full coding for SPI code based on my requirement and some explanation aside??if using SPI code need to compile by using SPI software?
really headache on it~

---------- Post added at 18:57 ---------- Previous post was at 17:57 ----------

Hi,
bsf means bit set f
bsf portd,0
means set bit 0 of portd

For SPI, take a look at my above post and the datasheet and reference manual for the PIC.

Hope this helps.
Tahmid.

i have 16 led..how i assign my bit number??
 

what about basic stamp? I thought the programming was so easy...
 

basic stamp is a microcontroller and everything is included on one board. Basic language is so easy to learn and program.
 

Basic Stamp is a microcontroller with peripherals on board programmed by BASIC language, but is very slow.

I prefer using a PIC or AVR and programming it with mikroBASIC, which would let me utilize everything without making everything slow.

eg BS2SX-IC give 10kIPS operation at 50MHz clock, whereas with an ATMEGA88 I could get 20000kIPS at 20MHz clock.

Hope this helps.
Tahmid.
 

//include file
#include <pic.h>
#include "delay.h"

//16F877A configuration
__CONFIG(0x3f71);

#define PORTDIT(adr, bit) ((unsigned)(&adr)*8+(bit))

#define SHIFT_DELAY 50

#define CLK RD0
#define DATA RD1
#define RCK RD2

static bit LED0 @ PORTDIT(PORTD, 0);
static bit LED1 @ PORTDIT(PORTD, 1);
static bit LED2 @ PORTDIT(PORTD, 2);
static bit LED3 @ PORTDIT(PORTD, 3);
static bit LED4 @ PORTDIT(PORTD, 4);
static bit LED5 @ PORTDIT(PORTD, 5);
static bit LED6 @ PORTDIT(PORTD, 6);
static bit LED7 @ PORTDIT(PORTD, 7);

unsigned int i; //for loop pause
unsigned int c; //for loop event loop

//pause functions
void pause_1();
void pause_2();

//main function
void main(void)
{
unsigned char data = 0b00000001;

TRISD = 0x00;
PORTD = 0b00000000;

while(1)
{
for ( c = 0; c < 8; ++c )
{
DATA = ( ( data & ( 1 << c ) ) != 0 );
DelayMs ( SHIFT_DELAY );
CLK = 1;
DelayMs ( SHIFT_DELAY );
CLK = 0;
DelayMs ( SHIFT_DELAY );

RCK = 1;
DelayMs ( SHIFT_DELAY );
RCK = 0;
DelayMs ( SHIFT_DELAY );
}

/*
for(c=0; c<10; c++)
{


//forward
LED0 = 1;
pause_1();

LED0 = 0;
LED1 = 1;
pause_1();

LED1 = 0;
LED2 = 1;
pause_1();

LED2 = 0;
LED3 = 1;
pause_1();

LED3 = 0;
LED4 = 1;
pause_1();

LED4 = 0;
LED5 = 1;
pause_1();

LED5 = 0;
LED6 = 1;
pause_1();

LED6 = 0;
LED7 = 1;
pause_1();

LED7 = 0;



};


};*/

}

}

void pause_1()
{

for(i=0; i<4000; i++);
for(i=0; i<4000; i++);

};

void pause_2()
{

for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);

};


above is my source code include 595 code~i refer reference book to write but the expla nation of book is not detail.
i have some question:
1)((unsigned)(&adr)*8+(bit))<<<<<<<<<<this is means what?
2) #define SHIFT_DELAY 50<<<<<<<<<<the shift_delay is means what?
3)static bit LED0 @ PORTDIT(PORTD, 0);<<<the static bit is means what?
4)i)void pause_1();<<<<<<<<<<<<<this is means what?
  ii)void pause_2();<<<<<<<<<<<<can i exclude this code?just  put 4)i)code?
5)unsigned char data = 0b00000001;<<<<<this is means what?
6)TRISD = 0x00;<<<<<<<<<<<<<<<<this is means what?
  PORTD = 0b00000000;<<<<<<<<<<<<this is means what?
7)for ( c = 0; c < 8; ++c )<<<<<<<<<<<why need to loop 7 times?
8)DATA = ( ( data & ( 1 << c ) ) != 0 );<<<<this is means what?
9)if i want to change the pattern of displaying le d,which part of code should i change?


latch in shift register 595 is means what?
thanks~

---------- Post added at 04:55 ---------- Previous post was at 04:30 ----------

//include file
#include <pic.h>
#include "delay.h"

//16F877A configuration
__CONFIG(0x3f71);

#define PORTDIT(adr, bit) ((unsigned)(&adr)*8+(bit))

#define SHIFT_DELAY 50

#define CLK RD0
#define DATA RD1
#define RCK RD2

static bit LED0 @ PORTDIT(PORTD, 0);
static bit LED1 @ PORTDIT(PORTD, 1);
static bit LED2 @ PORTDIT(PORTD, 2);
static bit LED3 @ PORTDIT(PORTD, 3);
static bit LED4 @ PORTDIT(PORTD, 4);
static bit LED5 @ PORTDIT(PORTD, 5);
static bit LED6 @ PORTDIT(PORTD, 6);
static bit LED7 @ PORTDIT(PORTD, 7);

unsigned int i; //for loop pause
unsigned int c; //for loop event loop

//pause functions
void pause_1();
void pause_2();

//main function
void main(void)
{
unsigned char data = 0b00000001;

TRISD = 0x00;
PORTD = 0b00000000;

while(1)
{
for ( c = 0; c < 8; ++c )
{
DATA = ( ( data & ( 1 << c ) ) != 0 );
DelayMs ( SHIFT_DELAY );
CLK = 1;
DelayMs ( SHIFT_DELAY );
CLK = 0;
DelayMs ( SHIFT_DELAY );

RCK = 1;
DelayMs ( SHIFT_DELAY );
RCK = 0;
DelayMs ( SHIFT_DELAY );
}

/*
for(c=0; c<10; c++)
{


//forward
LED0 = 1;
pause_1();

LED0 = 0;
LED1 = 1;
pause_1();

LED1 = 0;
LED2 = 1;
pause_1();

LED2 = 0;
LED3 = 1;
pause_1();

LED3 = 0;
LED4 = 1;
pause_1();

LED4 = 0;
LED5 = 1;
pause_1();

LED5 = 0;
LED6 = 1;
pause_1();

LED6 = 0;
LED7 = 1;
pause_1();

LED7 = 0;



};


};*/

}

}

void pause_1()
{

for(i=0; i<4000; i++);
for(i=0; i<4000; i++);

};

void pause_2()
{

for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);
for(i=0; i<4000; i++);

};


above is my source code include 595 code~i refer reference book to write but the expla nation of book is not detail.
i have some question:
1)((unsigned)(&adr)*8+(bit))<<<<<<<<<<this is means what?
2) #define SHIFT_DELAY 50<<<<<<<<<<the shift_delay is means what?
3)static bit LED0 @ PORTDIT(PORTD, 0);<<<the static bit is means what?
4)i)void pause_1();<<<<<<<<<<<<<this is means what?
  ii)void pause_2();<<<<<<<<<<<<can i exclude this code?just  put 4)i)code?
5)unsigned char data = 0b00000001;<<<<<this is means what?
6)TRISD = 0x00;<<<<<<<<<<<<<<<<this is means what?
  PORTD = 0b00000000;<<<<<<<<<<<<this is means what?
7)for ( c = 0; c < 8; ++c )<<<<<<<<<<<why need to loop 8 times?
8)DATA = ( ( data & ( 1 << c ) ) != 0 );<<<<this is means what?
9) void pause_1(), void pause_2()<<this is what?
10 )for(i=0; i<4000; i++);<<why need to loop 4000 times?
11)if i want to change the pattern of displaying led,which part of code should i change?how to change?


latch in shift register 595 is means what?
thanks~
 

There is no such thing as C++ for PIC uC, and in your code that you posted, I can't see any mention of 595 shift register. For 595's you only need 3 pins: one for serial data, one for serial clock, and one for strobe (assuming that you keep your 595's constantly enabled).

---------- Post added at 20:15 ---------- Previous post was at 20:12 ----------

latch in shift register 595 is means what?
thanks~

Read the datasheet for 595.

Writing software without understanding how hardware function is useless wasting of time. Bette to "waste time" reading datasheets and educating yourself
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top