PIC10F200, MPASM, pin should be output then input...but isn't

Status
Not open for further replies.
T

treez

Guest
Hello,
I am writing MPASM code which should make GPIO,1 of PIC10F200 an output low for 10ms, then an input for 790ms.
This is repeated over and over.
However, the GPIO,1 pin does not become an input when it should......it actually stays as an output low.
-I know this because there is a 47K pull-up resistor on this pin, and it does not pull the pin up.

Do you know what i am doing wrong?
(Is it something to do with the ReadModifyWrite?)
....Do i have to just do a few dummy read instructions (eg, btfsc GPIO,1 nop nop ) after setting it to an input to make it really become an input?

By the way, here is the code....
Code:
;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    list      p=10F200            ; list directive to define processor
    #include <p10F200.inc>        ; processor specific variable definitions

    __CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



#define		PIN_TRIGGER		0
#define		PIN_SYNC		1
#define		PIN_PHASE		2
#define		PIN_FPM			3


;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
;VARIABLE DEFINITIONS
sync_phase_FLAG      	EQU 	0x13    	;insync of bit 0 is clear
FPM_FLAG				EQU		0x14		;FPM=75 if bit 0 is clear
ACDC_FLAG				EQU		0x15		;AC if  its bit one is set
counter             	EQU 	0x15    	;counter for delays
counter1            	EQU 	0x17
counter2            	EQU 	0x18
counter3            	EQU 	0x19
counter4            	EQU 	0x1A
count					EQU		0x1B

phase_REG1				EQU		0x1C
phase_REG2				EQU		0x1D



;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    ORG     0xFF            ; processor reset vector

; Internal RC calibration value is placed at location 0xFF by Microchip
; as a movlw k, where the k is a literal value.

        ORG     0x000           ; coding begins here
        movwf   OSCCAL          ; update register with zero





;vvvvvvvvvvvvvvvvvvv          OPTION REGISTER            vvvvvvvvvvvvvvvvvvvvvv
start
    	movlw       0b11000111
    	option                                  ;set option register
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
;SET PORTS UP AS INPUTS/OUTPUTS.
        movlw   0b00001110      ;Set ports to input or output
        tris    GPIO
		nop
;Initiate the ports
		bcf		GPIO,PIN_TRIGGER			;Ensure trigger output low

;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;start up delays
	call	delay_195ms
	call	delay_195ms
	call	delay_195ms
	call	delay_195ms


;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
;Check for ACDC input


;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^




;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
;0000000000000000000000000000000000000000000000000000000000000000000000000
FPM60_INSYNC
	
;Send trigger
		bsf		GPIO,PIN_TRIGGER
		call	delay_10us
		bcf		GPIO,PIN_TRIGGER


;Set sync pin to an output
        movlw   0b00001100      
        tris    GPIO            
		nop
;Ensure trigger output low
		bcf		GPIO,PIN_TRIGGER			

;Send sync pulse
		bcf		GPIO,PIN_SYNC
		call	delay_10ms

;Set sync pin to an input
       	movlw   0b00001110      
        tris    GPIO            
		nop
		bcf		GPIO,PIN_TRIGGER			

		call	delay_195ms
		call	delay_195ms
		call	delay_195ms
		call	delay_195ms
		call	delay_30ms	
		
		goto	FPM60_INSYNC
;0000000000000000000000000000000000000000000000000000000000000000000000000
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^	
				



delay_10us
	nop
	nop
	nop
	nop
	nop

	nop
	nop
	nop
	nop
	retlw	0x00



;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
delay_2ms
;	clrwdt
    movlw   0x04			;4
    movwf   counter1
kkk
    movlw   0xA7			;167
    movwf   counter
jjj
    decfsz  counter,1       ;INNER LOOP=501us
    goto    jjj

    decfsz  counter1,1
    goto    kkk
    retlw   0x00
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
delay_5ms
;	clrwdt
    movlw   0x0A			;10
    movwf   counter1
