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.

10f222 not writing to GPIO?

Status
Not open for further replies.
This is my first project with the 10f222 and I'm having a problem writing to the GPIO pins in this program. I'm using MPLAB sim and when I get to the MOVWF GPIO command the pins don't change.
I only have one output (0) and I have tried BSF, BCF, MOVWF, and they don't have any effect.
I've looked though the datasheet but I haven't found anything that I haven't already tried, but, I'm probably just overlooking something.

Code:
	list      p=10F222            ; list directive to define processor
	#include <p10F222.inc>        ; processor specific variable definitions

	__CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF & _MCPU_OFF & _IOFSCS_4MHZ

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.




;***** VARIABLE DEFINITIONS
TEMP_VAR    UDATA
TEMP        RES     1             ;example variable definition
COUNT0		RES		1			;COUNTER FOR DELAY
COUNT1		RES		1			;COUNTER FOR DELAY
TEMPOUTPUT	RES		1			;TEMP FILE FOR OUTPUT





;**********************************************************************
RESET_VECTOR	CODE   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.

MAIN		CODE		    0x000
			movwf	 	  OSCCAL            ; update register with factory cal value
											

			GOTO			START




;SUBROUTINES


DELAYP100

			CLRF			TMR0
			CLRF			COUNT0
		
			MOVLW			D'206'
			MOVWF			COUNT0

RESET0		MOVLW			D'198'
			MOVWF			TMR0
LOOP0		DECFSZ			TMR0,1
			GOTO			LOOP0
	
			DECFSZ			COUNT0,1
			GOTO			RESET0
			RETLW			D'0'
;================================================================

start
			MOVLW			B'00000110'			;
			TRIS			GPIO				;								
			CLRF			GPIO				;
			MOVLW			B'11010111'			;
			OPTION							

												;
			MOVLW			B'10000100'			;
			MOVWF			ADCON0				;
				
			MOVLW			B'11111111'			;
			MOVWF			GPIO				;
			CALL			DELAYP100			;
			MOVLW			D'0'				;
			MOVWF			GPIO				;
			CALL			DELAYP100			;


	END
 
No everything builds fine with no errors or warnings, but when I step the sim though the program everything work fine until I get to the "movwf gpio", and none of the values change. Could it be in the Sim itself?
I'm using the watch window to watch the SFRs
 
hi,
Just put your code thru my MPLAB 7.x,, its showing lots of assembly errors?
 
I've dissable case sensitivity and suppressed coff to cod file in linker

Had to modify linker
CODEPAGE NAME=.idlocs START=0x200 END=0x205 PROTECTED
 
Last edited:
Still Stumped

