Easy: Make a LED blink? PIC12F615 - Page 1
Forum section: electronics / general

author: netwinder
author_rank: Regular Contributor
timestamp: April 26, 2016, 11:34:43 pm
content: Hello EEVBlog fourm,I come with a simple task, that I aparantly can't do. I have a PIC12F615 and i've been trying to make a LED blink on it. The LED is on GP0, pin 7 of the IC.Code:#define _XTAL_FREQ 8000000#include <xc.h>// BEGIN CONFIG#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)void main() {TRISIO = 0;GPIO = 0;while (1) {GPIObits.GP0 = 1;__delay_ms(500); // 500msGPIObits.GP0 = 0;__delay_ms(500); // 500ms}}I've been through countless "solutions" online to no avail. Its probably my poor understanding of the PIC microcontroller, so feel free to roast me in knowledge.Thanks for your time

author: Ian.M
author_rank: Super Contributor
timestamp: April 26, 2016, 11:40:09 pm
content: Turn off the watchdog.The /MCLR pin needs a 10K pullup to Vdd.Do you have a crystal + appropriate load capacitors connected to the OSC1,OSC2 pins? If not, you need to use the internal oscillator instead of HS mode for the chip to run at all.

author: botcrusher
author_rank: Regular Contributor
timestamp: April 26, 2016, 11:49:30 pm
content: While the watchdog is overkill for this application, perhaps mentioning what's wrong with the current use of watchdog would also be of help.The watchdog isn't Almighty and knowing. You can think of it as a self destruct mechanism, it doesn't know that the program froze. It just knows that somebody pushed the damn button to start it, and that unless somone resets it, It's going to go boom.Anyways, you didn't put any kind of code to reset the doomsday clock, so it'll keep resetting.

author: netwinder
author_rank: Regular Contributor
timestamp: April 26, 2016, 11:51:17 pm
content: I changed my code to:Code:#define _XTAL_FREQ 8000000#include <xc.h>// CONFIG#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)#pragma config IOSCFS = 8MHZ // Internal Oscillator Frequency Select (8 MHz)#pragma config BOREN = OFF // Brown-out Reset Selection bits (BOR disabled)void main() {TRISIO = 0;GPIO = 0;while (1) {GPIObits.GP0 = 1;__delay_ms(500); // 500msGPIObits.GP0 = 0;__delay_ms(500); // 500ms}}Thanks everybodyI also added the 10k pull up resistor.

author: westfw
author_rank: Super Contributor
timestamp: April 28, 2016, 12:05:53 am
content: You might want to add:Code:ANSEL = 0; // disable analog input functionsCMCON0 = 0; // disable comparator outputsIt used to be (might still be; haven't been paying much attention) that pins with analog functions defaulted to analog mode, which could cause strange behavior when trying to use them for digital IO.

author: JPortici
author_rank: Super Contributor
timestamp: April 28, 2016, 12:00:21 pm
content: for future referenceQuotemeans that you don't need to pull up mclr and that the pin has become a GP input (input only)the code is right, so.. have you actually programmed the chip?

author: Ian.M
author_rank: Super Contributor
timestamp: April 28, 2016, 12:07:39 pm
content: Actually, leaving the /MCLR pin floating is always inadvisable.Some PICs support enabling a weak pullup when /MCLR is disabled and the pin is configured as a logic input, but the internal pullup is insufficient for good EMI immunity, and, for PICs that support HV programming, transient voltages above Vdd on the pin can cause momentary programming mode entry and an apparent reset. Therefore an external pullup should be used, or if the environment is expected to be electrically noisy, /MCLR should be jumpered to Vdd at the ICSP header.

author: dannyf
author_rank: Super Contributor
timestamp: April 28, 2016, 03:54:12 pm
content: "internal pullup is insufficient for good EMI immunity, "What's good or good enough is high subjective and application specific.Two things here.1. Will a floating mclr pin generate a reset? I think the answer is a definitive no.2. Will a floating mclr pin cause the chip go into programming mode. It is possible but difficult.The wpu is about 20k equivalent. It is hard to imagine that you encounter sufficiently strong emi on every job where that kind of bypass isn't sufficient.

author: Ian.M
author_rank: Super Contributor
timestamp: April 28, 2016, 04:06:17 pm
content: Although the PIC12F615 nominal weak pullup current is 250uA, equivalent to 20K @Vdd=5V, the worst case (minimum) is only 50uA (100K). Also there is no weak pullup on the GP3 input with /MCLR disabled. Leaving CMOS inputs like GP3 floating is certainly bad practice, so one needs to do something with it (e.g. a pullup) anyway.

author: macboy
author_rank: Super Contributor
timestamp: May 02, 2016, 01:11:00 pm
content: I agree with Ian.M, either connect it to some output to eliminate the issue, or connect a good pull-up to it to eliminate the issue. Left floating, it might be an issue. Or might not. Why take the chance?