spi 74hc595 Cascading atmega64

I have a problem with displaying 40 values displayed on the 7 segment (40 components 74hc595 cascade link. enter image description here

Here is the date sheeto f74hc595:http://www.componentschip.com/details/Texas-Instruments/74HC595D.html


I implement my program on arduino and it works well Here is my code:

static const byte Pattern[] = {
B00010100, // 0
B00111111, // 1
B10011000, // 2
B00011010, // 3
B00110011, // 4
B01010010, // 5
B01010000, // 6
B00011111, // 7
B00010000, // 8
B00010010, // 9
B00010000}; // BLANK


byte HC595_DS_POS = 2; //Data pin (DS) pin location

byte HC595_SH_CP_POS = 3; //Shift Clock (SH_CP) pin location
byte HC595_ST_CP_POS = 4; //Store Clock (ST_CP) pin location



void IE74595_Out(uint8_t *p, unsigned char n)
{
unsigned char i, j;
uint8_t b;


digitalWrite(HC595_ST_CP_POS,0);
digitalWrite(HC595_SH_CP_POS,0);


for(j=0;j<n;j++)
{
b = Pattern[*(p+n-j-1)]; // Lay byte cao nhat truoc

for(i=0;i<8;i++)
{

digitalWrite(HC595_SH_CP_POS,0);

if(b & 0b00000001)
{

digitalWrite(HC595_DS_POS,1);

}
else
{

digitalWrite(HC595_DS_POS,0);

}

digitalWrite(HC595_SH_CP_POS,1);

b=b>>1; //Now bring next bit at MSB position

}
}


digitalWrite(HC595_ST_CP_POS,1);

}



void setup()
{
// put your setup code here, to run once:
pinMode(HC595_ST_CP_POS, OUTPUT);
pinMode(HC595_SH_CP_POS, OUTPUT);
pinMode(HC595_DS_POS, OUTPUT);

}

void loop() {

uint8_t Data[40]={2,5,1,3,2,1,3,6,1,9,4,8,1,7,0,5,1,2,5,6,5,4,1,4,1,8,1,3,1,9,5,6,4,5,6,2,6,1,0,2};


IE74595_Out(Data,40);


}

And then I remade another program on atmel studio and I load it via extrem burner and Usbasp in my card Here is my code :

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

static const uint8_t Pattern[] = {
0b00010100, // 0
0b00111111, // 1
0b10011000, // 2
0b00011010, // 3
0b00110011, // 4
0b01010010, // 5
0b01010000, // 6
0b00011111, // 7
0b00010000, // 8
0b00010010, // 9
0b00010000}; // BLANK

#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)

#define HC595_DS_POS PC4 //Data pin (DS) pin location
#define HC595_SH_CP_POS PC5 //Shift Clock (SH_CP) pin location
#define HC595_ST_CP_POS PC6 //Store Clock (ST_CP) pin location



#define HC595_PORT PORTC
#define HC595_DDR DDRC


void IE74595_Out(uint8_t *p, unsigned char n)
{
unsigned char i, j;
uint8_t b;

output_low(HC595_PORT,HC595_ST_CP_POS);
Topic archived. No new replies allowed.