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.

Newbe Help 12F629

Status
Not open for further replies.

dons21

New Member
I am new to the Pic Micro scene and am learning during my spare time, my main goal it to learn about software PWM, I have managed to learn some of the basics with www.winpicprog.co.uk.

I have successfully flashed LED's with the 16F628 but i want to use the 12F629 at the moment less ports registers etc...

I have read 'PIC in Practice by DW Smith' it is also my main learning guide, I used the following code to turn on and off GPIO 1 pin 6.
;HEADER FOR 12F629

;

;

;

;



TMR0 EQU 1 ;TMR0 is FILE 1.

TRSIO EQU 85H

GPIO EQU 5 ;GPIO is FILE 5.

STATUS EQU 3 ;STATUS is FILE 3.

ZEROBIT EQU 2 ;ZEROBIT is FILE 2.

GO EQU 1

OPTION_R EQU 81H

CMCOM EQU 19H

OSCCAL EQU 90H

COUNT EQU 20H ;USER RAM LOCATION



;*******************************************************

LIST P=12F629

ORG 0

GOTO START

;*******************************************************

;Configuration Bits

_CONFIG H'3F84'





;*******************************************************

;SUBROUTINE SECTION

;1/100 SECOND DELAY

DELAY CLRF TMR0 ;START TMR0

LOOPA MOVF TMR0,W ;READ TMR0 IN W

SUBLW .39 ;TIME - W

BTFSS STATUS,ZEROBIT ;CHECK TIME-W=0

GOTO LOOPA

RETLW 0 ;RETURN AFTER TMR0=39



;P1 SECOND DELAY

DELAYP1 MOVLW .10

MOVWF COUNT

TIMEC CALL DELAY

DECFSZ COUNT

GOTO TIMEC

RETLW 0

;**********************************************************

;CONFIGERATION SECTION



START BSF STATUS,5 ;BANK1

MOVLW B'00001001' ;BITS 0,3 ARE I/P

MOVWF TRISO



MOVLW B'00000111'

MOVWF OPTION_R ;PRESCALER is /256



CALL 3FFH

MOVWF OSCCAL ;Calibrates 4MHZ oscillator



BCF STATUS,5 ;BANK0



MOVLW 7H

MOVWF COMCON

CLRF GPIO

;***********************************************************

;Program Starts Now.

BEGIN MOVLW B'00000010' ;turn on LED1

MOVWF GPIO

CALL DELAYP1

MOVLW B'00000000' ;TURN OFF LED1

MOVWF GPIO

CALL DELAYP1

GOTO BEGIN

END

I keep getting errors with the compiler MPLAB IDE. Where am I going wrong, please don't post the answer, point me in the right direction I want to learn and not be showen.

Also when using the tutorials on www.winpicprog.co.uk for the 16F628 the code does not use the EQUates section, why is it in all the code examples in my 'PIC in practice book' ?

Is it because some compilers don`t know where the GPIO or STATUS registers are?

Thanks for any help
 
First always use the include file
include <p16F629.inc>
it's a standard text file (worth a look at)
Then use the proper name not address (the include file will make that work)
so
bsf STATUS, 5 becomes bsf STATUS, RP0

What errors are you getting?

This simple program should flash an LED on GP1 (modified from my Inchworm Quick Project poster)
Code:
  [FONT=Crystal];*** WDT reset toggles GP1[/FONT]
  [FONT=Crystal]     
   list     p=12F629
   include <p12F629.inc>
   __CONFIG 0x3FBC
   org      0
   movlw    b'00001110'
   option
   movlw    b'11111101'
   tris     GPIO
   movlw    b'00000100'
   xorwf    GPIO, f
   sleep
   end[/FONT]
Hey Nigel when did you get the forth green square...
 
Last edited:
Your errors are caused by label mismatches and incorrect use of the config directive.

Config should be proceeded by 2 underscore characters - you only have 1.
The label for the tris register is TRSI0 in the equates but in the code it is TRIS0. Same with CMCOM and COMCON.

As mentioned above, the best way is to use the supplied equate file. You should also consider using the supplied template file in "C:\Program Files\Microchip\MPASM Suite\Template\Code" called 12F629TEMP.ASM

Mike.
 
Also, once you have the code assembling, you may have problems with the call to 0x3ff. This location should contain a retlw instruction. Some programmers write over this value and this causes your code to crash.

The simplest way to fix this is to remove these two lines,
Code:
	CALL	3FFH
	MOVWF	OSCCAL ;Calibrates 4MHZ oscillator

Mike.
 
Thanks for all the help, but I am still unable to get anything to work (turn on/off, flash a led on any of the GPIO ports).

Maybe I have a bad chips, (i have tryed the code on two of them) or maybe it is the programmer i have been using. The JDM it has been working fine for the 16F628.

Is there a programmer i should use instead.

once again thanks for all the help.
 
First always use the include file
include <p16F629.inc>
it's a standard text file (worth a look at)
Then use the proper name not address (the include file will make that work)
so
bsf STATUS, 5 becomes bsf STATUS, RP0

What errors are you getting?

This simple program should flash an LED on GP1 (modified from my Inchworm Quick Project poster)
Code:
  [FONT=Crystal];*** WDT reset toggles GP1[/FONT]
  [FONT=Crystal]     
   list     p=12F629
   include <p12F629.inc>
   __CONFIG 0x3FBC
   org      0
   movlw    b'00001110'
   option
   movlw    b'11111101'
   tris     GPIO
   movlw    b'00000100'
   xorwf    GPIO, f
   sleep
   end[/FONT]
Hey Nigel when did you get the forth green square...

hey i am trying to find the header file fo rthe pic16f629 so to see it but i cannot locate it.. where is it saved? thanks
 
hey i am trying to find the header file fo rthe pic16f629 so to see it but i cannot locate it.. where is it saved? thanks

You'll never find it it should of been 12f629 there is not a 16f629:D:D
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top