PDA

View Full Version : 1st 16F877A program in PICBasic



Borisw37
- 18th January 2005, 14:41
Hello everybody,
I recently received a programmer/development board and 16F877A microcontroller (EasyPIC2 http://www.mikroelektronika.co.yu/english/product/tools/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.

mister_e
- 18th January 2005, 16:48
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


DEFINE OSC 20

TRISB.2=0 'define PORTB.2 as output

start:
Toggle PORTB.2
PAUSE 1000
goto start

Borisw37
- 19th January 2005, 02:33
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)

mister_e
- 19th January 2005, 03:20
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

;************************************************* ***************
;* 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

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


;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 (http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=543)


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.

Borisw37
- 19th January 2005, 04:46
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