Friday 16 May 2014

Programming of micro controllers 8051

by Unknown  |  in micro controllers at  00:42

Programming of micro controllers 8051
In this programing u can control four device by using only two input.circuit diagram is shown below.

#include <reg51.h>                           
 sbit izero=P0^0;
 sbit ione=P0^1;
 sbit itwo=P0^2;
 sbit ozero=P1^0;
 sbit oone=P1^1;
 sbit otwo=P1^2;
 sbit othree=P1^3;


 void main(void)
 {
      unsigned char a=0,b=0,c=0,d=0,e,f,g,h,sum;
    ozero=0;
    oone=0;
    otwo=0;
    othree=0;
    izero=0;
    ione=0;
    itwo=0;
    for( ; ; )
    {
       
        do
        {
            g=itwo;
        }while(g==0);
        e=izero;       
         f=ione;
        if(e==1)
        {
            sum=1;
        }
        else
        {
            sum=0;
        }
        if(f==1)
        {
            sum=sum+2;
        }
        else
        {
            sum=sum;
        }
        switch(sum)
        {
            case(0):
            {
                if(a%2==0)
                {
                    ozero=1;
                }
                else
                {
                    ozero=0;
                }
                a++;
                break;
            }
            case(1):
            {
                 if(b%2==0)
                {
                    oone=1;
                }
                else
                {
                    oone=0;
                }
                b++;
                break;
            }
            case(2):
            {
                if(c%2==0)
                {
                    otwo=1;
                }
                else
                {
                    otwo=0;
                }
                c++;
                break;
            }
            case(3):
            {
                 if(d%2==0)
                {
                    othree=1;
                }
                else
                {
                    othree=0;
                }
                d++;
                break;
            }
           
        }
        for(h=0;h<240;h++);
    }
}

0 comments:

Proudly Powered by Blogger.