Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F877A interface with shift register 74HC595 and led

Status
Not open for further replies.

cly_1018

New Member
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 that can compile in MPLAB software to display some pattern such as moving forward or backward and lighting up the led?

thanks~
 
It is not too complex. Read the 74HC595 data sheet to start. Datasheets from some vendors are better then others. There are a lot of vendors making the 595. If you still have questions come back and ask them but don't expect us to do your homework.

You said C++ which compiler are you using ? Have you used it before ?
 
i have complete my source code but after program to pic..the led just will light up but can't show the pattern~

do i need to include any 595 source code in my program??

i'm using MPLAB to compile it~
 
//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++);

};
 

Attachments

  • schematicss2.jpg
    schematicss2.jpg
    140.8 KB · Views: 1,027
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top