还是昨天那个关于AD转换的程序

2019-03-25 18:48发布

本帖最后由 windirection 于 2017-9-25 20:56 编辑

;***********************************************************
                               org                          000h          ;定义程序存放区域的起始地址
                        goto                        main
                        org                        0004h
                        bcf                        pir1,0
                        bcf                        t1con,0
                         movlw                tmr1lb
                        movwf                tmr1l
                        movlw                tmr1hb
                               movwf                tmr1h
                               bsf                        t1con,0
                        comf                r1
                        btfsc                r1,0
                        bsf                        adcon0,2
                        retfie
main        nop
                      bsf                   status,5
                       movlw                 0x00
                       movwf                  trisd
                movlw                0x01
                       movwf                  trisa
                bsf                        pie1,0
                movlw                0x0e
                movwf                adcon1
                       bcf                   status,5     ;恢复到文件寄存器体0
                clrf                decimal
                clrf                hundred
                clrf                thousand
                clrf                r0
                movlw                0x0
                movwf                porta
                movwf                portd
                movlw                0x34
                movwf                t1con
                movlw                0xc0
                movwf                intcon
                movlw                tmr1lb
                movwf                tmr1l
                movlw                tmr1hb
                movwf                tmr1h
                bsf                        t1con,0
                movlw            0x41
                movwf                adcon0
start                nop
                call                display
                call                ad_conversion
                goto                start
;*********************************************
;*************ad conversion value*************
ad_conversion
                        btfsc                adcon0,2
                        goto                exit
                        movf                adresh,0
                        movwf                ad_value
                        clrf                bit
                        clrf                decimal
                        clrf                hundred
                        clrf                thousand
                        clrf                r0
                        clrf                r
;*********************************************
                        movf                ad_value,0
                        sublw                ad_4v
                        btfsc                status,0
                        goto                next
                        movlw                0x04
                        movwf                thousand
                        movlw                ad_4v
                        subwf                ad_value,1
                        btfsc                status,2
                        goto                exit
                        goto                result
;**********************************************
next                        movf                ad_value,0
                        sublw                ad_3v
                        btfsc                status,0
                        goto                next0
                        movlw                0x03
                        movwf                thousand
                        movlw                ad_3v
                        subwf                ad_value,1
                        btfsc                status,2
                        goto                exit
                        goto                result
;*********************************************
next0                movf                ad_value,0
                        sublw                ad_2v
                        btfsc                status,0
                        goto                next1
                        incf                thousand
                        incf                thousand
                        movlw                ad_2v
                        subwf                ad_value,1
                        btfsc                status,2
                        goto                exit
                        goto                result
;*********************************************
next1                movf                ad_value,0
                        sublw                ad_1v
                        btfsc                status,0
                        goto                result
                        incf                thousand
                        movlw                ad_1v
                        subwf                ad_value,1
                        btfsc                status,2
                        goto                exit
;****************************************
result                bcf                        status,0
                        decfsz                ad_value,1
                        btfsc                status,0
                        goto        lpdeci
                        incf                decimal
                        movlw                0x07
                        addwf                bit,1
                        movf                bit,0
                        movwf                r
                        movlw                0x0a
                        subwf                r,1
                        btfsc                status,0
                        call                inc_deci
                        goto                result
;*****************************************
lpdeci                movf                decimal,0
                        movwf                r0
lp_deci                movf                r0,0
                        movwf                decimal
                        movlw                0x0a
                        subwf                r0,1
                        btfsc                status,0
                        goto                inc_hund
                        goto                exit
inc_hund           incf                hundred
                        goto                lp_deci
;*****************************************
exit                        nop
                        return
;***************inc decimal***************
inc_deci                movf                r,0
                        movwf                bit
ret                        incf                decimal
                        return
;******************************************
;                                Display
;******************************************
display                movf                  decimal,0
                        call        numb
                        movwf                  portd
                        movlw                  0x08
                         movwf                  porta
                         call   delay
;******************************************
            movf                  hundred,0
            call        numb
            movwf                  portd
            movlw                  0x10
            movwf                  porta
            call   delay
;******************************************
            movf                  thousand,0
            call        numb
            movwf                  portd
            movlw                  0x20
            movwf                  porta
            call   delay
                        return
;******************************************
;                                Delay
;******************************************
delay                             movlw   0x2
                          movwf   71h
lp1                            decfsz    71h,1
                               goto     lp1
                               return     
;******************************************
;                                Table
;******************************************
numb                      addwf        pcl,1
                retlw        0x3f
                retlw        0x06
                retlw        0x5b
                retlw        0x4f
                retlw        0x66
                retlw        0x6d
                retlw        0x7d
                retlw        0x07
                retlw        0x7f
                retlw        0x6f
                        end

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
windirection
1楼-- · 2019-03-26 00:32
今天在厂里面有软件跑了一天,没有问题。回来在板子上运行了几下,跑了几转也没有问题。不知道怎么弄的就不行了,死机了,跑不了。把红 {MOD}里面的改为一个数字送到AD—value后,用软件自己可以跑。板子也没有问题,下别的程序可以跑。
windirection
2楼-- · 2019-03-26 05:39
哪位大神帮忙看下啊

一周热门 更多>