Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ARGH! PIC12F629 help please =D

Status
Not open for further replies.

Peter_wadley

New Member
Hey,

I just received my JDM programmer which came with a 12F629 chip.

I have been trying for 4 hours to get this chip to blink an LED with assembly BUT I CANT :mad:

Every tutorial I have found has been no help..

I have read through half of the DATASHEET but have not yet understood how to set up the Ports and the internal osc...

I think I may have erased the factory OSC setting for internal OSC also :D

Can anyone please post the assembly code which sets up the ports... turns off the comparators and sets up the internal 4mhz OSC..

Thanks so much-a!

Peter Wadley
 
A good starting point is the template files supplied by Microchip. You'll find them in C:\Program Files\Microchip\MPASM Suite\Template\Code or the equivalent on your system. The template sets up the config to use the internal osc and has the calibration code included.

To write to the port you need to setup the comparators and data direction register.
Code:
		movlw	0x07		;turn comparators off
		movwf	CMCON
		bsf	STATUS,RP0
		movlw	b'00000000'	;0 = input
		movwf	TRISIO
		bcf	STATUS,RP0

You can then write to the port,
Code:
		movlw	0x55
		movwf	GPIO
You also want somewhere for the program to go when it gets to the end,
Code:
hang		goto	hang
If you have messed up the calibration value then you need to put it back,
Code:
		org	0x3ff
		retlw	0x80

Your complete code should end up like,
Code:
;**********************************************************************

	list      p=12f629           ; list directive to define processor
	#include <p12f629.inc>        ; processor specific variable definitions

	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT  

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.




;***** VARIABLE DEFINITIONS
w_temp        EQU     0x20        ; variable used for context saving 
status_temp   EQU     0x21        ; variable used for context saving






;**********************************************************************
		ORG     0x000             ; processor reset vector
		goto    main              ; go to beginning of program


		ORG     0x004             ; interrupt vector location
		movwf   w_temp            ; save off current W register contents
		movf	STATUS,w          ; move status register into W register
		movwf	status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


		movf    status_temp,w     ; retrieve copy of STATUS register
		movwf	STATUS            ; restore pre-isr STATUS register contents
		swapf   w_temp,f
		swapf   w_temp,w          ; restore pre-isr W register contents
		retfie                    ; return from interrupt


; these first 4 instructions are not required if the internal oscillator is not used
main
		call    0x3FF             ; retrieve factory calibration value
		bsf     STATUS,RP0        ; set file register bank to 1 
		movwf   OSCCAL            ; update register with factory cal value 
		bcf     STATUS,RP0        ; set file register bank to 0

		movlw	0x07		;turn comparators off
		movwf	CMCON
		bsf	STATUS,RP0
		movlw	b'00000000'	;0 = input
		movwf	TRISIO
		bcf	STATUS,RP0

		movlw	0x55
		movwf	GPIO

hang		goto	hang


		org	0x3ff
		retlw	0x80


; initialize eeprom locations

		ORG	0x2100
		DE	0x00, 0x01, 0x02, 0x03



		END                       ; directive 'end of program'

HTH

Mike.
 
Just noticed a mistake in the comment above, I wrote "0=input" when it should have said "0=output".

Mike.
 
The Oscillator value is normally stored at location 0x3ff and should be saved before the chip is erased. If it is accidentally erased then the only thing you can do is to set it to a midway point. Midway = 0x80. You can recalibrate the chip be setting the Oscillator to _INTRC_OSC_CLKOUT and measuring the frequency coming out of GP4.

Mike.
 
:mad: Argh, I still cant program this chip:mad:


I have tried so many different thing but the chip just wont take the darn code!!!

Ive used IPROG, Nigels program and PONY

The Programmer Worked for my 16f84a though!

Im sure I have it in the socket correctly too.

Here is the programmer im using:

**broken link removed**

When ever I try to program it it says:


No "Oscillator Calibration Value" found.
Do you want to use value from file (3480h) instead?

Yes - No - Cancel

Ive chosen Yes and No - many many times and have kept getting the infamous:

Verify failed at address 0000h!

error message (iprog)


------

I just changed the hardware from direct I/O to windows API

I can now save code on it and then read it back to make sure it is actually on the chip..

but its not blinking the LED..

can someone post code blink an LED with this chip?

I dont know but im stumped on this one.. time to rest!

take care
 
Ok Now I understood.

If I erase my PIC12F629 with the OSCAL value.
When Next time if I want the 4MHZ frequency what’s the value do I have to write to the 0x3ff location? Is it still 80?

Thanks again
 
Here is some code which should flash any LEDs on the port.
Code:
;**********************************************************************

	list      p=12f629           ; list directive to define processor
	#include <p12f629.inc>        ; processor specific variable definitions

	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT  

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.


		cblock	0x22
Count
Count2
		endc



;***** VARIABLE DEFINITIONS
w_temp        EQU     0x20        ; variable used for context saving 
status_temp   EQU     0x21        ; variable used for context saving






;**********************************************************************
		ORG     0x000             ; processor reset vector
		goto    main              ; go to beginning of program


		ORG     0x004             ; interrupt vector location
		movwf   w_temp            ; save off current W register contents
		movf	STATUS,w          ; move status register into W register
		movwf	status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


		movf    status_temp,w     ; retrieve copy of STATUS register
		movwf	STATUS            ; restore pre-isr STATUS register contents
		swapf   w_temp,f
		swapf   w_temp,w          ; restore pre-isr W register contents
		retfie                    ; return from interrupt


