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.

Seeking assistance (help) to understand 8051 code

Status
Not open for further replies.

kapsh

Newbie
Joined
Apr 7, 2022
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
43
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.

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;}
            }
        }
    }
 

Hi,

It´s not clear what you want to know.
It´s also not clear what you need to modify.
Did you read the MAXxxx datasheet?

Klaus
 

Hi,
I want to understand the whole code specially related to MAX. with the help of its datasheet I am able to understand functions like Write_Max7219_byte, Init_Max7219 & Write_Max7219. But, when it comes to functions like int parameter() , I am unable to understand what each line of code specially related to MAX does.

In terms of modification, I first have to understand the whole program and then have to check to do some modification/correction/addon
 

Hi,

Example:
Write_Max7219(2,0xce);
It writes "0xCE" to address 2. While address2 is for digit1. (Table 1, Table 2)
So it writes 0xCE to digit 2.
0xCE is 0b11001110
See Table 6: It should display this:
Code:
 #####
#     .
#     .
#     .
 .....
#     .
#     .
#     .
 #####   ##

Klaus
 

Hi,
Thank you for the clarification.
But, if we go with the comment in the code, it says - // to show 'par' on the display".. but as per clarification if we check it is not displaying what it says. and that is what arise the confusion. Its just one portion of the code I have shared there few more that just increases this confusion for me. Please help me with this.

Thanks.
 

Hi,

You speak in riddles. This makes it hard - and time wasting - for us to give the answers you want to see.
* Why hiding the information what you want to modify? So we don't know what to focus on.
* Why giving vague informations like "it is not displaying what it says" instead of saying (example) "the display stays blank"
* you don't give the schematic and the PCB layout, thus we don't know how many digits really are connected, if the segments are wired as recommended in the datasheet and whether digit0 is left or right..

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top