TropicalMonkey
New Member
Hello everyone!
I am very new to MCU programming. In order to try out the free HITECH compiler I built a MCU's "Hello, World" program that is to blink an LED. I got the code from somewhere on the internet and compiled and programmed 12f675 successfully. The LED does blink .. well almost. Apparently it is too sensitive to the EMI. The LED blinking might start and stop for no reason. Initially I suspected my el cheapo bread-board. But it turned that when I am sitting at my desk with the bread-board blinking LED on the desk, I can turn that off by simply lifting my feet from the ground - and vice versa. It looks like it is suffering from EMI or floating inputs. I tried to change all GPIO to outputs and that did not solve the issue. But if I leave all GPIOs as inputs and pull them up to +VDD, it just works fine. Is that normal? Or am I missing something?
Oh! by the way, here is the program I got from internet:
I am very new to MCU programming. In order to try out the free HITECH compiler I built a MCU's "Hello, World" program that is to blink an LED. I got the code from somewhere on the internet and compiled and programmed 12f675 successfully. The LED does blink .. well almost. Apparently it is too sensitive to the EMI. The LED blinking might start and stop for no reason. Initially I suspected my el cheapo bread-board. But it turned that when I am sitting at my desk with the bread-board blinking LED on the desk, I can turn that off by simply lifting my feet from the ground - and vice versa. It looks like it is suffering from EMI or floating inputs. I tried to change all GPIO to outputs and that did not solve the issue. But if I leave all GPIOs as inputs and pull them up to +VDD, it just works fine. Is that normal? Or am I missing something?
Oh! by the way, here is the program I got from internet:
Code:
// Copyright (c) 2005, K9spud LLC.
// http://www.k9spud.com/hoodmicro/
__CONFIG(INTIO & WDTDIS & PWRTEN);
#define bitset(var, bit) ((var) |= 1 << (bit))
#define bitclr(var, bit) ((var) &= ~(1 << (bit)))
#define LED_PIN 4
void main(void)
{
unsigned int i;
INTCON = 0; // disable interrupts
TRISIO = ~(1 << LED_PIN); // configure all pins as inputs, except the LED_PIN
//TRISIO = 0;
OSCCAL = _READ_OSCCAL_DATA(); // restore oscillator calibration
for(;;)
{
bitset(GPIO, LED_PIN); // turn the LED on
for(i = 0; i < 10000; ++i)
{
// do nothing, busy wait loop
}
bitclr(GPIO, LED_PIN); // turn the LED off
for(i = 0; i < 10000; ++i)
{
// do nothing, busy wait loop
}
}
}