1st 16F877A program in PICBasic


Closed Thread
Results 1 to 5 of 5
  1. #1
    Borisw37's Avatar
    Borisw37 Guest

    Question 1st 16F877A program in PICBasic

    Hello everybody,
    I recently received a programmer/development board and 16F877A microcontroller (EasyPIC2 http://www.mikroelektronika.co.yu/en...s/easypic2.htm) The included programmer software works great, along with MikroBasic, also included.
    Now I am trying to write some very basic programs in PICBasic with the help of MicroCode Studio. All I am trying to do is just blink on of the LEDs on port B (lets say PORTB.2) on and off once every second. I wrote the seemingly simple PICBasic code, it compiled loaded to 16F877A, but nothing seems to happen.
    I selected 16F877A in MicroCode Studio, and in the programming software, are there some other settings i need to change?
    Can somebody please do me a favor:
    1) Write a simple PICBasic code to just turn the LED on/off
    2) Compile it and post the PICBasic along with ASM code, so i can compare it to what i got.
    Thank you very much.
    Unfortunately I am not at the computer that has all the PIC software installed on it, so i cant post the code that I got.

    Thank you,

    Boris.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what about your hardware setting? what speed of crystal do you use? If it's higher than 4MHZ, let's say 20MHZ, you must include this line at the top of your code

    DEFINE OSC 20

    AND you must set your programmer to HS clock speed.

    The whole code will probably looks something like that
    Code:
    DEFINE OSC 20
    
    TRISB.2=0 'define PORTB.2 as output
    
    start:
         Toggle PORTB.2
         PAUSE 1000
         goto start
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Borisw37's Avatar
    Borisw37 Guest


    Did you find this post helpful? Yes | No

    Default

    Hello,
    Thank you, i got it to work
    Question:
    you mentioned "AND you must set your programmer to HS clock speed." is there a way to set it in the code so when the programmer opens the code it will automatically be set to "HS"
    What do different clock speeds mean? (LP,XT,HS,RC)

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    yes for sure. There's many way to do that.

    First of all, we will disable the PBP default configuration setting. with NOTEPAD open 16F877A.INC file in the PBP folder. It look like this
    Code:
    ;****************************************************************
    ;*  16F877.INC                                                  *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2003 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 11/07/03                                        *
    ;*  Version   : 2.45                                            *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            include 'M16F87x.INC'   ; PM header
            device  pic16F877, xt_osc, wdt_on, pwrt_on, lvp_off, protect_off
            XALL
            NOLIST
        else
            LIST
            LIST p = 16F877, r = dec, w = -302
            INCLUDE "P16F877.INC"   ; MPASM  Header
            __config _XT_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF
            NOLIST
        endif
            LIST
    now place a ; in front of theses lines
    Code:
    device  pic16F877, xt_osc, wdt_on, pwrt_on, lvp_off, protect_off
    
    __config _XT_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF
    will look like this
    Code:
    ;device  pic16F877, xt_osc, wdt_on, pwrt_on, lvp_off, protect_off
    
    ;__config _XT_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF
    default setting are now disabled.

    Now putting your configuration fuse into your program:

    If you're using PM as assembler(wich is, as i remind, the default setting in MicroCode Studio) you'll add this line in your program header

    @ DEVICE PIC16F877A, HS_OSC

    If you get some compilation error it's because you're using MPASM as assembler so use the following

    @ __config _HS_OSC

    Everything is also well explain in this thread

    What do different clock speeds mean? (LP,XT,HS,RC)
    I hate to say that but all the explanations are in the datasheet. Different oscillator setting, different possible oscillator speed.
    In your case XT is for an crystal up to 4MHZ, HS 4MHZ & up.
    Last edited by mister_e; - 19th January 2005 at 03:26.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Borisw37's Avatar
    Borisw37 Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    Thank you mister_e,
    as you can tell im a noob at PICs, just got one recently, trying to move away from Basic Stamp2 (eeek ). I will definately read through that thread, and once again thanks for your help.
    I am sure i'll have plenty more questions

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  2. Replies: 1
    Last Post: - 23rd May 2009, 09:22
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. 16f877a
    By dirkwerk in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th November 2007, 22:01
  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