mmm
    movlw   0xA7			;167
    movwf   counter
nnn
    decfsz  counter,1       ;INNER LOOP=501us
    goto    nnn

    decfsz  counter1,1
    goto    mmm
    retlw   0x00
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
delay_10ms
;	clrwdt
    movlw   0x14			;20
    movwf   counter1
qqq
	clrwdt
    movlw   0xA7			;167
    movwf   counter
ppp 
    decfsz  counter,1       ;INNER LOOP=501us
    goto    ppp

    decfsz  counter1,1
    goto    qqq
    retlw   0x00
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
delay_30ms

    movlw   0x3C			;60
    movwf   counter1
sss
;	clrwdt
    movlw   0xA7			;167
    movwf   counter


rrr 
    decfsz  counter,1       ;INNER LOOP = 501us
    goto    rrr

    decfsz  counter1,1
    goto    sss
    retlw   0x00
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
delay_50ms

    movlw   0x64			;100
    movwf   counter1
ttt
;	clrwdt
    movlw   0xA7			;167
    movwf   counter


vvv 
    decfsz  counter,1       ;INNER LOOP = 501us
    goto    vvv

    decfsz  counter1,1
    goto    ttt
    retlw   0x00
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
delay_195ms

    movlw   0xFF			;100
    movwf   counter1
XXX
;	clrwdt
    movlw   0xFF			;167
    movwf   counter


YYY 
    decfsz  counter,1       ;INNER LOOP = 501us
    goto    YYY

    decfsz  counter1,1
    goto    XXX
    retlw   0x00
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    END
 
Last edited by a moderator:

Hi,

Think you can see from the screenshot you get build Warnings.
 

Attachments

  • ScreenShot002.jpg
    298.3 KB · Views: 97
Reactions: treez

    T

    Points: 2
    Helpful Answer Positive Rating
thanks, ..but i am using MPLAB v8.60 ( because all our old code was written in that).

Are you saying that all i have to do is change 0b00001110 to b'0001110' and all my problems will be gone?

.............the strange thing is that i set the pin to an input, and it goes output low.........................but in actual fact the pic does still read the pin....it just obviously reads it as input low.......in other words, the bottom transistor of the pin's totem pole is getting stuck on.

I thought it must be some read modify write type problem?

.....maybe i have to just purge the pin's latch of the command which is turning on the pin's lower transistor.

Isn't there something about writing to a pin, or writing to a pin's "latch"


Is what i am suffering a common problem?......surely i am not the only person in the world who's wanting to use the same pin as alternately an input then an output?

I am thinking there must be a slot about this in the MPASM user guide , but i can't find it.

I do specifically remember at college that the teacher was full of doubt about us using the same PIC pin as an input and subsequently as an output.

....i dont remember her saying it was a problem of radix
 

Hi,

thanks, ..but i am using MPLAB v8.60 ( because all our old code was written in that).

You can use the latest version of Mplab, its unlikely to make any difference to your code.


Are you saying that all i have to do is change 0b00001110 to b'0001110' and all my problems will be gone?

No, All I did was find that those instructions were invalid as it was applying a default value, whatever that is ??
Being as it was on your setup instructions it would be reasonable to get them correct first.



Detailed in other posts in this forum , it recommended that you use PORT when reading from a Port and LAT when writing to a PORT.


The pin can only be in one state at a time, so providing you switch it from input to output correctly I do not see why it should be a problem.
Clearly you have to be careful of using a pull up resistor when in output mode, though think 47k should not be a problem - but you do not mention what the input device is, so no idea how that will affect things when you change it to an output ??

....i dont remember her saying it was a problem of radix

Mplab applies a default radix, typically hex, you can see those acceptable parameters from the the help file.

If your code is not working suggest you slow your delays down to a visual pace, say a second, so you can actually see whats happening.
( assume you do not have a debugger header / Pickit for that chip ? )
 
Reactions: treez

    T

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…