PDA

View Full Version : Started using PICBasic Pro 2.46



Qacer
- 24th January 2006, 22:18
Hi all,

So after reading through some literature, I decided to start playing with the PICBasic Pro compiler and a PICKit 1 programmer on a 12F675. I'm using MPLAB and have the following simple code:

TRISIO = %001000
GPIO = %110111

I compiled and programmed the device, but when I view the Special Functions Register, it says that TRISIO and GPIO are 0x00.

Can anyone help?

Thanks!

Melanie
- 25th January 2006, 08:39
The question that first springs to mind is... "How do you know if your PIC actually ran"?

I always say that like a car engine, a PIC needs three things to run. Whilst a car needs fuel air and a spark, a PIC needs CLOCK, MCLR and VOLTS. I'll assume you got the VOLTS bit correct, so that leaves CLOCK and MCLR.

How have you arranged the OSCILLATOR and MCLR settings of your 12F675 as nothing you've posted hints at this arrangement.

Next a simple error, it won't affect your PIC's running, but you'll notice that GP.3 is an INPUT ONLY pin on this PIC. You've set TRISIO correctly by indicating it's an INPUT, but you then go and spoil it by setting GPIO as an output.

Try this simple piece of code...


'
' PIC Defines
' -----------
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE pic12F675, WDT_ON
' Watchdog Timer
@ DEVICE pic12F675, PWRT_ON
' Power-On Timer
@ DEVICE pic12F675, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic12F675, BOD_ON
' Brown-Out Detect

'
' Hardware Defines
' ----------------
LED var GPIO.0

'
' Initialise
' ----------
TRISIO=%00001000
CMCON=%00000111
ANSEL=%00000000

'
' Program Body
' ------------
Loop:
Toggle LED
Pause 500
Goto Loop

End


You may compile this with the command line...

PBP -p12F675 myprog -v

Your PIC should work and toggle GPIO.0 pin at approximately 1Hz. You need do nothing else besides apply VOLTS and now MCLR and CLOCK will be taken care of internally. Go look at my usage of CMCON and ANSEL in the appropriate chapters of the PICs DATASHEET to discover why I have used them and for what purpose.

Qacer
- 25th January 2006, 20:04
Thank you very much, Melanie! I will try the code as soon as I get my system setup. I guess I was a bit confused with the TRISIO and GPIO registers. I had the though that TRISIO was used to turn the GPIO pins into input or output and that the GPIO disables or enables the pin. Am I misinformed?

Melanie
- 25th January 2006, 20:17
You are correct in what you say... but GPIO = %110111 would set all pins High except GPIO.3 which (if it were an output) set that Low. Writing to GPIO.3 is kinda non-productive. Naturally, none of this would work unless you first disable the onboard comparators and ADC's which is where CMCON and ANSEL come in.

Qacer
- 25th January 2006, 20:26
Ahh, thanks for the enlightment, Melanie. I think I did not disable the comparators and ADC. I naturally assumed that GPIO would default to general purpose inputs/outputs.

Qacer
- 26th January 2006, 16:15
Hi again, Melanie.

I tried the following code:


@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE pic12F675, WDT_ON
' Watchdog Timer
@ DEVICE pic12F675, PWRT_ON
' Power-On Timer
@ DEVICE pic12F675, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic12F675, BOD_ON
' Brown-Out Detect

CMCON=%00000111
ANSEL=%00000000
TRISIO=%00001000


GPIO = %00111111


I used MPLAB v7.30 and followed the meLabs instructions in setting up PICBasic for this software.

When I compiled the code, I got the following error:

Executing: "C:\pbp\PBPW.EXE" -ampasmwin -oq -z -p12F675 "test.bas"
PicBasic Pro Compiler 2.46, (c) 1998, 2005 microEngineering Labs, Inc.
All Rights Reserved.
Warning[207] C:\TEMP\TEST\TEST.ASM 68 : Found label after column 1. (DEVICE)
Error[122] C:\TEMP\TEST\TEST.ASM 68 : Illegal opcode (pic12F675)
Warning[207] C:\TEMP\TEST\TEST.ASM 76 : Found label after column 1. (DEVICE)
Error[122] C:\TEMP\TEST\TEST.ASM 76 : Illegal opcode (pic12F675)
Warning[207] C:\TEMP\TEST\TEST.ASM 84 : Found label after column 1. (DEVICE)
Error[122] C:\TEMP\TEST\TEST.ASM 84 : Illegal opcode (pic12F675)
Warning[207] C:\TEMP\TEST\TEST.ASM 92 : Found label after column 1. (DEVICE)
Error[122] C:\TEMP\TEST\TEST.ASM 92 : Illegal opcode (pic12F675)
Warning[207] C:\TEMP\TEST\TEST.ASM 100 : Found label after column 1. (DEVICE)
Error[122] C:\TEMP\TEST\TEST.ASM 100 : Illegal opcode (pic12F675)
Loaded C:\temp\test\test.COD.
BUILD SUCCEEDED: Thu Jan 26 11:13:19 2006


Any tips?

Bruce
- 26th January 2006, 16:37
MPASMWIN does not support the @ DEVICE config fuse directive. This is only available if you're using the PM assembler.

If you need to place the config directive in your BASIC code, and you're using MPASMWIN, this would be the equivalent.

@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _BODEN_ON

To use this in your BASIC code, you'll need to edit the 12F675.INC file in your PBP directory, and comment out the default MPASM config directive line.

The MPASM line looks like this;

LIST
LIST p = 12F675, r = dec, w = -302
INCLUDE "P12F675.INC" ; MPASM Header
;__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
NOLIST

Use the ; symbol to comment out the default config fuse line. Save the file. Now you can add the line above directly to your BASIC code.

Or just make the change to the 12F675.INC file & save it.

Melanie
- 26th January 2006, 16:42
The configuration defines I gave you are valid for the default PM Assembler. If you want to use Microchips MPASM then they have to be changed to match MPASM...

http://www.picbasic.co.uk/forum/showthread.php?t=543

Qacer
- 26th January 2006, 16:49
Ahh, I see. I actually emailed meLabs and told them about a BUILD failed error message I got when using the PM.exe file. The guy told me to stick to MPASM if I'm not experiencing any other problem.

mister_e
- 26th January 2006, 16:55
For what it worth, i always use MPASM. As i switch many times from 10,12,16,18 series, i don't spend time to switch between PM and MPASM. MPASM gives also some ASM advantage too.

If you want, read the MPASM PDF to see what you can add to PBP.

ONLY Macro is a MAIN advantage. DA,DT and other a just great too.