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.

cly_1018

Newbie level 6
Joined
Oct 24, 2010
Messages
13
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,283
Activity points
1,450
how to interfacing PIC16F877A with shift register 74HC595 and led?
i need the help on c++ source code using MPLAB~

do i need to write both source code separately:
1) source code for interfacing PIC16F877A with shift register 74HC595
2) source code for interfacing PIC16F877A with led
 

Hai,

You write source code for 74hc595 .Actually It is not difficult one.First you study about 74hc595 pin like clk,data,etc..
 
but hw to write the part of (0x01) or (0x20)?the (0x01)means what?
 
hai,

Which 0x01 or 0x20?.Is it PIC memory address? OR what?

If it is pic memory address then you start your program like

list p=pic16f877a
#include"p16f877a.inc"
cblock 0x20
; registers used in your program like,r1,r2,etc
endc
org00
then start your program
 
i'm using c++ to write

yaa...it's PIC memory address~how to determine it?

below is my program

#include<pic.h>
__CONFIG(0x3F3A)<<this (0x3F3A)means what?how should I explain to sir?

void delay();<<this delay izit time delay?
void led_show();
void clear();
void clock();<<this clock means what?
void check;<<this check can I don't put?

"3" in RED color
const int led01[5][8]{{0x00,01....}}<<this 0x00...how to write in order 2 display number of "3"?
 
hai,

void delay();<<this delay izit time delay?

ya it's time delay.

void clock();<<this clock means what?

Can you post your function content ? I think it's for your 74hc595,It has a clock pin

I am not familiar with your language I use MIkroc and MPLAB.
 
by using MPlab hw 2 write??can u gv me a guideline??
and hw to start?
 
Hai,

list p=pic16f877a
#include"p16f877a.inc"
cblock 0x20
; registers used in your program like,r1,r2,etc
endc
org00

This is for start a program
here i attach a simple program for blinking portb.You can simulate this program in PIC simulator ide. First you study About your pic registers and banks etc.
 

Attachments

  • blink.txt
    272 bytes · Views: 148
but i want to interface with PIC16F877A~interface with one 74HC595 shift register~
i need guide in source code of it~

---------- Post added at 10:56 ---------- Previous post was at 10:55 ----------

can you write the explanation aside?because i not so understand~
 
Hai,

Interfacing means
You can use 4 portb pin for connecting 74hc595.I think you have sufficient knowledge in pic (It has 4 ports,porta,b,c,and d) .

Portb 0th pin for data,1st pin for cloke,2nd pin foroutput enable and 4th pin for reset.
here i attach 74hc595 data sheet.
also i attach above program with explanation
 

Attachments

  • mc74hc595.pdf
    252 KB · Views: 214
  • blink.txt
    672 bytes · Views: 147
CBLOCK 0X20<<CBLOCK is what?
ENDC<<this means what?

---------- Post added at 12:29 ---------- Previous post was at 12:19 ----------

#INCLUDE "P16F84.INC"<< i'm using PIC16F877A~bt this is 16F84?
 
hai

CBLOCK 0X20 this means user defined registers are started from pic memory address 0x20

for example
CBLOCK 0x20
r1,r2
ENDC
Address of "r1" is 20 and r2 is 21

ENDC means register declaration completed.

#INCLUDE "P16F84.INC"
Change it
#INCLUDE "P16F877A.INC"
 

i want to interface like this:

1) no.11 pinout of shift register 595 connect with rd0 pinout of pic
2) no.14 pinout of shift register 595 connect with rd1 pinout of pic
3) no.12 pinout of shift register 595 connect with rd2 pinout of pic

how to write the source code?i still not understand how to see the memory address~
 

Hi cly_1018,
The PIC16F877A has internal SPI module. If you use it, the code will be simple, but you have to change hardware to RC1, RC3 and RC5.
If you want to stick with your current pinout, you'll have to use software SPI.

Hope this helps.
Tahmid.
 

but my hardware is using PIC16f877A and shift register of 74HC595~

i duno how to use SPI software to interface it~

i prefer assembly language that can compile in MPLAB~

can you help me?thanks..
 

hai,

11th pin of 74hc595 is data input pin

So, first you set as high all three pins

taht is

bsf portd,0
bsf portd,1 ;data
bsf portd,2

then check the changes in your led.
 

