Relay help!!

Status
Not open for further replies.

Thread Starter

elex09

Joined Mar 17, 2010
39
Thanks SgtWookie and Bill....I have anyway posted on the uC forum...getting a few responses from there too...will try that link thing, SgtWookie,....but meanwhile since i have been able to get my point across to u guys, if u have any suggestions on where i need to correct the code u can just let me know...

doubt: uC pins are by default output right? no need to initialize them as anything?
 

retched

Joined Dec 5, 2009
5,207
They may be floating or 3rd state, high-z If they are not assigned.

Good programming practices would be to define each pin being used for its intended usage. If you are using a pin as an input, define it as an input.. Depending on defaults WILL lead to troubles. Defaults change from chip to chip and from compiler to compiler.
 
uC pins are by default output right? no need to initialize them as anything?
You have to check the manual for defaults, but retched is right: don't count on the defaults. It's not uncommon for there to be some code path that looks sort of like a reset, but doesn't actually reset the hardware. In that case, your peripherals will be set up however they were before the pseudo-reset happened.

FWIW, most of the general-purpose microcontrollers I'm familiar with have most GPIO pins in Input / HiZ state after a reset. I don't know about your 89C51, though.
 

Thread Starter

elex09

Joined Mar 17, 2010
39
so that means i should initialize/define the port which i am using ie.P1 as ouput by:

Rich (BB code):
MOV P1,#00h;
or i can just clear the 1 pin that i am using...P1.6..
any other mistake as such? will make the change and check the working anyway..
any need of writing it all in an interrupt routine..?
 

retched

Joined Dec 5, 2009
5,207
If you only have one function, there is no need for an interrupt.

Interrupts are for when you want to do something, like count to a million, flash an led and count back to zero..and keep looping. Then If a button is pressed, the interrupt will jump out of the loop and execute code then return from where the interrupt occured.

So if you are counting to a million and someone presses a button at 600,003...

..the interrupt will jump out of the loop and flash a different led then return to the original loop that was interrupted

so:

1, 2 ,3.....600,003 BUTTON PRESS
[interrupt code and jump to interrupt code]
FLASH A BLUE LED [jump back]
600,004... 600,005... 600,006.........

If you dont have the counting going on, you need no interrupt. If you just want to flash the blue led when a button is pressed, you just wait for the button press in your main loop.
 
Status
Not open for further replies.
Top