//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~