Microprocessor Project Required Coding

alahmadhu7
include.docx

#include <msp430.h>// header file

//initialization

int display();

int num= 0;

char count[]= {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x67}; < do we need char count?

int ones;

int button();

int tens;

int flag=1;

int i;

int main()//p2.0, p2.1, p2.2, p2.3 ==

{

    _EINT();//enable global interrupt

    P2DIR &=~0x0f;// P2IN &=~0x01, P2IN &=~0x02, P2IN &=~0x04, P2IN &=~ 0X08

    P8DIR |=0xff;//to set the direction, output GPIO pins

    P7DIR |=0x0c;//to set the direction

    WDTCTL =WDTPW|WDTHOLD;//disable watchdog function

    TA0CCR0=50000;

    TA0CTL=TASSEL_2

+MC_1+TACLR;

    while(1)

    {

        button();

        display();

    }

}

#pragma vector =TIMER0_A0_VECTOR

__interrupt void stopwatch(void)//The timer A interrupt routine

{

    i++;

    if(i==20)//1s/50ms = 20

    {

        num=num+1;

        i=0;

        if (a==60)

        {

         a=0;

         }

    }

}

 int display()

 {

            ones=num%10;

            P8OUT =count[ones];

            P7OUT |=0x04;//high level output

            P7OUT &=~0x04; // low level output

            P8OUT = 0xFD;

            P7OUT |=0x08;// p7 output a high level 1

            P7OUT &=~0x08;// P7 output a low level 0

            _delay_cycles(2000);

            tens=num/10;

            P8OUT =count[tens];

            P7OUT |=0x04;

            P7OUT &=~0x04;

            P8OUT = 0xFb;

            P7OUT |=0x08;

            P7OUT &=~0x08;

            _delay_cycles(2000);

   return 0;

 }

 int button()

 {

     if ((0x01 &P2IN)==0) //increment +1

     {

         _delay_cycles(3000);

          if ((0x01 &P2IN)==0)

           {

              num=num+1;

              if (a==60)

              {

                  a=0;

              }

           }

        while(!(0x01 & P2IN));//for releasing

     }

     if (((0x02 &P2IN))==0)

          {

            _delay_cycles(3000);

               if (((0x02 &P2IN))==0)

                {

                   num=num-1;//decrement -1

                       if (num<0)

                       {

                           num=59;

                       }

                }

             while(!(0x02 & P2IN));

          }

     if (((0x04 &P2IN))==0)

              {

                _delay_cycles(3000);

                   if (((0x04 &P2IN))==0)

                    {

                       num=0;

                    }

                 while(!(0x04 & P2IN));

              }

     if (((0x08 &P2IN))==0)

     {

         _delay_cycles(3000);

         if (((0x08 &P2IN))==0)

         {

             if (flag==0)

             {

                 TA0CCTL0&=~CCIE;

                 flag=1;//watch start

             }

             else

             {

                 TA0CCTL0=CCIE;

                 flag=0;//watch stop

             }

             while(!(0x08 &P2IN));

         }

     }

     return 0;

 }