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.

????

Status
Not open for further replies.

hjl4

Member
Why is this not working?
Is chip kapput?

I have a 12f629 that refuses to flash simple led(green) with 330ohm resistor, tied into GP0. or GPIO,0. This is my 50th time, with no success.
I'm using a JDM programmer, and ICProg reports everytime, that everything OK.
I read the chip before trying anything out, and everything seems OK.

Here is the program.


; This file is a basic code template for assembly code generation *
; on the PICmicro PIC12F29. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. If the internal RC oscillator is not implemented *
; then the first four instructions following the label 'main' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PICmicro data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************

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.






;This program will blink a LED connected to pin 7 17-12-2005


fileA equ 26h
fileB equ 27h
fileC equ 28h

; bits on GPIO

pin7 equ 0 ;GP0 output to LED
pin6 equ 1 ;GP1
pin5 equ 2 ;GP2
pin4 equ 3 ;GP3
pin3 equ 4 ;GP4
pin2 equ 5 ;GP5



Start org 0x0000 ;program starts at location 000
nop
nop
nop
nop ;NOPs to get past reset vector address
nop
nop


SetUp bsf STATUS, RP0 ;Bank 1

movlw b'10000110' ;Turn off T0CKI, prescale for TMR0 = 1:128
movwf OPTION_REG

movlw b'00110111' ;Set GP0 (pin 7) as output
movwf TRISIO


;calibrating the internal oscillator


call 0x3ff ;get the calibration value
movwf OSCCAL ;calibrate oscillator
bcf STATUS, RP0 ;bank 0

clrf GPIO ;Clear GPIO of junk


LED bsf GPIO,pin7 ;turn on LED
call Del
bcf GPIO,pin7 ;turn off LED
call Del
goto LED



;Delay 1 sec

Del movlw 40h
movwf fileC
DelX decfsz fileA,1 ; ,1 denotes the result of the decrement
goto DelX
decfsz fileB,1 ; is placed in the file
goto DelX
decfsz fileC,1
goto DelX
retlw 00



;OSCCAL calibration value

org 0x3ff
movlw 0x20


end





any help would be appreciated.
 
hjl4 said:
Why is this not working?
Code:
	call	0x3ff		;get the calibration value
        .....
        .....
	;OSCCAL calibration value

	org	0x3ff
	movlw	0x20        ;shouldn't this be retlw 0x20 ?
	end

When you call 0x3ff, did the program return?
 
Well spotted! - the program will never work, as it will continually be restarting from 0x000 as the program counter loops round - and even worse, the stack will rapidly overflow as well. In either case, the program itself will never run!.
 
I give up, I tried your suggestions, and nothing works.

I mean how hard can it be. 5v to vdd, vss tied to ground, and led connected to
gp0.

I'm stumped.
Reason for using f629, was so I would'nt have to screw around interupts and comparators ect....

I'm open to suggestions.
 
hjl4 said:
;OSCCAL calibration value

org 0x3ff
movlw 0x20

You are overwriting the calibration value? Location 0x3ff already contains a RETLW instruction with the cal. value when the PIC is shipped and it shouldn't be overwritten/erased. To calibrate the oscillator you have to select BANK 1 and call 0x3ff. After that, the W register contains the cal. value; move it to the OSCCAL register and then select BANK 0.
 
Ok , I accidentely erased oscillator cal value, first day I had the chip, two years ago.
Thats why I tried to write new value in there.

Using advanced option to post code, Where is the magic button???

but anyhow, here is revised 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.






;This program will blink a LED connected to pin 7 17-12-2005


fileA equ 26h
fileB equ 27h
fileC equ 28h

; bits on GPIO

pin7 equ 0 ;GP0 output to LED
pin6 equ 1 ;GP1
pin5 equ 2 ;GP2
pin4 equ 3 ;GP3
pin3 equ 4 ;GP4
pin2 equ 5 ;GP5



Start org 0x0000 ;program starts at location 000
nop
nop
nop
nop ;NOPs to get past reset vector address
nop
nop


SetUp
bsf STATUS, RP0 ;Bank 1

movlw b'10000110' ;Turn off T0CKI, prescale for TMR0 = 1:128
movwf OPTION_REG

movlw b'00110111' ;Set GP0 (pin 7) as output
movwf TRISIO

call 0x3ff ;get the calibration value
movwf OSCCAL ;calibrate oscillator
bcf STATUS, RP0 ;bank 0

clrf GPIO ;Clear GPIO of junk


LED bsf GPIO,pin7 ;turn on LED
call Del
bcf GPIO,pin7 ;turn off LED
call Del
goto LED



;Delay 1 sec

Del movlw 40h
movwf fileC
DelX
decfsz fileA,1 ; ,1 denotes the result of the decrement
goto DelX
decfsz fileB,1 ; is placed in the file
goto DelX
decfsz fileC,1
return



;OSCCAL calibration value

org 0x3ff
retlw 0x20


end
 
BTW, there are no errors from compiler or the JDM programmer, after everything is said and done.
Yes I have 5volts dc on vdd, and vss tied to ground.
Is there anyway to check for dead chip????
 
I don't know where you got that code from because it doesn't work. The equates (pin7 equ 0 ;GP0 output to LED) make it very confusing to read and have probably caused someone to incorrectly assume that resetting bit 7 of TRISIO will set GP0 to input. Try setting trissio to b'00110110' and that should fix it.

BTW, the Go Advanced button is next to the Post Quick Reply button.

Mike.
 
OK Pommie,

That piece of code was taken from TE interactive site. blink.asm.

I will now try to paste my code on here.
This code also always fails.

As for Go advanced , I did that, and nowhere can I find a way to paste 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

COUNT equ 0x25
COUNT2 equ 0x26


