Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem of testing I/O pins of PIC16F877

Status
Not open for further replies.

jz do it

Newbie level 3
Joined
Jan 31, 2005
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
42
hello all,
i'm new in microcontroller...
Recently,i would like to do a project regarding the used of PIC16F877.
So,i test my PIC's i/o first..all the output pins of my PIC can work well.(i test with led blinking program..
but when i test the input pins of porta and portb with the program at the bottom,
some of input pins seem like can't detect the input..
(rb2,rb3,rb4,rb5,rb7,ra1,ra2 and ra3)
is my pic broken already??
or my testing program is incorrect?
can anyone help me with this??thanks~

;testing PORTA input with PORTD as output
;testing PORTB input with PORTC as OUTPUT

LIST p=16F877
include "P16F877.inc"

cblock 0x20
tmp1
tmp2
ENDC

ORG 0x0000

;set ports
bcf STATUS,RP1
bsf STATUS,RP0
movlw 0xFF
movwf TRISA
movlw 0xFF
movwf TRISB
movlw 0x00
movwf TRISC
movlw 0x00
movwf TRISD
movlw 0x03
movwf TRISE
movlw 0x06
movwf ADCON1
movlw 0xFF
movwf OPTION_REG
bcf STATUS,RP0
clrf PORTA
clrf PORTB
clrf PORTC
clrf PORTD
clrf PORTE
goto Main

Main
clrf tmp1
clrf tmp2
call Check1
call Check2
movfw tmp1
movwf PORTD
movfw tmp2
movwf PORTC
goto Main

Check1
btfsc PORTA,0
bsf tmp1,0
btfsc PORTA,1
bsf tmp1,1
btfsc PORTA,2
bsf tmp1,2
btfsc PORTA,3
bsf tmp1,3
btfsc PORTA,4
bsf tmp1,4
btfsc PORTA,5
bsf tmp1,5
btfsc PORTE,0
bsf tmp1,6
btfsc PORTE,1
bsf tmp1,7
btfsc PORTE,2
bsf tmp1,7
return

Check2
btfsc PORTB,0
bsf tmp2,0
btfsc PORTB,1
bsf tmp2,1
btfsc PORTB,2
bsf tmp2,2
btfsc PORTB,3
bsf tmp2,3
btfsc PORTB,4
bsf tmp2,4
btfsc PORTB,5
bsf tmp2,5
btfsc PORTB,6
bsf tmp2,6
btfsc PORTB,7
bsf tmp2,7
return

end
 

Well, what is your input?

You say your program doesn't work, but you don't say what you have connected to the ports or what you expected to happen, or what did happen.

Some of these pins are analog inputs, and I believe they are configured as such by default. Have you changed that?

Also, you have a very strange way of reading all the pins. Why not just

movf PORTA,w
movwf tmp1
movf PORTB,w
movwf tmp2

?
 

    jz do it

    Points: 2
    Helpful Answer Positive Rating
hi~cyr

yah...like u said...
i should write with that only...
no need to check 1 by 1...
thus, i didn't set my portb as input also...all my setting is wrong...
i corrected it already and everything works fine...
thanks a lot!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top