PDA

View Full Version : first program 12f683



sparkness
- 19th April 2011, 19:51
hello group, this is my first pgm and I'm using 12f683 on breadboard with a pickit2 programmer in MPlAB IDE v.8.46 , not compiling, the compiler chokes
on this code , what simple thing am I doing wrong. I have no problem programming in ASM to this chip

'************************************************* ***************
'* 12F683.BAS *
'* *
'* By : Leonard Zerman, Jeff Schmoyer *
'* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
'* All Rights Reserved *
'* Date : 05/14/04 *
'* Version : 2.45 *
'* Notes : *
'************************************************* ***************

BANK0 $0020, $007F
BANK1 $00A0, $00BF
EEPROM $2100, $21FF
LIBRARY "PBPPIC14"
DEFINE CCP1_REG GPIO
DEFINE CCP1_BIT 2

include "PIC14EXT.BAS"

PORTL VAR GPIO
PORTH VAR GPIO
TRISL VAR TRISIO
TRISH VAR TRISIO

include "PBPPIC14.RAM"

main:
goto main

'*-----------------------* EOF 12F683.BAS *---------------------*

Output:


Executing: "C:\PBP\PBPMPLAB.BAT" -ampasmwin -k# -p12F683 "C:\PBP\12F683.BAS"
Executing: "C:\PBP\PBPW.EXE" -ampasmwin -k# -p12F683 "C:\PBP\12F683.BAS"
PICBASIC PRO(TM) Compiler 2.60, (c) 1998, 2009 microEngineering Labs, Inc.
All Rights Reserved.

C:\PBP\PIC14EXT.BAS ERROR Line 11: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 12: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 13: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 14: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 15: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 16: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 17: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 18: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 19: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 20: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 21: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 22: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 23: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 24: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 25: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 26: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 27: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 28: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 29: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 30: Redefinition of VAR.
C:\PBP\PIC14EXT.BAS ERROR Line 31: Redefinition of VAR.
FATAL ERROR: Too many errors. (21)
Halting build on first failure as requested.
BUILD FAILED: Tue Apr 19 13:32:22 2011

sparkness
- 19th April 2011, 22:26
OK, I commented out several lines to get the compiler to stop choking and added some asm to get this started


'************************************************* ***************
'* 12F683.BAS *
'* *
'* By : Leonard Zerman, Jeff Schmoyer *
'* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
'* All Rights Reserved *
'* Date : 05/14/04 *
'* Version : 2.45 *
'* Notes : *
'************************************************* ***************

BANK0 $0020, $007F
BANK1 $00A0, $00BF
EEPROM $2100, $21FF
'LIBRARY "PBPPIC14"
'DEFINE CCP1_REG GPIO
'DEFINE CCP1_BIT 2

' include "PIC14EXT.BAS"

'PORTL VAR GPIO
'PORTH VAR GPIO
'TRISL VAR TRISIO
'TRISH VAR TRISIO

' include "PBPPIC14.RAM"

ASM
BANKSEL TRISIO
MOVLW B'01100000' ;4mhz
MOVWF OSCCON
BCF TRISIO,5 ;GP5 output
ENDASM
start:
LOW PORTL.5
PAUSE 500
HIGH PORTL.5
PAUSE 501
goto start

End


'*-----------------------* EOF 12F683.BAS *---------------------*

ScaleRobotics
- 20th April 2011, 00:26
The files like 12F683.BAS are meant to be left alone. You should be naming your own file xyz.bas or xyz.pbp, or any name to your liking (that does not exist in PBP). Hopefully you made a copy of the file so you can restore 12F683.BAS back to normal.

You may sometimes have to edit some configs in files like 12F683.inc, but changing configs should be it. Don't write a program there.

mackrackit
- 20th April 2011, 00:32
If you need some examples to play with take a look here.
http://melabs.com/samples/PBP-mixed/index.htm

sparkness
- 20th April 2011, 00:44
thanks,I'm aware of that copy mistake but I dont know why I have to comment out parts of the .bas file to get it to compile with this simple test code

mackrackit
- 20th April 2011, 00:48
That was/is not test code. It is part of the "guts" of PBP just like the *.inc files in the same directory.

sparkness
- 20th April 2011, 15:07
here is the steps I have taken in MPLAB
1.click project wizard and select 12f683 and save project as test-12f683.mcp
2. copy file 12f683.bas to folder and rename it test-12f683.bas
3. click finish and project is complete
add 2 lines of code
main:
goto main

press f-10 to compile and the program chokes
then I comment out several items and now it will compile
this does not seem right

my code will run on the micro. just want make sure that this is the right way

http://www.mini-ms.com/images/4.gif
http://www.mini-ms.com/images/5.gif
http://www.mini-ms.com/images/6.gif

ScaleRobotics
- 20th April 2011, 15:14
just want make sure that this is the right way

http://www.mini-ms.com/images/4.gif



No, you are not supposed to put code in, and compile the guts of PBP, like this file. Please re-read posts above.

mackrackit
- 20th April 2011, 15:16
Again, that is not a sample or test code. You should not be trying to run it, it is a file PBP needs to help compile code.

Restore the file to its original state and try one of the smples I linked you to.

sparkness
- 20th April 2011, 15:20
so I should not add the source file 12f683.bas to the project and create an empty file called test-12683.bas in this example?

ScaleRobotics
- 20th April 2011, 15:30
You got it.

Or you can try running one from melabs, like Dave suggested.
http://melabs.com/samples/LABX4-12F68x/



' Name : BLINKX4.pbp
' Compiler : PICBASIC PRO Compiler 2.6
' Assembler : PM or MPASM
' Target PIC : PIC12F683
' Hardware : LAB-X4 Experimenter Board
' Oscillator : 4MHz internal
' Keywords :
' Description : PICBASIC PRO program to blink an LED connected
' to GPIO.0 about once a second.
'

LED Con 0 ' Alias GPIO.0 to LED

ANSEL = 0 ' Set all digital
CMCON0 = 7 ' Analog comparators off

mainloop:
Low LED ' Turn on LED connected to GPIO.0
Pause 500 ' Delay for .5 seconds
High LED ' Turn off LED connected to GPIO.0
Pause 500 ' Delay for .5 seconds
Goto mainloop ' Go back to mainloop and blink LED forever

End

sparkness
- 20th April 2011, 15:32
my mistake, I was adding the .bas file to the project
I was using the steps required for an Assembler project

midali
- 4th January 2014, 14:37
I'm back with a stupid questions. I want to turn on a led when RC signal is > 1,6ms , but my led is off all time. Please,can somebody explain me why my code not work?

1000x thx

code:

ansel = 0
wpu = 0
cmcon0 = 7
signal var word

main:

Pulsin gpio.3,1,signal
if signal > 1600 then high gpio.0

goto main
end

midali
- 4th January 2014, 15:01
i solved... the problem was from CONFIG . MCLRE must be off and measured pulse is in 10us.

#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
#ENDCONFIG

ansel = 0
wpu = 0
cmcon0 = 7
signal var word

main:

pulsin gpio.3,1,signal
if signal > 160 then high gpio.0


goto main
end

Acetronics2
- 4th January 2014, 15:52
Hi,

you also must add in your program the condition for the led to be off ...

as outputs are bistable kind ... they will stay on the last programmed state, otherwise stated ... ;)

Alain

midali
- 4th January 2014, 16:07
Thx Alain! I try to learn about microcontrolers and any info are welcome.