pic单片机的端口默认是输入模式吗?

2020-02-09 09:30发布

;***********************
;This program demonstrates the need for context saving
;Port A not used. Port B bit 0 used for ext.interrupt ip.
        #include P16f84A.inc
;
rhi                        equ        10
rlo                        equ        11
phi                        equ        12
plo                        equ        13
qhi                        equ        14
qlo                        equ        15
                       
                        org                00
                        goto        start
                        org                04
                        goto        Int_Routine
;
start                org                0010
                        bsf                INTCON,INTE        ; enable external interrupt
                        bsf                INTCON,GIE        ; enable glabal int
loop                movlw        99
                        movwf        phi                        ; preload numebers to be load
                        movwf        plo                       
                        movwf        qhi
                        movwf        qlo
                        call        Double_add
                        movlw        00                        ; clear
                        movwf        rhi
                        movwf        rlo
                        goto        loop
;This subroutine adds two 16-bit numbers, stored in phi-plo, and qhi-qlo,
;and stores result in rhi-rlo.
Double_add
                        movf        plo,0
                        addwf        qlo,0
                        movwf        rlo
                        btfsc        STATUS,0

                        incf        phi,1                ; add in carry
                        movf        phi,0
                        addwf        qhi,0                ; add upper bytes
                        movwf        rhi
                        return
Int_Routine
                        bcf                STATUS,0        ; clear the carry flag
                        movlw        0ff                        ; change W reg value
                        bcf                INTCON,INTE
                        retfie
                        end

本人是初学者,这个程序是一本书上的例题,我想问的是为什么程序开头没有定义port B端口的输入输出属性呢,此处只用到port B 0的输入属性,产生下降沿中断。是不是pic单片机的端口默认是输入模式吗?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
8条回答
cn-sha
1楼-- · 2020-02-09 14:59
我用过的几种PIC单片机端口默认是输入模式,用过的几种其它系列单片机端口默认也是输入模式,到现在为止还没用过端口默认不是输入模式的单片机(不知是否有不是输入模式的单片机)。
millwood0
2楼-- · 2020-02-09 20:42
it depends on the chips and ports.

in general, you should never rely on the default setting. Instead, you should explicitly set the pins' mode.
wuha
3楼-- · 2020-02-09 23:13
好像单片机的IO口默认都是输出状态的,因为一上电,单片机IO如果是输出的话,有可能与其他器件冲突,或者误动作
yongxu
4楼-- · 2020-02-10 01:09
thank you for all you guys,especially Millwood0, i get it……
aliangnisno1
5楼-- · 2020-02-10 05:37
 精彩回答 2  元偷偷看……
wuha
6楼-- · 2020-02-10 10:57
回复【3楼】wuha 东方不败
好像单片机的io口默认都是输出状态的,因为一上电,单片机io如果是输出的话,有可能与其他器件冲突,或者误动作
-----------------------------------------------------------------------

晕,写错了,默认是输入!

一周热门 更多>