View previous topic :: View next topic |
Author |
Message |
paco Guest
|
12F629 basics (Assembler runs - CCS don't) |
Posted: Sun Jun 04, 2006 3:41 pm |
|
|
Hi all.
I have a problem, i don't use PIC12F629 from years and i have a program to migrate to CCS.... but i get a problem probably in configuration.
Why this code doesn't work? (i attach the assembler code that it works compiling with Mplab. I have check that both .hex files can be writed into the PIC with IcProg o WinPic800).
Thanks.
paco
//*********************
#include <12F629.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin enabled
#FUSES PUT //Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#use delay(clock=4000000)
void main()
{
disable_interrupts(GLOBAL);
setup_comparator(NC_NC_NC_NC);
set_tris_a(0x24); //00011000 a3 and a4 as inputs
port_a_pullups(FALSE);
while (true)
{
output_high(PIN_A5);
delay_ms(100);
output_low(PIN_A5);
delay_ms(100);
}
}
//*********************
;*********************
;Assembler... it works!
list P=12f629
#include <P12F629.inc>
radix dec
__config H'31C4' ;same fuses config than CCS code above.
PDel0 EQU 020H
PDel1 EQU 021H
rojo equ 0x05
ORG 0x00
goto inicio
ORG 0x04
inicio
;**************** BANCO 0 *******************
bcf STATUS,RP0 ;bank 0
clrf GPIO
movlw 07h ;111
movwf CMCON ;GP0/1/2 comparators configured as I/O
;**************** BANCO 1 *******************
bsf STATUS,RP0 ;bank 1
; call 3FFh
; movwf OSCCAL ; if activate doesn't works
movlw b'00011000'
movwf TRISIO ; GP0/1/2/5 output GP3/4 input
movlw 0
movwf WPU ;disable pull ups
bcf STATUS,RP0
;******************volvemos al banco
clrf GPIO
principal
bsf GPIO,rojo ;GP5 red led on
call Del500 ;wait 0.5s
bcf GPIO,rojo ;GP5 red led off
call Del500 ;wait 0.5s
goto principal
;-------------------------------------------------------------
; Code generated by PDEL ver 1.0 on 04/04/2005 at 19:39:51
; Description: Waits 500000 cycles
;-------------------------------------------------------------
Del500 movlw .239 ; 1 set number of repetitions (B)
movwf PDel0 ; 1 |
PLoop1 movlw .232 ; 1 set number of repetitions (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 cycles delay
PDelL2 goto PDelL3 ; 2 cycles delay
PDelL3 clrwdt ; 1 cycle delay
decfsz PDel1, 1 ; 1 + (1) is the time over? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) is the time over? (B)
goto PLoop1 ; 2 no, loop
PDelL4 goto PDelL5 ; 2 cycles delay
PDelL5 goto PDelL6 ; 2 cycles delay
PDelL6 goto PDelL7 ; 2 cycles delay
PDelL7 clrwdt ; 1 cycle delay
return ; 2+2 Done
;-------------------------------------------------------------
END
;********************* |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 04, 2006 3:53 pm |
|
|
What is your version of the CCS compiler ? Look for the version
number at the top of the .LST file. The .LST file is in your project
folder. The version will be a number such as 3.191, 3.249, etc. |
|
|
paco Guest
|
|
Posted: Sun Jun 04, 2006 4:16 pm |
|
|
CCS PCM C Compiler, Version 3.227, 16465 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 04, 2006 4:30 pm |
|
|
I just noticed this comment in your ASM file:
Quote: | ; call 3FFh
; movwf OSCCAL ; if activate doesn't works |
The CCS compiler calls address 0x3FF. If you have accidently erased
the RETLW instruction at that address, then the program won't run.
To fix this problem, add the line shown in bold below to your CCS
program. When you program the PIC, a new "RETLW 0x80" instruction
will be placed at address 0x3FF. I picked 0x80 as the value, because
the 12F629 data sheet says it's the value for "center frequency".
So it may not give you exactly 4 MHz for the oscillator frequency, but
it will be close, and it should still work.
Quote: | #use delay(clock=4000000)
#rom 0x3FF = {0x3480}
void main()
{ |
|
|
|
paco Guest
|
|
Posted: Sun Jun 04, 2006 4:56 pm |
|
|
I tried this after search and search the web but i get an error while programming the pic.
With WinPic800 v.3.58
'Error writting address 0x0003FF
Write 0x3480 Read 0x3FAF'
With IcProg 1.05D
'Code Error in address 0000h !'
Paco
PS: I don't need exactly 4Mhz, this is not a problem. |
|
|
paulf1965 Guest
|
|
Posted: Sun Jun 04, 2006 4:59 pm |
|
|
You are setting the TRIS registers incorrectly in the C code. set_tris_a(0x24) sets pin 5 as an input. Should you be using 0x15 instead? |
|
|
paulf1965 Guest
|
|
Posted: Sun Jun 04, 2006 5:00 pm |
|
|
Sorry - should have been 0x14 instead (typo) |
|
|
paco Guest
|
|
Posted: Sun Jun 04, 2006 5:11 pm |
|
|
24 in binary is 000000000011000 where (reverse order)
0 - GP0
0 - GP1
0 - GP2
1 . GP3
1 - GP4
0 - GP5
0 - no more pins
0 - no more pins
.....
So GP5 is output... check with the assembler program, it's the same config and the asm it works fine.
but thaks.
Paco. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 04, 2006 5:56 pm |
|
|
Quote: | I tried this after search and search the web but i get an error while programming the pic.
With WinPic800 v.3.58
'Error writting address 0x0003FF
Write 0x3480 Read 0x3FAF'
With IcProg 1.05D
'Code Error in address 0000h !' |
Somehow, you need to fix this problem and get the proper value
programmed at address 0x3FF. Either get a new programmer,
or get a new 12F629.
It's possible that either WinPic800 or IcProg erased or damaged
the value at 0x3FF. If you use MPLAB with ICD2 or some other
Microchip programmer, then MPLAB will protect address 0x3FF.
It won't let you erase it. |
|
|
paco Guest
|
|
Posted: Sun Jun 04, 2006 7:09 pm |
|
|
I'm trying a lot of changes in the configuration of both programs... with icprog i finally program a pic but... is a ramdom proccess until i recognize where is the problem because i have modified delay times, Vcc control and.... Bandgap...
¿what is Bandgap in the 12F629? |
|
|
paco Guest
|
|
Posted: Mon Jun 05, 2006 5:38 am |
|
|
It have not a system to do it, i try and try changing bandgap, selecting (or deselecting "real time") in the icprog, activating and desactivating Vcc control... one of each five times (aprox) the pic is written correctly but doesn't work repeating the parameters... ¿?¿?¿?
But ok, this is an error of my software or programmer but... it is a secondary problem, the main one is that CCS need to write (or to access) to this address (0x03FF)... and one of the solution is your option to add.
#rom 0x3FF = {0x3480}
This is for PIC12F629 and the last value '80' is the standard value to get 4Mhz but must be adjusted for each pic.
Many thanks 'PCM programmer'... next week i'll get a new pic writer to change my older TE20 and i hope not to get this error.
Regards.
Paco. |
|
|
paulf1965 Guest
|
|
Posted: Mon Jun 05, 2006 12:14 pm |
|
|
Was late last night and my maths was screwy but point I was trying to make is valid.
In assembler:
movlw b'00011000'
movwf TRISIO ; GP0/1/2/5 output GP3/4 input
OK so you are moving 0001 1000 into the TRIS for the port which corresponds to
7 6 5 4 3 2 1 0
O O O I I O O O
0001 1000 in hex is 0x18 NOT 0x24
0x24 in binary in 0010 0100 which corresponds to
7 6 5 4 3 2 1 0
O O I O O I O O
Thus setting pin 5 as an input. This may not be the only problem and sorry for confusing the issue with my rubbish maths.
Paul. |
|
|
|