8x8 led matrix control using 74hc595 and cd4017

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

/*
 * free_lance_2.c
 *
 * Created: 23-05-2020 11:23:32
 *  Author: Chirag Goyal
 */ 

#include <avr/io.h>
#define F_CPU 16000000UL
#include<util/delay.h>
#define reg_port PORTD
#define reg_data PD7
#define reg_clock PD1
#define reg_latch PD5
#define data_high() (reg_port|=(1<<reg_data))
#define data_low() (reg_port&=~(1<<reg_data))
#define cd_en PD2
#define cd_clk PD3
#define cd_rst PD4


void reg_pulse()		//to pulse the shift register
{
	reg_port|=(1<<reg_clock);
	reg_port&=~(1<<reg_clock);
}

void reg_store()		//to store the data
{
	reg_port|=(1<<reg_latch);
	_delay_ms(1);
	reg_port&=~(1<<reg_latch);
	_delay_ms(1);
}


void counter_init()
{
	reg_port&=~(1<<cd_en);
	reg_port&=~(1<<cd_rst);
}

void reg_write(unsigned char x)
{
	
	for(unsigned char i=0;i<8;i++)
	{
		if(x&0b10000000)
			data_high();
		else
			data_low();
		reg_pulse();
		x=x<<1;
	}
	reg_store();
}
void counter()
{
	reg_port|=(1<<cd_clk);
	_delay_ms(1);
	reg_port&=~(1<<cd_clk);
	//_delay_ms(1);
	
}
int main(void)
{
	DDRD=0xff;
	unsigned char ch[8]={0b00000001,0b00000010,0b00000100,0b00001000,0b00010000,0b00100000,0b01000000,0b10000000};
	counter_init();
    while(1)
    {
        //TODO:: Please write your application code 
		
		for(unsigned char j=0;j<8;j++)
		{
			//for(unsigned char k=0;k<48;k++)
			{
				reg_write(ch[j]);
				counter();
				//_delay_ms(1);
			}	
		}	
    }
}

I've written this code for controlling led matrix using shift register for sending data and decade counter for iteration of columns. The problem is that the 8th column(MSB) is displaying all leds on. Please have a look and give some suggestions, I've very less experience of AVR

Attachment(s): 

Chirag Goyal

Last Edited: Sat. May 23, 2020 - 10:16 PM