PDA

View Full Version : Novice 16F83A BLINK LED program help



owali
- 24th July 2007, 03:49
I wanted to try a very simple LED program for my PIC16F84A. I wired it in the following manner:

5V to 4.7k Ohm resistor to MCLR pin
5V to VDD
VDD to ground via .1uF cap
20 MHz ceramic resonator across OSC1 pin and OSC2 pin
Ground to Vss
Pin RB1 to 470 Ohm resistor to LED to Ground

I put the following program into Microcode studio:
loop:
high portb.1
pause 50
low portb.1
goto loop
end

The melab configuration is the following:
Oscillator=RC
Watchdog time=Enabled
Power up timer=Enabled
Code up protect= Off

The strangest thing happens though... The LED only goes on when I move my hand close to the circuit. I don't even have to touch the circuit, and the LED remains on(does not blink) until I move my hand away.

I have no idea what I am doing wrong. Can someone PLEASE help me figure this out?? Thanks

Pic_User
- 24th July 2007, 04:13
Hi owali,

Welcome to the PICBASIC forum. You are on the right track, starting with a simple, program and circuit.

Oscillator=RC
Is generally used for the Resistor/Capacitor Oscillator not for a 20 MHz ceramic resonator.

-Adam-

owali
- 24th July 2007, 04:40
What setting should it be on for a resonator? XT? I just programmed it with XT and the result is the same.

Are there any other settings that could be wrong on melab?



Oscillator=RC
Is generally used for the Resistor/Capacitor Oscillator not for a 20 MHz ceramic resonator.

-Adam-

Pic_User
- 24th July 2007, 04:43
Hi owali,

I could not find any reference to the PIC16F83A.

If you PIC can allows a 20Mhz resonator try:
DEFINE OSC 20

Also, the PBP manual says;
The oscillator defaults to XT on most devices.
This is the setting for the default 4MHz oscillator.
If a faster oscillator is used, this setting must be changed to HS.

-Adam-

owali
- 24th July 2007, 04:46
Sorry, it is actually a PIC16F84A


Hi owali,

I could not find any reference to the PIC16F83A.

If you PIC can allows a 20Mhz resonator try:
DEFINE OSC 20

Also, the PBP manual says;
The oscillator defaults to XT on most devices.
This is the setting for the default 4MHz oscillator.
If a faster oscillator is used, this setting must be changed to HS.

-Adam-

Pic_User
- 24th July 2007, 05:16
Hi owali,

See Melanie’s extremely helpful post:
Presetting Configuration Fuses (PIC Defines) into your Program
http://www.picbasic.co.uk/forum/showthread.php?t=543

Are you using PBP or PBC compiler?

-Adam-

owali
- 24th July 2007, 05:20
I am using PBP

malc-c
- 24th July 2007, 10:28
I wanted to try a very simple LED program for my PIC16F84A. I wired it in the following manner:

5V to 4.7k Ohm resistor to MCLR pin
5V to VDD
VDD to ground via .1uF cap
20 MHz ceramic resonator across OSC1 pin and OSC2 pin
Ground to Vss
Pin RB1 to 470 Ohm resistor to LED to Ground

The strangest thing happens though... The LED only goes on when I move my hand close to the circuit. I don't even have to touch the circuit, and the LED remains on(does not blink) until I move my hand away.

I have no idea what I am doing wrong. Can someone PLEASE help me figure this out?? Thanks

You don't mention anything about the timing capacitors. You need a 22pf - 33pf capacitor from OSC1 to GND and another between OSC2 and GND, with the resonator / Crystal between OSC1 and OSC2.

However if your resonator has three pins then the centre pin needs to be grounded. This is because three pin resonators have the capacitors built in.

owali
- 24th July 2007, 11:43
I have the three pin, and the center is gounded.

Pic_User
- 24th July 2007, 14:45
Hi owali,
Please see this post about a similar problem:
http://www.picbasic.co.uk/forum/showthread.php?t=5469
hope this helps,
-Adam-
Let us know if you have tried any of our posted suggestions.

