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
 
Thread Tools Display Modes
Old 13th March 2004, 03:30 AM   (permalink)
Default Weird 12F629 GPIO setting?

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 ;;;;;;
eirikr is offline   Reply With Quote
Old 13th March 2004, 05:49 AM   (permalink)
Default

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.
Nigel Goodwin is offline   Reply With Quote
Old 13th March 2004, 12:52 PM   (permalink)
Default

yeah i just checked with the data sheet, GPIO is in bank 0, not bank 1. TRISIO is in bank 1.
__________________
www.winpicprog.co.uk - Great PIC language tutorials.
pike is offline   Reply With Quote
Old 14th March 2004, 04:08 AM   (permalink)
Default

Everything works now! Thanks a lot guys!
eirikr is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 08:00 AM.


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