I've tried this agian on a different computer with MPLAB 7.41, but I still cannot write to GPIO,0 with BSF or MOVWF. I tried using a little different code but I still had the same result.
Disabled case sensitivity in the assembler
suppressed coff to cod file generation in the linker( if I don't I get an error for to long of a filename/path)
modified idlocs in the linker (CODEPAGE NAME=.idlocs START=0x200 END=0x205 PROTECTED) to fit in my variables.
This is getting beyond my limited knowledge and I don't know if i'm setting it up wrong or just not using the right commands. If any one could give me any pointers I would apprieciate it.
I wrote this code to just to test and see if I could change the GPIO,0.



Code:
list p=10F222 ; list directive to define processor
#include <p10F222.inc> ; processor specific variable definitions
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _MCPU_OFF & _IOFSCS_4MHZ
 
;***** VARIABLE DEFINITIONS
temp EQU 0x09 ;example variable definition
TEMPVAR UDATA 0X0A
COUNT0 RES 1
COUNT1 RES 1
COUNT2 RES 1
ADTEMP RES 1
 
;**********************************************************************
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 factory cal value
 
 
start
nop ; example code
movlw 0xFF ; example code
movwf temp ; example code
; remaining code goes here
MAIN
MOVLW B'11010111'
OPTION
MOVLW B'00001110'
TRIS GPIO
BCF OSCCAL,0
MOVLW B'10000100'
MOVWF ADCON0
 
 
BSF GPIO,0
CALL DELAY100
GOTO MAIN
 
;==========================================
DELAY100
CLRF COUNT0
CLRF TMR0
MOVLW .200
MOVWF COUNT0
RESET0 MOVLW .200
MOVWF TMR0
LOOP0 DECFSZ TMR0,1
GOTO LOOP0
 
DECFSZ COUNT0
GOTO RESET0
RETURN
 
Try this:

Code:
	list      p=10F222            ; list directive to define processor
	#include <p10F222.inc>        ; processor specific variable definitions

	__CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF & _MCPU_OFF & _IOFSCS_4MHZ

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.




;***** VARIABLE DEFINITIONS
temp	EQU     0x09        ;example variable definition



;**********************************************************************
	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 factory cal value




start
	nop                       ; example code
	movlw   0xFF              ; example code
	movwf   temp              ; example code

; remaining code goes here
 MOVLW B'11010111'
 OPTION
 MOVLW 0x0
 ;MOVLW B'00001010'
 TRIS GPIO
 MOVLW B'00000100'
 MOVWF ADCON0
 clrf GPIO
toggle 
 comf GPIO
 goto toggle




	END                       ; directive 'end of program'
 
It would appear that you have found a bug/typo in either the simulator, the datasheet or the pic itself. It looks like ANS0 and ANS1 are swapped around. If you change your code to load ADCON0 with b'01000100' then it works correctly. It's very confusing as it looks like 0x40 in ADCON0 sets both inputs to digital.:confused:

Mike.
 
Thanks Mike, I see what your saying about 0x40, I guess I'll just have to play with it once I get it in the circuit. Thanks again for your time.
 
10f222 not writing to GPIO, GP2 pin

I have had the similar problem, where I could not able to write to GP2 pin using 10f222 PIC micro controller.

The value in GP2 pin is toggling no matter what value I set it, even though I have not set it for TRI state.

here is the code and initial configuration I tried.


Code:
	list      p=10F222            ; list directive to define processor
	#include <p10F222.inc>        ; processor specific variable definitions

	__CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF & _MCPU_OFF & _IOSCFS_4MHZ 


; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


;***** VARIABLE DEFINITIONS
		    UDATA

reg1		res		1 1st reference voltage value	
reg2		res		1 2nd reference voltage value	
calreg		res		1
cflag		res		1				 conditional flag
counter1	res		1
counter2	res		1



#define PORT_MASK	b'111000'	;make GP2 an output, but GP0, GP1 is also made as an output to avoid short circuit, GP3 as Input. It is mapped according to GPIO Pins
#define MAXLIMIT	0xC0		;maximum limit for voltage
#define LOWLIMIT	0x01		;lowest limit for voltage


;**********************************************************************
RESET_VECTOR	CODE   0x1FF       ; processor reset vector
				res		1
	
; Internal RC calibration value is placed at location 0xFF by Microchip
; as a movlw k, where the k is a literal value.

MAIN	CODE    0x000 
	movwf   OSCCAL       ; update register with factory cal value

start
;Initial configuration
	movlw   PORT_MASK  ; Configure GP2 as an output
	tris	GPIO
             movlw   b'00000'       ; set GP2 Low for output, frm 0V 
	movwf 	GPIO

	movlw   b'10000100'			; Configure ADC,  AN1 analog , Conversion OFF GO/DONE = 0, ADON ::::Configuring Input port and ADC configuration
	movwf	ADCON0				; AN1 selected
	bcf 	cflag,0				; initially conditional flag should be '0'
	movlw	b'00100'		;set the flag for output Logical HIGH, to check output
	movwf 	GPIO
 
This is probably due to having that pin configured as an oscillator output (FOSC4). You have to clear bit 0 in OSCCAL to have this functioning as GPIO.

I have had the similar problem, where I could not able to write to GP2 pin using 10f222 PIC micro controller.

The value in GP2 pin is toggling no matter what value I set it, even though I have not set it for TRI state.

here is the code and initial configuration I tried.


Code:
	list      p=10F222            ; list directive to define processor
	#include <p10F222.inc>        ; processor specific variable definitions

	__CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF & _MCPU_OFF & _IOSCFS_4MHZ 


; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


;***** VARIABLE DEFINITIONS
		    UDATA

reg1		res		1 1st reference voltage value	
reg2		res		1 2nd reference voltage value	
calreg		res		1
cflag		res		1				 conditional flag
counter1	res		1
counter2	res		1



#define PORT_MASK	b'111000'	;make GP2 an output, but GP0, GP1 is also made as an output to avoid short circuit, GP3 as Input. It is mapped according to GPIO Pins
#define MAXLIMIT	0xC0		;maximum limit for voltage
#define LOWLIMIT	0x01		;lowest limit for voltage


;**********************************************************************
RESET_VECTOR	CODE   0x1FF       ; processor reset vector
				res		1
	
; Internal RC calibration value is placed at location 0xFF by Microchip
; as a movlw k, where the k is a literal value.

MAIN	CODE    0x000 
	movwf   OSCCAL       ; update register with factory cal value

start
;Initial configuration
	movlw   PORT_MASK  ; Configure GP2 as an output
	tris	GPIO
             movlw   b'00000'       ; set GP2 Low for output, frm 0V 
	movwf 	GPIO

	movlw   b'10000100'			; Configure ADC,  AN1 analog , Conversion OFF GO/DONE = 0, ADON ::::Configuring Input port and ADC configuration
	movwf	ADCON0				; AN1 selected
	bcf 	cflag,0				; initially conditional flag should be '0'
	movlw	b'00100'		;set the flag for output Logical HIGH, to check output
	movwf 	GPIO
 
Thanks ChayD, yes the problem got resolved with that only...but it was long back now, anyway thanks again for your reply
 
Status
Not open for further replies.

Latest threads

Back
Top