Hi,
These are the steps for writing data to an SPI device (single byte write):
1. Make CE = 1 to begin writing.
2. The 8-bit address is shifted in one bit at a time, with each edge of SCLK. Notice that A7 = 1 for write operation, and A7 bit goes in first. A7 is the 8th bit of Address through pin SDI.
3. After all 8 bits of the address are sent in, the SPI device expectws to receive the data belonging to that address location immediately.
4. The 8-bit data is shifted in one bit at a time, with each edge of the SCLK.
5. Make CE = 0 to indicate the end of the write cycle.

Example:
Code:
;Example code for SPI operation
#DEFINE   SS         PORTC.0 ;This is slave select
SPL_MS
              MOVLW  B'00010000' ;SDI INPUT, REST OUTPUT
              MOVWF  TRISC
              MOVLW   B'00110000' ;ENABLE SPI AND PINS, CLOCK POLARITY
              MOVWF   SSPCON1 ;IDLE HIGH, MASTER MODE, FOSC/4
              MOVLW   B'01000000' ;SAMPLE BIT IN MIDDLE, TRANSITION ON RISING PULSE
              MOVWF   SSPSTAT
ACCESS
              BCF         SS
              MOVLW   0X55
              MOVWF   SSPBUF
              BSF        SS
WAIT
              BRA   WAIT

END

You should take a look at the datasheet for reference.
Tahmid.
 

here are my code~in hardware part, I have 16 led that connected to shift register 595 and pic16F877A~after i burnt my coding to pic, how do i do on my hardware 2 display?need what instrument?

//include file
#include <pic.h>

//16F877A configuration
__CONFIG(0x3f71);

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

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);
static bit LED8 @ PORTDIT(PORTD, 8);
static bit LED9 @ PORTDIT(PORTD, 9);
static bit LED10 @ PORTDIT(PORTD, 10);
static bit LED11 @ PORTDIT(PORTD, 11);
static bit LED12 @ PORTDIT(PORTD, 12);
static bit LED13 @ PORTDIT(PORTD, 13);
static bit LED14 @ PORTDIT(PORTD, 14);
static bit LED15 @ PORTDIT(PORTD, 15);

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)
{

TRISD = 0x00;
PORTD = 0b00000000;

while(1)
{

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;
LED8 = 1;
pause_1();

LED8 = 0;
LED9 = 1;
pause_1();

LED9 = 0;
LED10 = 1;
pause_1();

LED10 = 0;
LED11 = 1;
pause_1();

LED11 = 0;
LED12 = 1;
pause_1();

LED12 = 0;
LED13 = 1;
pause_1();

LED13 = 0;
LED14 = 1;
pause_1();

LED14 = 0;
LED15 = 1;
pause_1();

LED15 = 0;


//reverse
LED14 = 1;
pause_1();

LED14 = 0;
LED13 = 1;
pause_1();

LED13 = 0;
LED12 = 1;
pause_1();

LED12 = 0;
LED11 = 1;
pause_1();

LED11 = 0;
LED10 = 1;
pause_1();

LED10 = 0;
LED9 = 1;
pause_1();

LED9 = 0;
LED8 = 1;
pause_1();

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

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

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

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

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

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

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

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

};

//re-initalize PORTD
PORTD = 0b00000000;

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

PORTD = 0b10101010;
pause_2();

PORTD = 0b01010101;
pause_2();

};

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

PORTD = 0b11110000;
pause_2();

PORTD = 0b00001111;
pause_2();

};

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

PORTD = 0b11001100;
pause_2();

PORTD = 0b00110011;
pause_2();

};

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

PORTD = 0b10000001;
pause_1();

PORTD = 0b01000010;
pause_1();

PORTD = 0b00100100;
pause_1();

PORTD = 0b00011000;
pause_1();

PORTD = 0b00100100;
pause_1();

PORTD = 0b01000010;
pause_1();

};

}

}

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++);

};

---------- Post added at 10:44 ---------- Previous post was at 10:40 ----------

hai,

11th pin of 74hc595 is data input pin

So, first you set as high all three pins

taht is

bsf portd,0
bsf portd,1 ;data
bsf portd,2

then check the changes in your led.

~~~~bsf is means what??

can u teach me how to write the complete source code that can generate in MPLAB?
if using SPI software how to write..thanks~
 

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.
 

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 din study SPI before..can you help me by using PORTD with c++ source code that can compile in MPLAB?

i'm using 16 led and connect with shift register 74HC595 & PIC16F877A for hardware part~how do i write my software program part using c++ code to display some pattern of lighting up the led?

thanks~
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top