Could anyone help me to find out what wrong with my code
My program will check value from portB
If portB =11000 PIC will read analog input from RA0 then send digital value to PORTC
If PortB not equal 11000 PIC will read analog input from RA1 then send digital value to PORTC
Here is my source code
LIST P=16F877,W=-302
INCLUDE P16F877.INC
__CONFIG 0x3D32 ; XTAL 20 MHZ. HS GAIN
include "P16F877.inc"
ADCon0 EQU H'001F'
ADCon1 EQU H'009F'
status EQU H'0003'
z EQU H'0002'
PORTB EQU 0x06
PORTD EQU 0x08
TRISB EQU 0x86
TRISD EQU 0x88
; Start at the reset vector
org 0x000
goto Start
org 0x004
Interrupt
retfie
Start
bsf status,RP0 ;bank 1
bcf status,RP1
BANKSEL ADCon1
movlw B'00000000'
movwf TRISC ;portc [7-0] outputs
movlw B'11111111'
movwf TRISB
movlw B'00000000'
movwf TRISD
clrf ADCon1 ;left justified, all inputs a/d
bcf status,RP0 ;bank 0
Main
movlw B'00011000'
xorwf PORTB,w
btfsc status,z
movlw B'01000001'
movlw B'01001001'
movwf ADCon0
call ad_portc
goto Main
ad_portc
bsf ADCon0,GO ;Start A/D conversion
Wait
btfsc ADCon0,GO ;Wait for conversion to complete
goto Wait
movf ADRESH,W ;write A/D result to PORTC
movwf PORTC ;
return
end
When I run this program it will show the output from RA1 only whatever I set for PORTB
My program will check value from portB
If portB =11000 PIC will read analog input from RA0 then send digital value to PORTC
If PortB not equal 11000 PIC will read analog input from RA1 then send digital value to PORTC
Here is my source code
LIST P=16F877,W=-302
INCLUDE P16F877.INC
__CONFIG 0x3D32 ; XTAL 20 MHZ. HS GAIN
include "P16F877.inc"
ADCon0 EQU H'001F'
ADCon1 EQU H'009F'
status EQU H'0003'
z EQU H'0002'
PORTB EQU 0x06
PORTD EQU 0x08
TRISB EQU 0x86
TRISD EQU 0x88
; Start at the reset vector
org 0x000
goto Start
org 0x004
Interrupt
retfie
Start
bsf status,RP0 ;bank 1
bcf status,RP1
BANKSEL ADCon1
movlw B'00000000'
movwf TRISC ;portc [7-0] outputs
movlw B'11111111'
movwf TRISB
movlw B'00000000'
movwf TRISD
clrf ADCon1 ;left justified, all inputs a/d
bcf status,RP0 ;bank 0
Main
movlw B'00011000'
xorwf PORTB,w
btfsc status,z
movlw B'01000001'
movlw B'01001001'
movwf ADCon0
call ad_portc
goto Main
ad_portc
bsf ADCon0,GO ;Start A/D conversion
Wait
btfsc ADCon0,GO ;Wait for conversion to complete
goto Wait
movf ADRESH,W ;write A/D result to PORTC
movwf PORTC ;
return
end
When I run this program it will show the output from RA1 only whatever I set for PORTB
Last edited: