Connect with us

PIC10F200, MPASM: Pin input, then output

Discussion in 'Microcontrollers, Programming and IoT' started by eem2am, Jul 30, 2012.

Scroll to continue with content
  1. eem2am

    eem2am

    414
    0
    Aug 3, 2009
    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
     
  2. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    on a couple variations of the chip the GP0 is multiplexed with the comparator. Try disabling the comparator by loading '00000000' into the CMCON0 register right after you configure your option register and before your main program starts.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-