___________________________________________________________________________________________________
________________________________________________________________________________________________ Content for the tab VIDEO
Click Here: Depth understanding of SPI Protocol
1. Circuit of spi interfacing with ATmega16 using MAX7221
1. Program of spi interfacing with ATmega16 using MAX7221
/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- ATMEGA16 CONTROL MAX7221 USING SPI
PROTOCOL AND ACCORDING MAX7221 CONTROL 8 7-SEGMENT DISPLAYS
******************************************************/
#include<avr/io.h>
#include<util/delay.h>
#define MOSI 5
#define SCK 7
#define SS 4
int ar[10]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f };
int ar1[8]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
void spi_ini();
spi_tr(unsigned char cmd,unsigned char data);
void main()
{
int i,a,b,c,d,e,f,g,h;
spi_ini();
a=b=c=d=e=f=g=h=0;
//spi_tr(0x09,0b00000010);
spi_tr(0x0a,0xf);
spi_tr(0x0b,0xf);
for(i=0;i<9;i++)
{
spi_tr(ar1[i],ar[0]);
_delay_ms(100);
}
spi_tr(0x0c,0x01);
while(1)
{
spi_tr(ar1[7],ar[a]);
spi_tr(ar1[6],ar[b]);
spi_tr(ar1[5],ar[c]);
spi_tr(ar1[4],ar[d]);
spi_tr(ar1[3],ar[e]);
spi_tr(ar1[2],ar[f]);
spi_tr(ar1[1],ar[g]);
spi_tr(ar1[0],ar[h]);
a++;
if(a==10)
{
a=0;
b++;
}
if(b==10)
{
a=b=0;
c++;
}
if(c==10)
{
a=b=c=0;
d++;
}
if(d==10)
{
a=b=c=d=0;
e++;
}
if(e==10)
{
a=b=c=d=e=0;
f++;
}
if(f==10)
{
a=b=c=d=e=f=0;
g++;
}
if(g==10)
{
a=b=c=d=e=f=g=0;
h++;
}
if(h==10)
{
a=b=c=d=e=f=g=h=0;
}
_delay_ms(3000);
}
}
void spi_ini()
{
DDRB|=(1<<MOSI)|(1<<SCK)|(1<<SS); // make output pin for spi
SPCR|=(1<<MSTR)|(1<<SPE)|(1<<SPR1); // enable spi in master mode
}
spi_tr(unsigned char cmd,unsigned char data)
{
PORTB &=~(1<<SS); //enable transmission
SPDR=cmd; // start transmission
while(!(SPSR&(1<<SPIF))); // wait for complete transmission
SPDR=data; // start trasmission
while(!(SPSR&(1<<SPIF))); // wait for transmission
PORTB |=(1<<SS); // disable transmission
}
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)