I/o problem

Status
Not open for further replies.

zhaniko93

New Member
with 16f628a i have such thing in code:
set ra6 to output, bsf it and than when i xorwf porta for toggling other bit, ra6 goes 0 if i have led connected with it and stays 1 if i have nothing connected with it . what's wrong?
i can't paste code as i have no internet and use mobile for posting, sorry
 
Did you disable the comparator? Can you be a little more specific as to what you're trying to do?
 
yes i have, program sets ra6, then in interrupt i have to toggle ra0, so i xor it with 0x01, and it clears ra6 too, why?
 
So your code looks like this?

Code:
		list		p=16F628A, r=dec, w=-302
		include		<P16F628A.INC>
		__config	_LVP_OFF & _BOREN_OFF & _PWRTE_ON & _WDT_OFF & _INTOSC_OSC_NOCLKOUT

		cblock		0x70
				W_TEMP
				STATUS_TEMP
		endc

		org		0x000		;reset vector
		goto		START

		org		0x004		;interrupt vector
		movwf		W_TEMP		;push W
		swapf		STATUS,W	;push STATUS
		banksel		0x00		;bank 0
		movwf		STATUS_TEMP

		movlw		0x01		;toggle RA0
		xorwf		PORTA,F
		
ISRExit		swapf		STATUS_TEMP,W	;pop STATUS
		movwf		STATUS
		swapf		W_TEMP,F	;pop W
		swapf		W_TEMP,W
		retfie

START		movlw		0x07		;disable comparator
		movwf		CMCON
		banksel		TRISA		;bank 1
		movlw		b'00000000'	;port a all outputs
		movwf		TRISA
		banksel		0x00		;bank 0

		bsf		PORTA,6
		<rest of code>

		end
When I do it on my logic calculator, RA6 should stay high if XOR'ing it with 0x01.
 
Last edited:
yes, absolutelly the same, i think that this pin has internal circuit such that when it's output and i read it, it reads 0? i tried it on rb2 (added xor portb with 0x00) and it works.
 
Well...in normal practice we don't read outputs. We only read inputs while we write to outputs.

I just set up a test circuit with the 16F628A and the above code with LEDs on RA0 and RA6 using a TMR0 interrupt to toggle RA0 on/off. It works as expected...the LED on RA6 stays on while the LED on RA0 flashes as it's toggled in the interrupt.
 
Last edited:
OK here's my code:
movlw 0x07
movwf CMCON
banksel TRISA
movlw 0x01
movwf TRISB
clrf TRISA
banksel PORTA
clrf PORTA
start bsf PORTA, 7
btfsc PORTB, 0
goto $-1
movlw 0x00
xorwf PORTA, f
goto $

when i clear rb0, ra7 goes 0. replacing ra0 or ra1 with ra7,it doesnt go 0 any more! what's wrong with ra7?
 
I changed my code to such thing:
bsf PORTA, 7
btfsc PORTA, 7
bsf PORTA, 0
IT doesn't set ra0, if i change porta 7 with for example porta 1, it sets. looking at the datasheet, there's strange schmit trigger AT ra7 input, with one pin connected to osc mode. i don't understand it( i use INTRC_OSC_NOCLKOUT)
 
I tested it and it works on my 16F628A. Although in code we don't typically poll output bits like that. We usually copy the contents of the port to a general purpose RAM register, then read it off of the register -

Code:
		movfw		PORTA		;copy contents of PORTA 
		movwf		0x20		;to RAM register 0x20
		btfsc		0x20,7          ;is RA7 high?
         	bsf             PORTA,0         ;yes, set RA0 high
           	goto              $

However...your code as shown worked on my PIC -

Code:
START		movlw		0x07
		movwf		CMCON
		clrf		PORTA
		banksel		TRISA
		clrf		TRISA
		banksel		PORTA
		bsf		PORTA,7
		btfsc		PORTA,7
		bsf		PORTA,0
		goto		$

RA6 and RA7 work fine as outputs as long as you're using _INTOSC_OSC_NOCLKOUT in the config word. Try changing the config word so it's like this -

Code:
		__config	b'10000100110000'
 
Last edited:
OK...YOU ARE STILL NOT LISTENING!!!

Yes...both LEDs turn on on my PIC.

I posted code to set your config word with. Why haven't you tried that? Try it, and if it works I will explain why it does.
 
list P=16F628A
include <P16F628A.inc>
__config b'10000100110000'

errorlevel -305, -302





movlw 0x07
movwf CMCON

banksel TRISA
movlw b'00000001'
movwf TRISB ;TRISB<3> Clear fro PWM, 0 Set for IR in
clrf TRISA

banksel PORTA
clrf PORTA





Start
bsf PORTA, 7
btfsc PORTA, 7
bsf PORTA, 0

goto $








END

Doesn't work (
 
OK...assemble this code -

Code:
	        list		p=16F628A, r=dec, w=1
		include		<P16F628A.INC>
		__config	b'10000100010000'
 
		org		0x000		;reset vector
		goto		START
 
START		movlw		0x07		;disable comparator
		movwf		CMCON
		clrf		PORTA		;init ports
		clrf		PORTB
		banksel		TRISA		;bank 1
		clrf		TRISA		;RA0-RA7 outputs
		movlw		b'00000001'	;RB1 input
		movwf		TRISB
		banksel		PORTA		;bank 0
 
		bsf		PORTA,7		;RA7 high
		btfsc		PORTA,7		;is RA7 low?
		bsf		PORTA,0		;no, set RA0
		goto		$	
		
		end

Also, two things...first off, you should not have to suppress error 305. If you're getting error 305, then you're forgetting to put a W or an F after a 2 operand instruction (such as decfsz <ADDRESS>,F). Message 302 should be the ONLY assembler message you should ever have to suppress.

Second thing...if you're going to try to fix it yourself, then why are you posting this issue on a forum if you're not going to listen to the advice given?
 
Last edited:
Well it works fine on my 16F628A. Both RA7 and RA0 go high on my PIC with the above code so I know the code is solid. This means we have a hardware issue.

Do you have LEDs hooked up to RA0 and RA7? If so, could it be possible that the LEDs are backwards? Also, do you have a pull up resistor on RA5/MCLR?
 
Last edited:
please try connecting wire directly from RA7 to to ground and try, if it still works. they are not backwards, both work well and I have set RA5 normal I/O. PIC can provide max source of 25mA right? If I connect very small resistance (e.g. 1 Ohms), pic will have to change output voltage to 25mV in order to privide 25mA right? and when it happens and I read bit during it, will it read the latch value which I wroti in with bsf? as diagram shows form datasheet, it will read 25mV, which means 0 right? and if It's so, than everything works fine, I mean, that's normal action
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…