8x8 led matrix control using 74hc595 and cd4017

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've code shift register and decade counter to display a 8x8 led matrix. The bits seem to be off by 1 bit, e.g I expect them to go from row-1, column-1 to r-2,c-2 but the mid part, i.e. r-1,c-2 is also lighting.

/*
 * 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
#define del 1

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(del);
	reg_port&=~(1<<reg_latch);
	_delay_ms(del);
}


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(del);
	reg_port&=~(1<<cd_clk);
	//_delay_ms(del);
	
}

int main(void)
{
	DDRD=0xff;
	unsigned char c[8]={0b00000000,0b11111101,0b11111011,0b11110111,0b11101111,0b11011111,0b10111111,0b00000000};
	unsigned char d[8]={0b00000000,0b11111101,0b11111011,0b11110111,0b11110111,0b11111011,0b11111101,0b00000000};
	
	counter_init();
    while(1)
    {
        //TODO:: Please write your application code 
		

		for(unsigned char k=0;k<48;k++)
		for(unsigned char j=0;j<8;j++)
		{
			reg_write(c[j]);
			counter();
			//_delay_ms(1);
		}
		
		for(unsigned char k=0;k<48;k++)
		for(unsigned char j=0;j<8;j++)
		{
			reg_write(d[j]);
			counter();
			//_delay_ms(1);
		}
    }
}

In the attachments, I've printed N and M.

Attachment(s): 

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't start new threads about the same thing please.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the display is scrolling and you're pausing the simulation with incomplete frames displayed.

 

Rather than using Q8 on the 4017 to reset the counter, explicitly reset the counter before each frame with a pulse on PD4.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I made an LED text scroll like you described. 

 

First I bought a four unit 8x8 LED matrix like this one on eBay for about $10 USD: https://www.ebay.com/itm/MAX7219...

 

Each of the four PCBs has its own MAX7219 controller IC directly under the 8x8 LED matrix unit.  The four units all have their Vcc, GND, CS, and CLK lines connected together and the DataOut of each unit is connected (on the single PCB) to the DataIn of the next unit.

 

I use an Arduino Nano to drive the three lines that go into the MAX7219[data, CS, CLK].  I use the library "MD MAX7219"  [Mad Max]  found on GitHub.  To get this library working correctly with this 8x8x4 LED board, I had to change the display type to FC-16.   This is described in detail in the documentation written into the .h file of the library.  Now it runs the "Daft Punk" demo without problems.

 

Sure, this is a "cookie cutter" solution.  But I still had to spend a long time studying the library code, the MAX7219 datasheet, and any-and-all schematics that I could find on Google.   Using a standardized eBay 8x8x4 unit with a standardized Arduino library, along with needed code modifications is by far the easiest way to get a scrolling text display working. 

Last Edited: Sun. May 24, 2020 - 01:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm with #3 - as soon as you update the latch you then clock the counter. If this was a real circuit, you'd see ghosting. To avoid this, you have to 

1. load the shift register with new data

2. turn off all columns

3. update the latch

4. select new column

5. delay

rinse and repeat.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry about that. Some views and no reply made me think it was because of the community it was posted on

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will try that. Thank you

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I get the idea of what you're saying. How to turn off all columns?

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How were you circulating columns in that project?

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried using the enable. But the thing is enable turns off logic, and the output still remains working. I need to stop the output of counter to do  what you are saying. Any suggestions on how to do that would be appreciated. Thank you

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have solved the issue by turning off shift register (output data 255) and then shifting clock. Thank you guys for advice.

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

connect the hc595 oe (pin 13) to the avr.

 

Note: this circuit wouldn't work too well in the real world - the current drive of 4000 series cmos is poor and the HC595 is only a little better. You'd be better off using the port pins of the AVR.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is the code for avr studio5

If you are really using Studio 5, you must watch your LED sign & exit at the next train station.  RUN, not walk away from Studio 5.   Get on the next train to Studio 7 as fast as you can & never come back.    (studio 5 had many terrible problems).

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

If you are really using Studio 5, ...

 

My grumpy old AVR programmer computer laptop still uses Studio 4.  (.12)  It works.  Why 'move fast and break things'?  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've got 4.19 installed & still use it occasionally when I work on some older projects, or when V7 misbehaves...a good blast from the past

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've got 4.19 installed

4.18 here as well as AS7.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Didn't 4.19 have issues?  Isn't 4.18 the better choice for the 4.x lineage?

https://www.kanda.com/blog/microcontrollers/avr-microcontrollers/avrstudio-explored/

 

Disclaimer:  I'm not a user

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's not working on hardware. Are you suggesting that I should connect OE to Atmega, should I connect Reset as well?

 

Also, is there any alternative for this so I don't have to change hardware?

 

Thank you

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Noted. Will look into it. I'm not facing any problems now so I'll stay on AVR studio 5 for the moment

Chirag Goyal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

connecting reset won't be of any benefit to you. As you wrote, sending 0xFF to disable the segments is a perfectly valid method.

 

How did you come up with this bizarre hardware method anyway? Why did you not simply chain two HC595's together?

 

I think I was around 14 years old the last time I used a 4017! And that was with a NE555, some diodes and 74 series TTL to build a digital speedometer for my bike.