HELP needed for understanding C program

Discussion in 'Programmer's Corner' started by engineer_disaster, Apr 21, 2007.

  1. engineer_disaster

    Thread Starter New Member

    Apr 21, 2007
    1
    0
    hi this is zeeshan hayat from pakistan. i m final year electrical engg student. i have made project about eqrth quake detection. my teacher whote its programming for me. i don't understand it bcz i had studied assembly alnguage nd program is in C.kindly some one help me understand it.
    send me details at: zeeshanweb@gmail.com
    here is the prog:
    ___________________________________________________________________
    #include <At89x51.h>

    ///////////////////////////////
    //Selection Lines 2.0 2.1 2.2 Active Low
    //P0 a - g Active High

    sbit btnUp = P1^0;
    sbit btnDn = P1^1;

    sbit ind1 = P2^3; //Active Low
    sbit ind2 = P2^4;
    sbit ind3 = P2^6;
    sbit ind4 = P2^7;

    unsigned char Counter;
    unsigned char Format[10] = {0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10};
    unsigned char colon, ticks, secs;//, mins;

    void StartTimer()
    {
    colon = 10;
    ticks = 2;
    TMOD = 0x10; //timer 1 mode 2
    TH1 = 0x4c; //resetvalue;
    TL1 = 0x26; //resetvalue;
    TR1 = 1; //start timer 1
    EA = 1; //enable interrupts
    ET1 = 1; //enable timer 1 interrupt
    ind1 = 0;
    ind2 = 0;
    ind3 = 0;
    ind4 = 0;
    }//end void InitTimerRpm()

    void Delay()
    {
    unsigned int i;
    for(i = 0; i < 400;)
    {
    i++;
    }
    }

    void Display()
    {
    P0 = ~Format[Counter];
    P2_0 = 0;
    P2_1 = 1;
    P2_2 = 1;
    // P2 = 0xfe;
    Delay();
    P2_0 = 1;
    P2_1 = 0;
    P2_2 = 1;
    // P2 = 0xfd;
    Delay();
    P2_0 = 1;
    P2_1 = 1;
    P2_2 = 0;
    // P2 = 0xfb;
    Delay();
    }

    Timer1() interrupt 3 //timer 1 interrupt service routine
    {
    TR1 = 0; //turn off the timer as we reset it
    TH1 = 0x4c; //resetvalue;
    TL1 = 0x26; //resetvalue;
    TR1 = 1; //restart timer1
    colon--; //decrement colon while not zero
    if(colon == 0)
    {
    colon = 10;
    ticks--;
    if(ticks == 0)
    {
    ticks = 2;
    secs++;
    if(secs == 60)
    {
    // mins++;
    // if(mins == 60)
    // {
    TR1 = 0;
    EA = 0; //enable interrupts
    ET1 = 0; //enable timer 1 interrupt
    ind1 = 1;
    // }
    }
    }//end if(ticks == 0)
    }//end if colon
    }//end timer1() interrupt 3

    void main()
    {
    bit flag = 0;
    colon = 10;
    ticks = 2;
    // mins = 0;
    secs = 0;
    while(1)
    {
    if(!btnUp)
    {
    while(!btnUp)
    Display();
    if(Counter < 9)
    Counter++;
    else
    Counter = 0;
    }
    if(!btnDn)
    {
    while(!btnDn)
    Display();
    if(Counter > 0)
    Counter--;
    else
    Counter = 9;
    }
    Display();

    if(Counter > 0 && flag == 0)
    {
    StartTimer();
    flag = 1;
    }
    }
    }
    ________________________________________________________________
     
Loading...