Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Problam MAX7219 to avr

Status
Not open for further replies.

avr1083

Newbie level 3
Newbie level 3
Joined
Jun 12, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
Hi,

I want to control 7segments with a MAX7219.
using an ATmega32.

For testing i have connected only two 7 segments.

out put 7segments is on.

my code:

Code:
max2719.h

Code:
#define CLK  PORTB.5
#define DIN  PORTB.6
#define LOAD PORTB.7

void send16(unsigned int word)// SEND 16-bit
{
    char j; 
    
    CLK  = 0;
    LOAD = 0;
    
    for(j=0; j<16; j++)
    {
        DIN = word&0x8000; // send data to 7219
        CLK =1;            // pulse CLK
        CLK =0;
        word <<= 1;          // shift left one bit
    } 
    
    LOAD =1;               // pulse LOAD
    LOAD =0;
}



Code:
#define DIG0                    0b0000000100000000
#define DIG1                    0b0000001000000000
#define DIG2                    0b0000001100000000
#define DIG3                    0b0000010000000000
#define DECODEMODE              0b0000100100000000
#define INTENSITY               0b0000101000000000
#define SCANLIMIT               0b0000101100000011
#define POWERON                 0b0000110000000001
#define POWEROFF                0b0000110000000000
#define TESTON                  0b0000111100000001
#define TESTOFF                 0b0000111100000000


Code:
void main ( void ) 
{    
    PORTB = 0x00;
    DDRB = 0xFF;
    
    init7219();
    
    while(1)
        {
		            update7219();
        }
}

void init7219(void )
{
send16(POWERON);
send16(DECODEMODE);
send16(TESTOFF); /* disable test mode */
}

void update7219(void )
{
send16(POWERON);//Send power on command
send16(DIG0 | returnletter(2));//print '2' to digit 0
send16(INTENSITY | 0x0F);//Put on FULL intensity "1111" 
}


Code:
unsigned char returnletter(unsigned char letter)
{
  switch (letter)
	{
	      case 0: 
                    return 0b01111110;
          break;
          
          case 1: 
                    return 0b00110000;
          break; 
          
          case 2: 
                    return 0b01101101;
          break;
          
          case 3: 
                    return 0b01111001;
          break;
          
          case 4: 
                    return 0b00110011;
          break;   
          
          case 5: 
                    return 0b01011011;
          break; 
          
          // and so on… for all characters…
          default:  
                    return 0b00000000;
          break;
	}
}[ATTACH]121000._xfImport[/ATTACH][ATTACH]120999._xfImport[/ATTACH]
 

Hi,

Why don´t you use the M32 built in SPI periferal?

***
The MAX7219 has a CS* pin. Is that your "LOAD"?
If so, then you misunderstood the function. It should be all the time high (idle).
Before starting communication you set it low.
After communcation is finished you set it high(Idle).
--> No need to set it low again. In the datatsheet you see the low pulse only to specify the min. idle time before a new communication is started.
***

DIN = word&0x8000
I don´t know if this works. The result is a 16 bit value. But DIN is a boolean value. But i´m not familiar with the C expressions.

***
Code:
    while(1)
        {
		            update7219();
        }
}
This means the display is continously updateed without the change to "breath". You know what i mean. An update ever 300ms is enough. So a "wait for 300ms" between two updates is a good idea.

***
#define INTENSITY 0b0000101000000000
This sets minimum brightness. Maybe this is too low. Check on this.

***
#define SCANLIMIT 0b0000101100000011
This sets 4 digits to be updatet, but you say you have only two digits. Check on this.

***
send16(DIG0 | returnletter(2));//print '2' to digit 0
send16(INTENSITY | 0x0F);//Put on FULL intensity "1111"
"INTENSITY" is a 16 bit value, but "0x0F" is an 8 bit value. Is this correct C code?
The same is with "DIG0" and "returnletter(2)"

***
Please edit you post, because your attachment is within the "code" tags

***

Klaus
 
  • Like
Reactions: avr1083

    avr1083

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top