8 x 8 led matrix to show flowing output

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

I have started learning atmega16 a week ago and have learnt some basic info and am able to make basic programs like creating a library, printing letters on 8x8 led matrix. I want to make a project which shows the word in a flowing manner like in the train stations screen, the word coming from right and ending on left. I am able to get somewhat OK output just wanted to make it more optimised, efficient.

 

Here is the code for avr studio 5:

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

void main()
{
    DDRA=0xff;
    DDRB=0xff;
    DDRC=0xff;
    DDRD=0xff;
    unsigned char c[]={0b11111111,0b11111111,0b01111110,0b01111110,0b01111110,0b01111110,0b01111110,0b00000000};
    unsigned char h[]={0b11111111,0b11111111,0b00000000,0b11101111,0b11101111,0b11101111,0b11101111,0b00000000};
    unsigned char in[]={0b11111111,0b11111111,0b11111111,0b00000000,0b11111111,0b11111111,0b11111111,0b11111111};
    unsigned char r[]={0b11111111,0b11111001,0b01110110,0b10110110,0b11010110,0b11100110,0b00000000,0b11111111};
    unsigned char an[]={0b11111111,0b11111111,0b00000001,0b11101110,0b11101110,0b11101110,0b11101110,0b00000001};
    unsigned char g[]={0b11111111,0b11111111,0b00001110,0b01101110,0b01101110,0b01111110,0b01111110,0b10000001};
    
    
    while(1)
    {
        for(int a=-7;a<48;a++)
        for(int j=0;j<8;j++)
        {
            PORTA=(0b10000000>>j+a);
            PORTB=c[j];
            _delay_ms(1);
            
            PORTC=(0b10000000>>j+a);
            PORTD=c[j+8];
            _delay_ms(1);
        
            
            PORTA=(0b10000000>>j+a-8);
            PORTB=h[j];
            _delay_ms(1);
            
            PORTC=(0b10000000>>j+a-8);
            PORTD=h[j+8];
            _delay_ms(1);
        
        
            PORTA=(0b10000000>>j+a-16);
            PORTB=in[j];
            _delay_ms(1);
        
            PORTC=(0b10000000>>j+a-16);
            PORTD=in[j+8];
            _delay_ms(1);
        
        
            PORTA=(0b10000000>>j+a-24);
            PORTB=r[j];
            _delay_ms(1);
        
             PORTC=(0b10000000>>j+a-24);
            PORTD=r[j+8];
            _delay_ms(1);
        
        
            PORTA=(0b10000000>>j+a-32);
            PORTB=an[j];
            _delay_ms(1);
            
            PORTC=(0b10000000>>j+a-32);
            PORTD=an[j+8];
            _delay_ms(1);
        
            
            PORTA=(0b10000000>>j+a-40);
            PORTB=g[j];
            _delay_ms(1);
            
            PORTC=(0b10000000>>j+a-40);
            PORTD=g[j+8];
            _delay_ms(1);
        
        }        
    }
}

Edit: A little bit extra lag is added by screen recorder. The output should be more smoother, if its possible.

Attachment(s): 

Chirag Goyal

Last Edited: Sat. May 23, 2020 - 10:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well it's a good thing your using a simulation, because if you were using real hardware you would either burn out your LED's or the port pins of your micro or both as...

you have no current limiting resistors in series with your LEDS!!!

 

check out this arduino project, you may be able to use some of the code in your project, anyway, look at how there program works and see if it makes sense to you.

https://www.instructables.com/id...

 

jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

 

PORTA=(0b10000000>>j+a-8);

I am sitting here trying to work out what on earth your code is attempting to do here. I am admitting defeat. Would you consider adding some comments to explain what the intention of each stage is? How about also using variable names other than 'a', 'j' thta explain a little more about what the use of the variable is. C doen't mind you using names like character_counter or whatever the variable is being used for and it can (with the comments) make the code clearer to follow. Also this very line I've quote has got me rushing off to my C manual to try and remind myself of C operator precedence. I get the fact that a may be added to j before 8 is subtracted from the at what about that >>. Are we saying the binary constant is shifted by j fir or is it even shifted by (J + a - 8) ??

EDIT: OK, so if I read this right:

 

 

the the addition/subtraction are of a higher precedence than the right shift. So it's really:

(0b10000000 >> (j + a - 8));

So 'j' and 'a' are added then 8 subtracted and THEN this is used to shift the bit pattern. Still don't really understand the significance of 'j' and 'a' though

 

EDIT2:

       for(int j=0;j<8;j++)

OK so 'j' is a "bit shift"? But:

       for(int a=-7;a<48;a++)

so what is 'a' here. It's a "bit counter" or something ? Isn't there a case when a=-7 and j=0 that you are asking for a >> -15 then (also including the -8). Exactly what does a right shift of -15 look like??

Last Edited: Mon. Jun 17, 2019 - 04:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I first tried to write "0x00000001<<j+a" but it was giving the mirrored image. So just by method of hit and trial, I've come to this program. Also, if you'd notice I had to reverse the order of array declared for the letters. To be fair, I don't understand it fully. I have not been programming for long. I don't know the right way this could be written, so if you know anything regarding this please suggest. I'll try it and get back to you to discuss

Chirag Goyal

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

Yeah I know that. I'm a student of Electrical and Electronics Engineering. The reason is why bother with resistor on simulation.

Chirag Goyal

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

Stick to ONE thread!!

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Topic locked