View previous topic :: View next topic |
Author |
Message |
Tunfiskur
Joined: 01 Jun 2012 Posts: 13
|
Weird behavior 16F819 |
Posted: Mon Apr 22, 2013 2:04 pm |
|
|
Im trying to get my 16F819 to work. For now just a simple led blink.
Problem: The led only blinks if i hold the MCLR (pin 4) with my fingers. If i let go of it, the led will just go into very random state (blinking, not blinking etc).
Here is the connection diagram:
Here it the code:
Code: | #include "c:\devices\16F819.h"
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES BROWNOUT //Reset when brownout detected
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#use delay(clock=8000000)
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
// setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
while(1){
output_high(PIN_A1);
delay_ms(350);
output_low(PIN_A1);
delay_ms(350);
}
} |
Im using CCS v.4.010
Any help will be much appreciated |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19378
|
|
Posted: Mon Apr 22, 2013 2:28 pm |
|
|
Get rid of LVP.
You do not want this, and it is causing the behaviour you are seeing.
As a general comment, it is bad practice to have pins left floating.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Tunfiskur
Joined: 01 Jun 2012 Posts: 13
|
|
Posted: Mon Apr 22, 2013 2:34 pm |
|
|
Ttelmah wrote: | Get rid of LVP.
You do not want this, and it is causing the behaviour you are seeing.
As a general comment, it is bad practice to have pins left floating.
Best Wishes |
Thanks,
Another question about floatings pins, I always have a problem with knowing what pins to connect to pullup resistors and who not to. Is there a rule of thumb or any details in the datasheet that i can use to determine that? Not only for 16f819 but more in general?
thanks |
|
![](templates/subSilver/images/spacer.gif) |
SuperDave
Joined: 22 May 2008 Posts: 63 Location: Madison, TN
|
|
Posted: Mon Apr 22, 2013 2:59 pm |
|
|
Float is a potential problem on any pin designated as a digital INPUT (the most typical state at POR). Such pins have a very high impedance, meaning any leakage from anywhere can set their state and any varying leakage (AC line hum, local transmitter) will change their state. Even if you don't use those pins (and they are not interrupts!!) the constant state changing will draw more current.
Lots of fixes. Easiest is to Tris them as outputs. You could also tie them to power or ground but it would then be hard to hack and wack an additional input or output should the need arise. (General rule: do it in software instead of hardware if you have a choice.) If you are expecting production, pick a part with fewer pins and save some money as well. |
|
![](templates/subSilver/images/spacer.gif) |
|