; these first 4 instructions are not required if the internal oscillator is not used
main
		call    0x3FF             ; retrieve factory calibration value
		bsf     STATUS,RP0        ; set file register bank to 1 
		movwf   OSCCAL            ; update register with factory cal value 
		bcf     STATUS,RP0        ; set file register bank to 0

		movlw	0x07		;turn comparators off
		movwf	CMCON
		bsf	STATUS,RP0
		movlw	b'00000000'	;0 = input
		movwf	TRISIO
		bcf	STATUS,RP0

		movlw	0x55
		movwf	GPIO

Loop		movlw	0xff
		movwf	GPIO
		call	Delay
		clrf	GPIO
		call	Delay
		goto	Loop

hang		goto	hang


Delay		movlw	0x02
		movwf	Count2
		movlw	0
		movwf	Count
DelLoop		addlw	1
		btfss	STATUS,Z
		goto	DelLoop
		decfsz	Count,F
		goto	DelLoop
		decfsz	Count2,F
		goto	DelLoop
		return

		org	0x3ff
		retlw	0x80


; initialize eeprom locations

		ORG	0x2100
		DE	0x00, 0x01, 0x02, 0x03



		END                       ; directive 'end of program'

I can't test this code as I don't have a 629 handy.

Here is the hex file it produces. It's renamed txt as hex isn't allowed!!

Mike.
 
Last edited:
gramo said:
Geez assembler is so old school!

With Swordfish it’s simply done like the following code to set up the PIC and enable the internal oscillator..

Code:
Device  = 18F2620
Clock = 8
Config OSC = INTIO67


// Start of Program...

I really don't miss assembler :p

The OP only has a 12F629. The clever people who wrote Swordfish weren't clever enough to make it produce any code for the lowly 629.

Mike.
 
Hmm, your using a rather dodge programmer too!

I don't use dodgy JDM's anymore, found them to be far to unreliable!

The PICKit 2 is made by microchip, and supports almost every PIC on the market, including dsPIC's and 24F PIC's!

Its $34.95 from microchip
**broken link removed**

Anyhow, what about your wiring?
* Do you have 5V on MCLR?
* Is Vdd and Vss connected correctly?
* What is the voltage from your regulator?
* Is anything getting warm?
 
Last edited:
Pommie said:
The OP only has a 12F629. The clever people who wrote Swordfish weren't clever enough to make it produce any code for the lowly 629.

Mike.

The lowly 629 and every other 16F PIC have so many fundamental programming issues, I'm surprised they are still in use...

18F PIC's are not harder to use. Don’t get caught in this fallacy! They are 16F’s without any of the downfalls


Here's a quote from the Swordfish site;
Architecturally, the 16 series does not lend itself well to a structured high level language. It can be done - but it always involves compromising or constraining the language in some way. I accept this will impact on potential sales, but this isn't what Swordfish is about. The only absolute regarding development is that the compiler must be robust. As a code writer, you must trust the tools you use. Everything else is secondary. This is our primary objective. Finite resources means we must maintain a clear focus regarding development in order to achieve this objective.
 
If you've erased the oscillator calibration value the link below has code and a circuit that will work out what it should be so you can reprogram it.

**broken link removed**
 
gramo said:
The lowly 629 and every other 16F PIC have so many fundamental programming issues, I'm surprised they are still in use...

18F PIC's are not harder to use. Don’t get caught in this fallacy! They are 16F’s without any of the downfalls

Isn't that like arguing that small cars have no place because big cars are far superior. That students don't need to learn maths because they will always have access to a calculator.

Learning assembler gives a programmer a good understanding of what is happening at the chip level. He/She can then learn higher level languages. There is nothing wrong with high level languages, but a good grounding in assembler will produce a much better programmer, just like a good knowledge of maths will make a better engineer/accountant/physicist etc.

Your constant post of how assembler is inferior is like a university student telling a junior school teacher that she is out of date teaching the times tables as calculators can do it so much quicker/easier. We all know that but some people believe that learning times tables is worthwhile.

Sorry to the OP for going a bit of track.

Mike.
 
hi mike,
Watching this thread, just had to put in my 10cents worth.

As evolution continues to create new species.
I thought it might be an idea to coin two Latin generic names:

1. Assembler-Saurus Programmer-don, sometimes referred to the 'old guys':eek:

2. Swordus-Giveus-Abreakus, commonly known the Gramo-borus.;)

Sorry Gramo!, no offence intended.

Regards
 
Is it just me, or does anyone else think it's a bit weird to supply a 16F629 with a programmer, when it is not mentioned in the 'Devices Supported List' on the eBay listing that Peter posted.
 
geko said:
In the OP he says it's a 12F629 not a 16F629

It's actually a strange designation - because the 12F629/675 is actually a 16F series 14 bit chip.

12C series - 12 bit (fair enough, makes me happy :D )
16F series - 14 bit (getting confused now? :confused: )
18F series - 16 bit (still confused :confused: )
12F series - 14 bit (arrgh!!!!!! :rolleyes: )
 
Status
Not open for further replies.

Latest threads

Back
Top