Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 12th November 2007, 11:06 PM   (permalink)
Default Newbe Help 12F629

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
dons21 is offline  
Old 12th November 2007, 11:14 PM   (permalink)
Default

If it can't find the equates file, then perhaps the DOS path isn't set correctly? - move the offending equ file to the same directory as the source code.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 12th November 2007, 11:18 PM   (permalink)
Default

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:
 ;*** WDT reset toggles GP1      
   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
Hey Nigel when did you get the forth green square...
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com

Last edited by blueroomelectronics; 13th November 2007 at 05:43 AM.
blueroomelectronics is online now  
Old 13th November 2007, 02:19 AM   (permalink)
Default

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.
Pommie is offline  
Old 13th November 2007, 02:24 AM   (permalink)
Default

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.
Pommie is offline  
Old 16th November 2007, 04:46 PM   (permalink)
Default

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.
dons21 is offline  
Old 26th November 2007, 07:56 AM   (permalink)
Default

Problems fixed it was the JDM programmer not programming the chip.

I built P16PRO40 programmer from www.winpicprog.co.uk.

Much better than the JDM.
dons21 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Low voltage alarm - 12f629 samtheboxer Micro Controllers 9 25th July 2007 04:09 PM
Need help to interface a ps/2 mouse with 12f629 iamyanh Micro Controllers 3 29th November 2006 06:06 AM
changing chips, 12C508A to 12F629..... SnM Micro Controllers 3 5th May 2004 02:38 PM
Weird 12F629 GPIO setting? eirikr Micro Controllers 3 14th March 2004 05:08 AM
Can JDM program 12F629? Do I need an adapter? eirikr Micro Controllers 7 13th March 2004 04:08 AM



All times are GMT. The time now is 12:53 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker