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.

PIC12F675 does not work for toggling an LED built

Status
Not open for further replies.

swapan

Full Member level 4
Joined
Feb 20, 2009
Messages
199
Helped
27
Reputation
54
Reaction score
24
Trophy points
1,298
Location
Kolkata
Activity points
2,806
Hi guys,
While carrying out practical test of toggling an LED built around PIC 12F675, I am not able to make the MCU working. Please see the code alongwith fuse setting.

FUSE Setting:
INTOSC oscillator;
Watch Dog Timer : Disable
Power Up Timer : Disabled
MCLR pin function select : Disabled
Brown Our detect : Enabled

I have been trying for last 2 weeks, but could not get the LED lit. I have tested the same circuit on two separate PCBs. The result is same on both the hardwares.


Code:
sbit LED at GP5_bit;

void main() {
GPIO = 0x0;
TRISIO = 0xF; //Only GPIO Bit 5 is output.
CMCON = 0x7;  // Comparator off.
ANSEL = 0x21;  // AD Conversion Clock FOSC/32, AN0 is input.
 do {
 LED = ~LED;
 delay_ms (1000);
   } while (1);
}
 

Here is working fine on Proteus using this settings:

Image.png
 

Here is working fine on Proteus using this settings:

Sorry to be late in updating my post. Being frustrated, I compiled the code afresh. Now the code is running fine. I think some error crept in while compiling the code.
 

I'm glad it works now but there is a potential problem that you should be aware of:

The line "LED = ~LED;" might cause problems because of the way PIC ports work. It says "read in the state of the GPIO port, flip the LED bit, write it back to the port" so rather than just driving out a square wave, it depends on exactly what was read in from the LED bit. If any residual charge was left on the pin, for example from the capacitance of wiring and the LED, it may read the wrong state in.

A more reliable method is to create a variable, toggle that and write it to the GPIO port. It avoids the 'read' that causes the problem.

Brian.
 
Thanks Brian,
At the initial days of my learning, I suffered a lot for this RMW problem and experts of this forum guided me to overcome it. Actually I wanted to use the MCU for another code. But it did not work. Hence to carry out a test whether the MCU works, I burnt the MCU with this small code without caring for RMW error.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top