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.

8051 hardware input switch reading problem

Status
Not open for further replies.

aliraza786

Full Member level 4
Full Member level 4
Joined
Nov 10, 2009
Messages
210
Helped
14
Reputation
28
Reaction score
14
Trophy points
1,298
Location
Lahore, Pakistan, Pakistan
Activity points
2,914
hello i wana ask i have intefaced two switches with 8051 when one switch is on relay on and when other switch is on relay will be off..every thing works fine in protious and hardwre but it is ok for a short interval of time almost 5 minute but i have to off the relay after 12 hours ...after a long time 8051 doesnot read the pin i dnt know what is the problem.....this is the simple code here. 8051 read switch for a small interval of time but after a long time interval 8051 doesnot read the pin.........
___________________________________________________________________

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<reg51.h>
sbit sw=P2^0;
sbit sw1=P2^1;
unsigned int x,g;
sbit relay=P1^6;
void delay(x)
{
    for(g=0; g<x; g++)
    {
        TMOD=0x01;
        TH0=0xFC;
        TL0=0x67;
        TR0=1;
        while(TF0==0);
        TR0=0;
        TF0=0;
    }
}
void main()
{   P2=0xFF;
    sw=1;
    sw1=1;
 
    while(1)
    {
        if(sw==0)
        {
            delay(800);
            if(sw==0)
            {
                relay=0;
                delay(300);
            }
        }
        if(sw1==0)
        {
            delay(800);
            if(sw1==0)
            {
                relay=1;
                delay(300);
            }
        }
    }
}


my mcu is 89s51
 
Last edited by a moderator:

I suggest you to
1. share the circuit diagram, so we can look into h/w problem as well, if any.
2. If possible use EXT INTR (INT0 and INT1) instead of P2.0, P2.1.
 
i dont know how to use external intrupt please suggest me the article where i can learn how to use external intrupts ans sample code too....thnkyou very much for this help....!
 

i dont know how to use external intrupt please suggest me the article where i can learn how to use external intrupts ans sample code too....

Here are a few tutorials discussing external interrupts:





INTERRUPT PROGRAMMING IN 8051

Appnote 103 - 8051 Interrupt Vectors

To define an interrupt function using the Keil C51 Compiler, an interrupt number and register bank is specified where the interrupt number corresponds to a specific interrupt vector address.

void my_external_interrupt_0_routine(void) interrupt 0 using 2
{
/* do something */
}



8051_EX0.ZIP Keil Example

While each C compiler has its own Interrupt Service Routine (ISR) syntax, it appears you are using Keil, if not reference the appropriate compiler docs for the proper ISR syntax.



BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
#include<reg51.h>
sbit sw=P2^0;
sbit sw1=P2^1;
unsigned int x,g;
sbit relay=P1^6;

void init(void)
{
TMOD=0x01;
P2=0xFF;
sw=1;
sw1=1;



}
void delay(x)
{
for(g=0; g<x; g++)
{
TH0=0xFC;
TL0=0x67;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
}
void main()
{
init();
while(1)
{
if(sw==0)
{
delay(10);
if(sw==0);
{
while(!sw);
relay=0;
delay(10);
}
}

if(sw1==0)
{
delay(10);
if(sw1==0)
{
while(!sw1);
relay=1;
delay(10);
}
}
}
}
 

welove8051 i try ur code but still it is good for short time i can on the system but cant make it off.....becuse system have to remain on for almost 12 hours...
 

8051 read switch for a small interval of time but after a long time interval 8051 doesnot read the pin.........

It sounds like there maybe another issue besides your code. Especially if the system works for a period of time and then sudden fails.

Can you provide a schematic of your circuit?

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
@aliraza,

As I foretold...please share your hardware circuit design.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top