owali
- 24th July 2007, 15:11
I tried adding the following configuration code to my program.
@ DEVICE XT_OSC
@ DEVICE PIC16F84A,XT_OSC
@ DEVICE pic16F84A, INTRC_OSC_NOCLKOUT
' System Clock Options
@ DEVICE pic16F84A, WDT_ON
' Watchdog Timer
@ DEVICE pic16F84A, PWRT_ON
' Power-On Timer
@ DEVICE pic16F84A, MCLR_ON
@ DEVICE pic16F84A, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F84A, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F84A, CPD_OFF
' Data Memory Code Protect
' Set to CPD_OFF for Development Copy
' Set to CPD_ON for Release Copy
@ DEVICE pic16F84A, PROTECT_OFF

But I get errors when I compile now.

Error ... Undefined symbol 'lvp_off'

In addition to the configuration stuff, do I have to INCLUDE anything in my program?

Pic_User
- 24th July 2007, 17:15
Hi owali,

I tried adding the following configuration code to my program.
@ DEVICE XT_OSC
@ DEVICE PIC16F84A,XT_OSC
@ DEVICE pic16F84A, INTRC_OSC_NOCLKOUT
' System Clock Options
@ DEVICE pic16F84A, WDT_ON
' Watchdog Timer
@ DEVICE pic16F84A, PWRT_ON
' Power-On Timer
@ DEVICE pic16F84A, MCLR_ON
@ DEVICE pic16F84A, BOD_ON
' Brown-Out Detect
@ DEVICE pic16F84A, LVP_OFF
' Low-Voltage Programming
@ DEVICE pic16F84A, CPD_OFF
' Data Memory Code Protect
' Set to CPD_OFF for Development Copy
' Set to CPD_ON for Release Copy
@ DEVICE pic16F84A, PROTECT_OFF

But I get errors when I compile now.

Error ... Undefined symbol 'lvp_off'

In addition to the configuration stuff, do I have to INCLUDE anything in my program?
If you are using a sample PBP program to compile, you do not have to add an INCLUDE unless the original program used one.

In Microcode Studio make sure you are using the button for Compile(ing) AND Program(ing), not the button for just Compile(ing).

Make sure you are using PIC16F84A in the "drop down" box in Microcode Studio.

Are you using:
MeLabs default (PM) Assembler
or
Microchips (MPASM) Assembler

You can place the device “inline” like this style:
@ device pic16F648A, hs_osc, wdt_off, mclr_on, lvp_off, protect_off

But, you may be trying too hard. Most of the defines are already supplied by the default *.INC file (16F84A.INC) .

See this microEngineering Labs web page:

Specifying configuration bit settings in PICBASIC PRO programs.
If you add a configuration directive to your program file, you are actually replacing the default configuration that the compiler would otherwise include. The easiest way to determine the correct syntax is to get examples from the compiler and assembler's built-in resource files. To that end, it's best to understand how the compiler determines the config defaults....

....The first thing the compiler looks for is a file in the PBP folder that matches the targeted PIC. If you tell it to compile for a 16F84A, it reads the file "16F84A.INC". The contents of this file are divided into 2 sections, one for each assembler. An internal variable, "PM_USED", tells the compiler which section of the file to use. In the following example, you will see that the top section ("ifdef" to "else") is meant for the PM assembler and the bottom section ("else" to "endif") is meant for the MPASM assembler.

http://www.melabs.com/support/config_defaults.htm

You do have to change from the default (DEVICE XT_OSC in the 16F84A.INC file )
by adding @ DEVICE HS_OSC to your program:

also:
DEFINE OSC 20 for your 20 MHz resonator.

owali
- 25th July 2007, 02:37
Sweet! It works now. Thanks for all the help.
The following program worked:

'PicBasic Pro program
'LED Test
@ DEVICE HS_OSC
DEFINE OSC 20
loop:
PAUSE 500
high portb.1
pause 500
low portb.1
goto loop
end

Pic_User
- 25th July 2007, 03:34
Hi owali,

That’s great news. Keep going. What’s your next program?
Flash 4 LED “forward and backward”
Light LED while button is pressed
Flash LED while button is pressed
Fade an LED up and down in brightness
Do you have any other PIC models available?

-Adam-

owali
- 25th July 2007, 05:02
I will probably do some more simple LED programs first like you suggested. Then I will hook up the LCD I just bought. I also bought a Sharp IR distance sensor. I only have one PIC controller though.

Hi owali,

That’s great news. Keep going. What’s your next program?
Flash 4 LED “forward and backward”
Light LED while button is pressed
Flash LED while button is pressed
Fade an LED up and down in brightness
Do you have any other PIC models available?

-Adam-