avr1083
Newbie level 3
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:
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]