[PIC] Unable to set PORTA for ADC in PIC16F676. No response in simulator.

Status
Not open for further replies.

DDABPE

Newbie level 3
Joined
Oct 26, 2017
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
25
Hi,

When I am sending values to Port A, it does not get updated and the values remain 0x00. While all other registers are getting updated, the problem is observed only with portA. This is what I could observe in my simulator.
Please let me know if there is any mistake that I am making here.

The initialization I have done has been shown below.

Code:
  __CONFIG _WDT_ON & _PWRTE_ON &  _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF & _CP_OFF & _BODEN_OFF
;        1 - DELAYS: 18mS, 200mS, 500mS, MICRO4, 50uS
;********************************************************
	org		0x0000
	NOP
	goto 	START
;******************************************************
	org 	0x04
	goto 	INT_O
	org 	0x08
;******************************************************
INT_O
	bcf 	INTCON, INTF		; disabling interrupt
	clrf 	SENSEBIT
	MOVLW 	0X80
	MOVWF 	INTCON
	RETFIE	
;******************************************************
	org		0x0020
;******************************************************		
INIT	
#define V_OFF 		PORTC,5		;PIN5 -  RC5	VALVE OFF Signal
#define V_ON 		PORTC,4		;PIN6 -  RC4	VALVE ON Signal
#define IRLED 		PORTC,3		;PIN7 -  RC3	IR LED Signal
#define GRNLED		PORTC,2		;PIN8 -  RC2	SENSING INDICATOR	
#define VALVELED 		PORTC,1		;PIN9  - RC1	VALVE INDICATOR
#define IRSUPP 		PORTC,0		;PIN10 - RC0	IR SUPPLY
#define INPUT 		PORTA,2		;PIN11 - RA2	Remote eye input

RS0	equ 0X21	; reserve 1 address location
RS1	equ 0X22	; reserve 1 address location
RS2	equ 0X23	; reserve 1 address location
RS3	equ 0X24	; reserve 1 address location
RS4	equ 0X25	; reserve 1 address location
RS5	equ 0X26	; reserve 1 address location
SENSEBIT	equ 0X27				

; PORTA SETTING :

	BCF     STATUS,  RP0		; Bank 0
	CLRF	PORTA 			; Init PORTA
	MOVLW	03Fh 			; Set RA<all pins to 1 >
	MOVWF	PORTA
	MOVLW	07h			; 
	MOVWF	CMCON			;
	BSF     STATUS, RP0 		; Bank 1
	CLRF	ANSEL 			; digital I/O
	BSF	ANSEL, ANS0		; SET AN0 = Analog Input (PIN13)
	movlw   0x80			;  
	movwf	OPTION_REG		; locked in Option Reg
	MOVLW	03Fh 			; RA<all pins as inputs>
	MOVWF	TRISA 			;
	MOVLW	00h 			;Weak pull ups enabled -- all
	MOVWF	WPUA
	BCF	STATUS,	 RP0	 	; Bank 0
 
Last edited by a moderator:

Are you saying it doesn't read digital values from PORTA or it doesn't read an analog voltage from AN0 ?

Hints:
1. instead of setting and resetting the bits in the STATUS register, use the 'banksel' directive, it make it less likely you select the wrong register banks.
2. instead of the 'equ' statements, use the 'cblock' directive, it makes it easier to allocate and modify register locations.
3. be consistent with upper and lower case names. The compiler doesn't care but it makes it harder to read.

Brian.
 

Also which simulator? Is it possible for you to try this on real hardware (simulators can sometimes have bugs)?
Susan
 

Here I am talking about the the digital values that should be visibly updated in the simulator column of 'Special File Registers' for field PORTA. The simulator used is MPLAB IDE. Also when I m testing the entire code on real hardware there also the output is not correct.
So cant say if analog conversion is taking place or not.
 

Here I am talking about the digital values that should be read at the port.
Tried on hardware as well there also the output is incorrect.
Simulator used is MPLAB IDE. Also tried re-installing the simulator.
 

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…