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.

Bulb Light Intensity control using 8051

Status
Not open for further replies.

gaurav_sharma132

Member level 1
Joined
Feb 3, 2009
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,553
Hello
I'm making project on Home automation along with varying light intensity and fan speed using Philips TV remote.
There is little problem at software side I'm facing. As at one pin INT0 I have switch and at other INT1 i have ZVS(Zero voltage signal). Both interrupt routines are are edge triggered. What I want is at every time the switch is pressed the delay is going to be inc by 1ms. I have made delay routine using for loop. So that speed of fan or light intensity can be varied.

As a single variable is used inside both interrupt routine so I have declare the global variable above main but problem is that whenever I press switch the value is not updating in the function call inside INT1 routine.

#include<reg51.h>
#include<intrins.h>

sbit fan1=P1^3;

unsigned char x; //global variable decleration

void delay(unsigned int time)
{
unsigned int l,m;

for(l=0;l<time;l++)
for(m=0;m<112;m++);

}

void delay1(unsigned int time)
{
unsigned int l,m;

for(l=0;l<time;l++)
for(m=0;m<40;m++);

}

void ExtInt0() interrupt 0 //switch
{
x=x+1;
}

void ExtInt1() interrupt 2 //ZVS
{
delay(x); //this variable x is not incrementing at all
fan1=1;
delay1(1);
fan1=0;
}



void main()
{

IE=0x85;
IT1=1;
IT0=1;

while(1)
{


}
}
Whats is the problem? Please help me.
 

first there might be problem that u have not assigned any val while decleration like
unsigned char x = 0;
second connect an LED and make it turn on in inturrept function that will tell that your program runs into that function
 

Apart from the possible coding mistakes, I would implement the delay (or part of it) has a timer interrupt. Burning time with loops is not really reliable and keeps you from doing anything else, or if you do anything else the timing will not be accurate.

Another thing is that you may want to add debounce hardware and just to be safe a debounce software routine too, otherwise you may end up increasing the delay a few times per button press (just google for debounce to see what I mean).
 

ifithegr8 said:
first there might be problem that u have not assigned any val while decleration like
unsigned char x = 0;
second connect an LED and make it turn on in inturrept function that will tell that your program runs into that function
I have already did both things like initialized x=0 and also checked routine on LED's but it didn't work.

R00KIE said:
Apart from the possible coding mistakes, I would implement the delay (or part of it) has a timer interrupt. Burning time with loops is not really reliable and keeps you from doing anything else, or if you do anything else the timing will not be accurate.
Yes, firstly I tried same thing but same problem with variable which have the timer value as it is global accessed by two functions(Timer interrupt routine and INT0 routine).

R00KIE said:
Another thing is that you may want to add debounce hardware and just to be safe a debounce software routine too, otherwise you may end up increasing the delay a few times per button press (just google for debounce to see what I mean).
Yes but it is secondary thing.

Overall, Anything I tried to do got stuck at same problem of global variable.
 

Don't you need to explicitly tell the compiler what is the interrupt code and also set the interrupt vector properly?

I'm not familiar with the 8051 but you may also have to write an interrupt handler to check what triggered the interrupt and pass control to the correct interrupt code.

It should look like this:

interrupt address: jump to interrupt handler (or interrupt code, if all interrupts have unique interrupt addresses).

interrupt handler: check the interrupt registers for what triggered the interrupt and act accordingly.

At least the interrupt vector must have a "special" way to setup, it must be placed in an exact memory address and usually you have only space to place a jump instruction there because there should be another interrupt address right after that.
 

No, actually in C all done by it automatically.

Like I have to mention only interrupt number along with the function For Example 0 is for INT0 and 2 is for INT1. And if the interrupt code exceeds its pre defined memory then it automatically shifts to General purpose memory.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top