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.

Weird 12F629 GPIO setting?

Status
Not open for further replies.

eirikr

New Member
Hi all,

I am testing the 12F629 found something very weird. The PIC is suppose to flash two LEDs on GP0 and GP1.

1. The movlw b'00001111' to set TRISIO is not a typo - bit 0 and bit 1 are supposed to be zero for output, but LEDs won't flash unless I set them to one!
:shock:
I ran the MPLAB simulator, and:
2. bsf GPIO, GP1 will set GP1 bit to zero! :?
3. bcf GPIO, GP0 will set GP0 bit to one! :roll:

Anyone has any idea what's going on?


Here is the code:

Code:
		org	0x00			
		goto	init			

init	bcf	STATUS, RP0		; Bank 0
		clrf	GPIO			; Init GPIO
		movlw	07h				; Set GP<2:0>
		movwf	CMCON			; digital IO. Turn off comparator
		movlw 	b'00001111'		; GP<1:0> output GP<3:2> inputs
  		movwf	TRISIO			; 
		bsf	STATUS, RP0		; Bank 1

main	bsf	GPIO, GP1
		bcf	GPIO, GP0
		call	delay
		bcf	GPIO, GP1
		bsf	GPIO, GP0
		call 	delay
		goto	main

delay ;;;;; delay routine ;;;;;;
 
Without checking the datasheet, but based on other PIC's, the bank switching looks incorrent. TRIS is usually in bank 1, and GPIO in bank 0, you have them the other way. Which is why you think setting TRIS to 1 is making them an output - it's not, it's setting GPIO high. Then in the main part of the program you're toggling the TRIS bits, switching them from inputs to outputs.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top