; 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
nop
nop
nop
movlw 0x80
movwf COUNT
movwf COUNT2

initialize
bsf STATUS, RP0 ;back to bank 1
movlw 0x08 ;move literal 08h to w
movwf TRISIO ;set GP3 as only input.GP5, GP4, GP2, GP1 AND GP0 are all outputs.
bcf STATUS, RP0 ;return to bank 0


start

bsf GPIO, 0
call DELAY
bcf GPIO, 0
call DELAY
goto start



DELAY

LOOP1 decfsz COUNT,1
goto LOOP1
decfsz COUNT2,1
goto LOOP1
return




org 0x3ff
retlw 0x20

END ; directive 'end of program'



Ooops, maybe I just did.
 
Why are you posting different code? I told you what was wrong with the previous code. Try doing the change I suggested.

Also, I just noticed your delay routine is flawed.
Add this line,
Code:
Del	movlw 40h
	movwf fileC 
DelX 
	decfsz fileA,1 ; ,1 denotes the result of the decrement 
	goto DelX 
	decfsz fileB,1 ; is placed in the file 
	goto DelX
	decfsz fileC,1
	goto	DelX ;  <------ add this line
	return

Note how much easier the code is to read. The code tags are accessed via the # symbol.

Mike.
 
Ok Pommie

Thanks.

I changed code, as the one you modified, or the one previous, did not work, even with the changes you told me to implement.

Its Ok, I will abandon this chip, and try a 12f675 or something.

Thanks for telling me where code button is.
I just have to learn how to use it now.
 
hjl4,

Look like you are bitten by the CMCON bug. It is very common and many PIC users suffer from its effect.

However, one bitten, you would be immunized for your whole life.

Someone lucky would inject 0x07 into CMCON immediately right at the start of program to stop it from causing trouble later.
 
I didn't even bother to check if the 629 had comparators or not as the OP stated "Reason for using f629, was so I would'nt have to screw around interupts and comparators ect...." !!

However, shouldn't the above have worked anyway as when you set the pin to output, it can only be a digital output (the diagram for GP0 suggest that to be the case). I know that on earlier chips this was definitely the case. I had one case with a 818 where the ADC would only read from 500 - 1024 with a pot on the input because I forgot to switch to input and had inadvertently set the bit.

Mike.
 
Pommie said:
However, shouldn't the above have worked anyway as when you set the pin to output, it can only be a digital output (the diagram for GP0 suggest that to be the case).

I have also checked the GP0 block diagram before I did the above post and I'm also troubled as it did not show that CMCON would actually affect the GP0 if it is configured as output.

However, in the datasheet on section GPIO Port "initializing GPIO", Microchip did explicitly show sample code setting up GPIO as digital I/O by writing 0x07 to CMCON.

Therefore I have concluded to myself that the block diagram of GP0 is missing something important. That after reset the pin is in "Analoge" mode and nothing will come out even if one set the pin direction to "output". It is in an imaginary "analogue output" state instead of the digital output one wanted.

I have not tried to prove my theory otherwise as I always used the CMCON=7 and everything works as expected.

Any test/experience results that CMCON=0 and GP0 works as digital output is welcome.
 
So here is my original code, before all this screwing around.

All other codes that I posted, is because I thought I was doing something wrong, even when following datasheet instruction.
If this does,nt work, then I don't know.


[ 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

COUNT equ 0x25
COUNT2 equ 0x26


; 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
nop
nop
nop
movlw 0x80
movwf COUNT
movwf COUNT2

initialize
bcf STATUS, RP0 ;back to bank 1
clrf GPIO
movlw 0x07
movwf CMCON
bsf STATUS, RP0
movlw 0x08 ;move literal 08h to w
movwf TRISIO ;set GP3 as only input.GP5, GP4, GP2, GP1 AND GP0 are all outputs.
bcf STATUS, RP0 ;return to bank 0


start

bsf GPIO, 0
call DELAY
bcf GPIO, 0
call DELAY
goto start



DELAY

LOOP1 decfsz COUNT,1
goto LOOP1
decfsz COUNT2,1
goto LOOP1
return




org 0x3ff
retlw 0x20

END ; directive 'end of program' ]

Looks like I also need help with (wrapping) CODE tags.
Can't figure that out either.

Thanks for all the help.
 
hjl4 said:
I will abandon this chip, and try a 12f675 or something.

With the PIC12F675 you have to care of addinional settings (ANSEL=0), if you don't use the ADCs and also the CMCOM registes should be loaded with 0x07, as suggested.

I wonder if your PIC is held in the reset state by the Power Reset feature? I would disable this function and remove the calibration routine.
You can also try to run a program with an external RC oscillator and see if the uC is damaged or not.
 
Thanks everybody.

To my amazement, it finally worked.
All this time, I thought my original code was wrong.
So I went to TE Interactive, took their code and was lost from there.
It now works.

The trick was turning comparators off.
Which I had tried previously but nothing worked.
I'm so happy I did'nt throw this chip out.

I, think I'll let this thing flash for an hour or two.
Now on to the real project of controlling a stepper motor with it.

Again, thank you all.
 
Another lesson you should have learned: the MPLAB simulator could have saved you a TON of time an frustration!

You could have watched it overflowing the stack and looping through all program memory, seen with the stopwatch that your delay routine wasn't correct, and perhaps most importantly, seen that your output pin wouldn't be changing.

If you're just now getting to flash an LED, and your next goal is controlling a stepper motor, it would probably be a very good idea for you to get familiar with simulation.
 
Same like PIC12f629 prob...... when u program 12c508a & PIC16f628a when selecting internal oscillator do u need to write the OSCCAL codes in the program....or can u wright the main code by ignoring that OSCCAL codes ?????bcuz I got stucked in programing 508a wasted about 4 chips.......
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top