aliraza786
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.........
___________________________________________________________________
my mcu is 89s51
___________________________________________________________________
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: