This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Dallas Semiconductor 450 Source Code Help

Hello all my name is Casey Hafeman. I have been struggling with this all night, and not sure how to attempt this anymore. I have the code working right when input P1^0 or P1^1 is true (1). But, I would like to add somewhere inside the code where when both inputs (P1^0, and P1^1 go false (0) there is a time delay of 5-10 seconds that it keeps cycling through the loop. Then finally turns completely off.

//Railroad Warning Light (With Lights and Bell) Source Code
#include <reg51.h>
void MSDelay (unsigned int);
void MSDelay2 (unsigned int);

sbit input = P1^0;
sbit input2 = P1^1;
sbit LLight = P0^1;
sbit RLight = P0^2;
sbit Bell = P0^4;

void main(void)
{
        unsigned int i;
        input = 0x00; //'input' As Input Port
        input2 = 0x00; //'input2' As Input Port
        LLight = 0xFF; //'LLight' As Output Port
        RLight = 0xFF; //'RLight' As Output Port
        Bell = 0xFF; //'Bell' As Output Port
        {
                LLight = 0;
                RLight = 0;
                Bell = 0;
                i=0;
        }
        for (;;)
        {
                if (input==1|input2==1)
                {
                MSDelay2 (1250);
                }
                LLight = 0;
                RLight = 0;
                Bell = 0;
        }
}
void MSDelay (unsigned int itime)
{
        unsigned int i, j;
        for (i = 0; i < itime; i++)
                for(j = 0; j < 1275; j++);
}
void MSDelay2 (unsigned int itime)
{
        unsigned int i;
        for (i = 0; i < itime; i++);
        {
                {
                                Bell = 1;
                                LLight = 1;
                                RLight = 0;
                                MSDelay (1250);
                        }
                        {
                                Bell = 1;
                                LLight = 0;
                                RLight = 1;
                                MSDelay (1250);
                        }
                }
        }

Parents
  • I don't know if anyone has seen this thread yet, but I did go through the code and deleted some parts of the code that were not needed it made it easier to read and less confusing (i hope)

    ...still looking to have that delay...

    but here is the updated code thus far...

    #include <reg51.h>
    void MSDelay (unsigned int);
    void MSDelay2 (unsigned int);
    
    sbit input = P1^0;
    sbit input2 = P1^1;
    sbit LLight = P0^1;
    sbit RLight = P0^2;
    sbit Bell = P0^4;
    
    void main(void)
    {
            for (;;)
            {
                    if (input==1|input2==1)
                    {
                    MSDelay2 (1250);
                    }
                    LLight = 0;
                    RLight = 0;
                    Bell = 0;
            }
    }
    void MSDelay (unsigned int itime)
    {
            unsigned int i, j;
            for (i = 0; i < itime; i++)
                    for(j = 0; j < 1275; j++);
    }
    void MSDelay2 (unsigned int itime)
    {
            unsigned int i;
            for (i = 0; i < itime; i++);
            {
                    {
                                    Bell = 1;
                                    LLight = 1;
                                    RLight = 0;
                                    MSDelay (1250);
                            }
                            {
                                    Bell = 1;
                                    LLight = 0;
                                    RLight = 1;
                                    MSDelay (1250);
                            }
                    }
            }
    

Reply
  • I don't know if anyone has seen this thread yet, but I did go through the code and deleted some parts of the code that were not needed it made it easier to read and less confusing (i hope)

    ...still looking to have that delay...

    but here is the updated code thus far...

    #include <reg51.h>
    void MSDelay (unsigned int);
    void MSDelay2 (unsigned int);
    
    sbit input = P1^0;
    sbit input2 = P1^1;
    sbit LLight = P0^1;
    sbit RLight = P0^2;
    sbit Bell = P0^4;
    
    void main(void)
    {
            for (;;)
            {
                    if (input==1|input2==1)
                    {
                    MSDelay2 (1250);
                    }
                    LLight = 0;
                    RLight = 0;
                    Bell = 0;
            }
    }
    void MSDelay (unsigned int itime)
    {
            unsigned int i, j;
            for (i = 0; i < itime; i++)
                    for(j = 0; j < 1275; j++);
    }
    void MSDelay2 (unsigned int itime)
    {
            unsigned int i;
            for (i = 0; i < itime; i++);
            {
                    {
                                    Bell = 1;
                                    LLight = 1;
                                    RLight = 0;
                                    MSDelay (1250);
                            }
                            {
                                    Bell = 1;
                                    LLight = 0;
                                    RLight = 1;
                                    MSDelay (1250);
                            }
                    }
            }
    

Children