kapsh
Newbie
Hello,
Greetings.
I have given a task to modify the program written by a previous employee, but as the code lacks comments and as I am not in touch with 8051 programming for long also I am not familiar with interfacing of 8052
with MAX7219, I am unable to understand that section properly. It will very helpful if any one can help me understand it. I have attached a portion of the code for your reference...
Thank you in advance.
Greetings.
I have given a task to modify the program written by a previous employee, but as the code lacks comments and as I am not in touch with 8051 programming for long also I am not familiar with interfacing of 8052
with MAX7219, I am unable to understand that section properly. It will very helpful if any one can help me understand it. I have attached a portion of the code for your reference...
Thank you in advance.
C:
#include<reg52.h>
#include<intrins.h>
void Write_Max7219_byte(unsigned char temp);
void Write_Max7219(unsigned char address,unsigned char dat);
void Init_Max7219(void);
int parameter();
/////////////////// array diclaration /////////////////
bit sin,pn,ack,calib=0,mvin=0;//mmsb =0,msb = 1,lsb = 1,
unsigned int array[11]={0Xfc,0X60,0Xda,0Xf2,0X66,0Xb6,0Xbe,0Xe0,0Xfe,0Xf6,0X00};
/////////// delay function for 1 m.s. ///////////
void delay(unsigned int time)
{
int i,j;
for(i=0;i<time;i++)
for(j=0;j<1257;j++);
}
///////// write in display ic ///////////
void Write_Max7219_byte(unsigned char temp)
{
unsigned char i;
for (i=0; i<8; i++)
{
CLK = 0;
DIN_1 = (bit)(temp& 0X80); //DIN_1 = (bit)(temp & 0X80 == 0X80 ? 1:0);
temp <<=1;
CLK = 1;
}
}
//////////////////////////////////////////////////////
void Write_Max7219(unsigned char address,unsigned char dat)
{
LOAD = 0;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
LOAD = 1;
}
/////////////////////////////////////////
void Init_Max7219(void)
{
Write_Max7219(0x0C,0x01); //Normal Operation XXXXXXX1 Shutdown Mode XXXXXXXX0
Write_Max7219(0x0F,0x00); //Normal Operation XXXXXXX0 Display Test Mode XXXXXXXX1
Write_Max7219(0x09,0x00); //Decode Mode Select D7~D0 1 B decode 0 No decode
Write_Max7219(0x0B,0x07); //SCAN LIMIT 0~7 0xX0~0xX7
Write_Max7219(0x0A,0x04); //Set Intensity 0xX0~0xXf
}
/////////////// parameter setup//////////
int parameter()
{
long int dis_value;
unsigned char spf = 0X01;
bit cb = 1,lp=0;
//////////////////////////////////// show par on to the display //
Write_Max7219(7,array[0]);
Write_Max7219(8,array[0]);
Write_Max7219(1,0x02);
Write_Max7219(2,0xce);
Write_Max7219(3,0xfa);
Write_Max7219(4,0x8c);
Write_Max7219(5,0x02);
Write_Max7219(6,0x00);
zero = 1 ;
delay (100);
while (zero == 1)
{
if (inc == 0)
{
if ( spf <= 4 )
{spf = spf + 1 ;}
else{ spf = 1;}
}
if (dec == 0)
{
if ( spf >= 1 )
{spf = spf - 1 ;}
else{ spf = 4;}
}
}
}