View Full Version : Question Pic change
FelippeRocco
Jul 23, 2007, 08:02 PM
Hey guys
If I want to change a Pic12C509 to 12F675, the mod in the asm is like below?
list p=12c509a
include "p12c509a.reg"
__config 0x000a
To
list p=12f675
include "p12f675.reg"
__config 0x000a
Thanks!
Felippe
Malc C
Jul 24, 2007, 04:07 AM
I'm no expert, but I don't think its as simple as changing the device in the list / include comamnd. Check the datasheet for comparaison between the two chips as you may need to set the ports up differently on the 675
Bruce Abbott
Jul 24, 2007, 07:42 AM
As well as including the correct register definitions, there are a few hardware changes that you need to account for:-
- Different Config options.
- File Registers start at address 32, not 7.
- Weak pullup enable is bit 7 in the Option Register, not bit 6.
- You must Call the last program address (0x3ff) to get the OSCAL value.
- Analog inputs and the comparator are enabled on startup, you must disable them to use digital I/O.
Here's some sample code that accomodates both chips:-
ifdef __12C509
PROCESSOR PIC12C509
INCLUDE <P12C509.inc>
__CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
endif
ifdef __12F675
PROCESSOR PIC12F675
INCLUDE <P12F675.inc>
__CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_BODEN_ON&_INTRC_OSC_NOCLKOUT
endif
radix dec ; decimal numbering
ifdef __12C509
CBLOCK 7
else
CBLOCK 32 ; user RAM starts here
endif
MyVar1 ; 1st RAM location
MyVar2 ; 2nd "" ""
ENDC
;--------------------------------------------------------------------------
; Bits to be set with the OPTION instruction
;--------------------------------------------------------------------------
; bit function state
;------ ------------------------- --------------
; 7 Weak Pullups (12F6xx) 1=inactive
; 6 Weak Pullups (12C50x) 1=inactive
; 5 Tmr0 clock source 0=internal
; 4 Tmr0 clock edge 0=low->high
; 3 Prescaler assign 0=timer
; 2 }
; 1 }prescaler divide 111=1:256
; 0 }
; 76543210
#DEFINE OptionBits B'11000111'
;---------------------------------------------------------------------------
; I/O directions
;---------------------------------------------------------------------------
; 543210
#DEFINE TrisBits b'000100' ; '0' = output
ORG 0
; get oscillator calibration value and use it to fine-tune clock frequency.
; 12C508/9 has value in W at startup, 12F629/75 gets it from RETLW at 0x3ff.
ifdef __12C509
ifdef OSC_CAL
movlw OSC_CAL
endif
movwf OSCCAL ; set oscillator calibration value
else
bsf STATUS,RP0 ; register bank 1
call 0x3ff ; get OSCCAL value
movwf OSCCAL ; set oscillator calibration
bcf STATUS, RP0 ; register bank 0
endif
ifdef __12C509
clrwdt
movlw OptionBits
OPTION
else
clrwdt
bsf STATUS,RP0 ; register bank 1
movlw OptionBits
movwf OPTION_REG
bcf STATUS,RP0 ; register bank 0
clrwdt
endif
; initialise I/O registers
ifdef __12C509
clrf GPIO ; all outputs low
movlw TrisBits
TRIS GPIO ; set I/O pin directions
else
clrf GPIO ; all outputs low
bsf STATUS,RP0 ; register bank 1
movlw TrisBits
movwf TRISIO ; set I/O pin directions
ifdef ANSEL
clrf ANSEL ; disable analog inputs
endif
bcf STATUS,RP0 ; register bank 0
movlw b'00000111'
movwf CMCON ; Comparator off
endif
; CPU specific stuff done, now we can start the main program!
goto Main
FelippeRocco
Jul 24, 2007, 10:46 AM
Ok, so I only have to add this lines in the .asm, and it will work with the 2 devices??
The archive that I have here don't have these lines:
INCLUDE <P12C509.inc>
__CONFIG _MCLRE_OFF&_CP_OFF&_WDT_ON&_IntRC_OSC
It have these:
include "p12c509a.reg"
__config 0x000a
And then the program begins...
there's no CBLOCK comand to set to 32 too...
Sorry guys, but I don't understand nothing about programing, the only thing I learned is Paschal...and it was a few years ago...
I'm trying to use a Flash pic instead a OTP cause it saves a lot of money if something go wrong, and I can learn with my errors without throw out the device...
I convert a .hex file in a .asm file using the Picdis, and I think that maybe the lines with the config comands...
Thanks for the help
AndyKunz
Jul 24, 2007, 01:10 PM
Use the disassembler's output for the code portion, but for the fuses (config bits) you should go directly to the hex file and look at what it sticks at those addresses. (Hex file parsing is easy - google for "intel hex" to find Intel's PDF on how it works). Compare that to the Microchip datasheet.
If you know nothing about the chip, the best way to get yourself some reprogrammability is probably to get yourself a 12C509/JW - it's an 8-pin DIP, ceramic, with window. They can be erased under UV light. It's exactly a 12C509 in all other areas.
Are you going to be improving somebody's product?
Andy
FelippeRocco
Jul 24, 2007, 06:13 PM
Is not improving...is adapting...
I'm trying to use another pic in the hex file of a magnetic actuator driver designed by Mr. Koichi Tanaka, from Japan...the hex is hosted in this place:
www.oyajin.jp/~toko/pic/0040/index.html
translated:
http://translate.google.com/translate?u=www.oyajin.jp%2F%7Etoko%2Fpic%2F0040%2 Findex.html&langpair=ja%7Cen&hl=pt-BR&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools
I have the 12f675 device with me now, so it's easier to me try to program with these device instead go out and buy the 12c509a...
Zlatko
Jul 24, 2007, 07:28 PM
Felippe,
12F509 works with 12C509 code as is. You can use 12F509 with the programmer for your 12f675. As far as I know, Koichi has not released his source code to the public.
As a bonus, if you want to go really small, 12F509 comes in 2mm x 3mm DFN / MC body ;)
I am running Koichis code on the 12F509...
If you wish, search for Martins YAPP code ( indoor forum ), that will run on the 12F675 and you also get the source code. Martins code does automatic shift selection, channel assignment ...etc ... so its independant of they TX brand. One code does all.
I have also run Bruce Abbotts actuator code on a 12F509 without a problem.
Martins YAPP
http://www.rcgroups.com/forums/showthread.php?t=383299
Bruce Abbotts code
http://homepages.paradise.net.nz/bhabbott/magnetic.html
Cheers
FelippeRocco
Jul 24, 2007, 08:56 PM
Ok Zlatko, I will try Bruce's code, on a 12f675...
Do you know the wiring diagram for it?
Another thing, Do I have to make some editing in the source code to use it, or just write the program in the pic?
Thanks for the help
Malc C
Jul 25, 2007, 03:52 AM
Another thing, Do I have to make some editing in the source code to use it, or just write the program in the pic?
Thanks for the help
If the code was written for the 12F675 then simply load the hex into the PIC - you shouldn't need to alter anything.
Bruce Abbott
Jul 25, 2007, 06:17 AM
Here is the circuit I used with my 'Mag3' code, to convert a GWS R-4P receiver for use with actuators. If you have high resistance actuators (>=200 Ohms) you can eliminate the TC4427 buffers and wire the actuators straight into the PIC.
FelippeRocco
Jul 25, 2007, 10:43 AM
Thanks Bruce, but I'm using a Berg, and I'm thinking in use the Mag1 code (servo to magnetic actuator)...
I don't know how to read the code to obtain the correct wiring, so, can you tell me how to wire this?
Thanks again.
Bruce Abbott
Jul 26, 2007, 05:59 AM
The Mag1 circuit is very simple, the only components required are the PIC and a couple of power conditioning caps. It will drive a 100 Ohm actuator (~40mA output current).
FelippeRocco
Jul 26, 2007, 02:57 PM
Thank you very much Bruce!!!
vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.