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.

12F509 - no output GP02

Status
Not open for further replies.

New2Pic2013

New Member
Hi

Not been playing with these for long and up till now all has made sense. However trying to get GP02 as an output as so far have failed miserably. It seems no matter what way I attempt to code the pin I cannot get any output. I can get pins 2.3.6 and 7 all to work but not 5. (pin 4 ignored as GP03 is input only)

Am I missing something obvious as the datasheet indicates this can be in or out

Thanks
 
I am sure everyone would like to see your code.

In addition, here is some code I wrote quite awhile ago to make all the pins outputs, except pin4 (MCLR), and to flash them. I have not checked the code recently, so cannot give any guarantees.

John

Code:
;**********************************************************************

    list      p=12F509            ; list directive to define processor
    #include <p12F509.inc>        ; processor specific variable definitions

    __CONFIG   _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC

;   __CONFIG 0FFA 



;***** VARIABLE DEFINITIONS

List	
d1	equ	0x11
d2	equ	0x0b

;*******************************************************************
RESET_VECTOR
    ORG   0x3FF      ; processor reset vector

    
MAIN
    ORG    0x000
    movwf   OSCCAL            	; update register with factory cal value 
start   
   	movlw	b'11000000'			; weak pull-ups disabled
	option
	movlw	b'001000'			; sets all pins to output, except GPIO,3 (pin4) 
	tris	GPIO
flash
	movlw	b'110111'			; sets all pins high
	movwf	GPIO
	call	dly_2E5
	movlw	b'000000'			; sets all pins low
	movwf	GPIO
	call 	dly_2E5
	goto	flash

dly_2E5
	clrwdt
	movlw	0x3f
	movwf	d1
	movlw	0x9d
	movwf	d2
delay
	decfsz	d1,f
	goto	$+2
	decfsz	d2,f
	goto	delay
	retlw	0

    END                       ; directive 'end of program'
 
Thanks for the reply

Not sure if all the code will make sense (have cut some of the mid sequences out) as this is written for PIC BASIC PRO and then converted. This does however runs fine giving me outpts (flashing leds) on the pins as earlier described.

This is currently showing for outputs 2 and 5. output 5 works nothing on 2.

I can change these around as much as I like but as i said only GPIO 0,1,4,5 will work. The next stage of this needs 5 outputs and hence the need to get pin 5 - GPIO2 working. I accept this is pushing the chip a bit and the next stage of the project is to use bigger chips, but I am more intrigued as to why it does work and also wont have the other chips for a few days.

Colin

'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 31/07/2013 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 23/07/2013 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'Program Name: BlinkLED
'Compiler and Version: PICBasic PRo v2.5
'PIC HARDWARE SETUP +++++++++++++++++++++++++++++++++++
'Written for PIC: PIC12F509

define OSC 4
TRISIO = %000000 'Set all pins as outputs
LCNT var word
led1 var gpio.2 ' white
output led1
low led1
led2 var gpio.5 'blue and turn off
output led2
low led2

Main:
LCNT = 1
do
toggle led1
pause 20
toggle led1
high led2
pause 10
toggle led1
pause 15
toggle led1
pause 20
toggle led1
pause 30
toggle led1
pause 10
Toggle led2
toggle led1
pause 25
toggle led1
pause 30
toggle led1
pause 80
toggle led1
pause 25
high led1
high led2
pause 400
low led2
LCNT = LCNT + 1
Loop until LCNT >25
low led2
low led1
sleep 7
GOTO Main
END '################# END OF PROGRAM #####################
 
Sorry, I don't do Basic. Do you have bit<5> of the Option register set to 0? Notice it is set to 0 in my code.

Source = datasheet
5.3 TRIS Registers
The Output Driver Control register is loaded with the contents of the W register by executing the TRIS f instruction. A ‘1’ from a TRIS register bit puts the corresponding output driver in a High-Impedance mode. A ‘0’ puts the contents of the output data latch on the selected pins, enabling the output buffer. The exceptions are RB3/GP3, which is input only and the T0CKI pin, which may be controlled by the OPTION register. See Register 4-3 and Register 4-4.

John
 
Hi John

I'm using basic only whilst I'm trying to learn Mlab and ASM code. It's does mean I can get smaller bits working quite quickly as my knowledge of basic is quite good, and I do at least understand the structure. The ASM is a whole new thing to learn, but I am progressing quite well. This also has the advantage that I can look at both and compare when it all goes belly up.

Anyway thanks for the last info. Correct - I have just found that GPIO.2 is the TOCKI pin as well and so will have to look into the OPTION register a bit further to see if I can find a way round it.

Thanks again for the swift response. Getting late out here now so going to knock off for tonight.

Will post my findings hopefully tomorrow

Colin
 
Had a quick look and can impose ASM into the basic and have managed to get the OPTION register to change by writing the OPTION code "bits". I added the code like this -

ASM
movlw b'11000000' ; weak pull-ups disabled
option b'00000000'
movlw b'001000' ; sets all pins to output, except GPIO,3 (pin4)
tris GPIO

endasm


Works now ! Tomorrow will be spend tidying up and and labels.

Great result thanks very much again

Colin (now its definitely bedtime)
 
I am delighted it worked for you. Just one point, "Option" does not need an operand. It will load the Option register with what is in "w."

Option.png

John
 
You don't need all that a simple
Code:
OPTION = %11000000
would do.
 
You don't need all that a simple
Code:
OPTION = %11000000
would do.

My code was in MPASM, and although your version builds without an error, it won't simulate (MPLab 8.89). Just curious, with your compiler, how may cycles does your code take?

John
 
I'm talking about the OP code he didn't need any inline ASM just set option just like he did the GPIO
 
Status
Not open for further replies.

Latest threads

Back
Top