Nigel Goodwin said:
On a quick glance it looks like you're not setting the pin as a digital one, by default AN0 is an analogue input - you MUST set it to be a digital input if you want to use it as one.
i have already assign into digital by assigning all AN0-AN7 digital I/O by applying h'06' to ADCON1 but it still didn't work.. i used the software UART simulation to input a character into AN0 for testing , one of the simlation tools for PIC simulator IDE.
list p=pic16f877, f=inhx8m
include <P16F877.INC>
__config _CP_OFF & _PWRTE_ON & _HS_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF
ERRORLEVEL -302 ;Suppress bank warning
cblock h'20'
Xmit_Byte ;Equ 0x20 ;holds byte to xmit
Rcv_Byte ; Equ 0x21 ;holds received byte
Bit_Cntr ; Equ 0x22 ;bit counter for RS232
Delay_Count ; Equ 0x23 ;delay loop counter
endc
ORG 0x00
call RECEIVE ; receive using pin A0
int ORG 0x04
goto int
RECEIVE
CALL SER_INIT
CALL Rcv_RS232
RETURN
SER_INIT
BSF STATUS, RP0 ;select bank 1
; BCF TRISB, 6 ;set B6 as an output
MOVLW h'06'
MOVWF ADCON1
CLRF TRISB ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; i set as trisb
BSF TRISA,0 ;set A0 as an input ;;;;;;;;;;;;;;; i set as trisA
BCF STATUS, RP0 ;select bank 0
; BSF PORTB, 6 ;set B6 high
RETURN
Rcv_RS232 BTFSC PORTA, 0 ;wait for start bit
GOTO Rcv_RS232
CALL Start_Delay ;do half bit time delay
BTFSC PORTA, 0 ;check still in start bit
GOTO Rcv_RS232
MOVLW 0x08 ;set up to read 8 bits
MOVWF Bit_Cntr
CLRF Rcv_Byte
Next_RcvBit CALL Bit_Delay
BTFSS PORTA, 0
BCF STATUS , C
BTFSC PORTA, 0
BSF STATUS , C
RRF Rcv_Byte , f
DECFSZ Bit_Cntr , f ;test if all done
GOTO Next_RcvBit
CALL Bit_Delay
MOVF Rcv_Byte, W
MOVWF PORTB ;; display on leds on what data received
RETURN
Start_Delay MOVLW 0x3C
MOVWF Delay_Count
Start_Wait NOP
DECFSZ Delay_Count , f
GOTO Start_Wait
RETURN
Bit_Delay MOVLW 0x78
MOVWF Delay_Count
Bit_Wait NOP
DECFSZ Delay_Count , f
GOTO Bit_Wait
RETURN
END