• 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.

pic16f877a problems reading adresh, adresl

Status
Not open for further replies.

kta22

New Member
Hi all. I can't read and put the 8bit result adresh in portb, but in the same time the adresl can be transfered in the portd. I don't know what seems to be the problem. This is the asm code :


#include <p16F877.inc>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _HS_OSC &_WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF

org 0x00
t equ 0x20
q equ 0x21
s equ 0x22
x equ 0x23
y equ 0x24
z equ 0x25
;
movlw b'10001001' ;
movwf ADCON0
clrf PORTA
bsf STATUS,RP0
movlw b'10000000'
movwf ADCON1
clrf TRISB
clrf TRISC
clrf TRISD
clrf ADRESL
bcf STATUS,RP0

clrf PORTD
clrf PORTB
clrf PORTA
clrf PORTE


loop1
call loopaa
bsf ADCON0,2
loop
btfsc ADCON0,2
goto loop
movf ADRESH,0
movwf PORTB
bsf 03,RP0
movf ADRESL,0
bcf 03,RP0
movwf PORTD
goto loop1


loopaa

movlw 0x8f
movwf x
movlw 0x8f
movwf y
movlw 0x0A
movwf z
delay1
bcf STATUS,2
decf x,1
btfss STATUS,2
goto delay1
bcf STATUS,2
movlw 0x8f
movwf x
decf y,1
btfss STATUS,2
goto delay1
movlw 0x8f
movwf x
movlw 0x8f
movwf y
decf z,1
btfss STATUS,2
goto delay1
return

nop
end

thanks
 

bananasiong

New Member
Hi,

I see that you have the result right-justified. So you'll be having bit 0 and bit1 in ADRESH register. And what do you mean that you can't? What are you expecting on PORTB? What's the analog voltage level appear on the AN1?

*EDIT: I didn't take a look at loopaa routine because they're way too messy.. I assume it's just a delay routine. BTW why don't you use bit C, Z, f, w, etc for easier reading..
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
This is why the more experienced people here recommend using the correct variable names.

You have,
Code:
	bsf	ADCON0,2
which should be,
Code:
	bsf	ADCON0,GO
The reason it doesn't work is that the GO/STOP bit is 1 not 2.

Mike.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top