Novice 16F83A BLINK LED program help


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Jul 2007
    Posts
    10

    Smile Novice 16F84A BLINK LED program help

    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
    Last edited by owali; - 24th July 2007 at 05:18.

  2. #2
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile Oscillator=RC

    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-
    Ohm it's not just a good idea... it's the LAW !

  3. #3
    Join Date
    Jul 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    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?

    Quote Originally Posted by Pic_User View Post
    Oscillator=RC
    Is generally used for the Resistor/Capacitor Oscillator not for a 20 MHz ceramic resonator.

    -Adam-

  4. #4
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile Hs

    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-
    Ohm it's not just a good idea... it's the LAW !

  5. #5
    Join Date
    Jul 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Sorry, it is actually a PIC16F84A

    Quote Originally Posted by Pic_User View Post
    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-

  6. #6
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Post

    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-
    Ohm it's not just a good idea... it's the LAW !

  7. #7
    Join Date
    Jul 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    I am using PBP

  8. #8
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by owali View Post
    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.

  9. #9
    Join Date
    Jul 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    I have the three pin, and the center is gounded.

  10. #10
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Post next idea....

    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.

  11. #11
    Join Date
    Jul 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    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?
    Last edited by owali; - 24th July 2007 at 15:53.

  12. #12
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Post the 16F84A.INC file

    Hi owali,
    Quote Originally Posted by owali View Post
    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.
    Ohm it's not just a good idea... it's the LAW !

  13. #13
    Join Date
    Jul 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Thumbs up

    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

  14. #14
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Thumbs up WooHoo!

    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-
    Ohm it's not just a good idea... it's the LAW !

  15. #15
    Join Date
    Jul 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    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.
    Quote Originally Posted by Pic_User View Post
    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-

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  3. Simple Blink program doesnt work.
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 1st March 2009, 20:30
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts