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.

PIC12F629 Input Problem

Status
Not open for further replies.

rojmrc

New Member
Hello Everyone,

I have a silly problem, but need help in this moment.
I need the pic to depending on the input output only to a different port
I have tried many thing so far I have this, and seems not to work
Any Ideas?

Your Help is very much appreciated!

Ps: sorry the code is not clean but I have tried quite a few things already

This is what I have
Code:
;--------------------------------------------------------------------------

	list	p=12F629

	#include<p12f629.inc>
	
	ERRORLEVEL -302     ;remove messages 

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

	
				; globals
 ;filedif equ 	20h	;this is the first available file
 ;		equ 	21h
 ;		equ 	22h
;		equ 	23h
 ;		equ 	24h
;		equ		25h

fileG equ 29h ; test file 

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

				; bits on GPIO
				
pin7		equ	0	;GP0  
pin6	 	equ	1	;GP1
pin5		equ	2	;GP2
pin4		equ	3	;GP3 
pin3		equ	4	;GP4 
pin2		equ	5	;GP5 
		
input 		equ 0x80	;input register
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	0x18	;Set GP0,1,2,5 as outputs. GP04 as input
	movwf	TRISIO
	
				
			;calibrating the internal oscillator

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

	movlw	0x07		;turn comparators off
	movwf	CMCON


	clrf 	GPIO       	;Clear GPIO of junk	
	goto 	Main		
	
 

	
	
	;Delay 0.51 sec

Del_1	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



Left ;	movlw 0x3E
	;	movwf TRISIO
		 movlw 0xff
	 	movwf GPIO
		nop
		clrf GPIO
		retlw 00
		;goto Main
Right ;	movlw 0x3D
	;	movwf TRISIO
		movlw 0xff
		movwf GPIO
		nop
		clrf GPIO
		retlw 00
;	goto Main
UpLeft; 	movlw 0x3B
	;	movwf TRISIO
		movlw 0xff
		movwf GPIO
		nop
		clrf GPIO
		retlw 00
;		goto Main
DownRight ;	movlw 0x1f
		;	movwf TRISIO
			movlw 0xff
			movwf GP5
			nop
			clrf GPIO
;		goto Main 
			retlw 00
	
Main
	movf GPIO,0
;movf filedif,0x01
;	movlw 01h
;	movwf 05
	BTFSS GPIO,01h
	call Left
	;call Del_1
;	movlw 02h
;	movwf 05
	BTFSS GPIO,02h
	call Right
	;call Del_1
;	movlw 03h
;	movwf 05
	BTFSS GPIO,0x03
	call UpLeft
	;call Del_1
;	movlw 04h
;	movwf 05 
	BTFSS GPIO,0x04
	call DownRight
	;call Del_1

	goto Main
;OSCCAL calibration value

	org	0x3ff
	movlw	0x20
		
; initialize eeprom locations

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

	end
 
I'm not analyzed your programm, but...
Value of OSCCAL 12f629 is factory setting to adress 0x3ff on new MCU!
Do'nt you program it.
And it is not:
movlw 0x20
but
retlw 0xXX

It is your first problem, infinity loop, infinity reset.
 
Last edited:
In each of the: left right upleft and down right subroutines, you need to include one or more lines of code to set a bit on the output port to turn on a LED and to have a halt or loop instruction at the end of the subroutine.
This will allow you to test the program and you will have to reset the micro to test each of the: left, right, upleft, and down right.
Once you get this working correctly, you set a bit in a file when the program goes into one of the sub-routines (or in the Main) and you can then check the bit later.
Do this first.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top