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
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
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'
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
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
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?