• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 16F84A 電壓表
#6
版主
版主


查看用戶資訊
程式這樣貼出來有些自已經亂掉了,我在猜應該是日文的注解。是否可以將檔案壓成 ZIP 後上傳方便修改。

發表於: 2010/2/22 10:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


16F84A 電壓表
#5
新會員
新會員


查看用戶資訊
這是在日本的一個網站 用16F84A 做電壓表 0-30V

我覺得蠻實用的~~不過 不太懂組語..弄在MPLAB IDE裡..

語法要修改~~希望有大大..能抽空指導 ^^



; ?mV3L.asm 2006.5.6
; jk1xkp
; 覦?FFC3L.asm ; 
;  PIC16F84A-20/P?
;
; ? 10.0MHz?
;

;?????
; ( H:open(LED L:4.7kGRD?)
;  LED???(A-F)
; ()??
; RA4(03) ? OP amp output
; RA3(02) ? 0.068F
; RA2(01) ? K1 ?
; RA1(18) ? K2 ?
; RA0(17) ? K3 ?
; LED segment output /input
; RB7(13) ?B
; RB6(12) ?E
; RB5(11) ?F
; RB4(10) ?A
; RB3(09) ?D SW-1; 25.5
; RB2(08) ?Dp SW-2; 2.55
; RB1(07) ?C
; RB0(06) ?G
;
;
;
.include 16f84.h ; 

.osc hs ; ?
.wdt off ; 
.pwrt on ; ?
.protect off ; ?

K1 equ ra.2
K2 equ ra.1
K3 equ ra.0

org 0ch

wait_cn ds 1
wait_cn2 ds 1
cn ds 1
cs ds 1 ;sub-counter
; --------------- adress 10&H
x ds 4 ;X #10h 
v ds 4 ;
y ds 4
poi ds 1
mode ds 1 ;if rb.2=L, K2 Dp. if rb.3=L, K1 Dp.
overf ds 1
test ds 1
; -------------- adress 20&H
dec ds 10 ; 10?
dec_top
val ds 4 ; 
val_m ds 1 ; ????
N ds 1 ;preccaler 1/N=1,2,3,4,5,6,8,9,10
; ------------- adress 30&H
dsp ds 6 ;LED 3?+Dp3?


org 0

goto start
org 4

tablenum
addwf pc,1 ;cycle3
; BEFADpCG 7segment AF
retlw 11111010b ;letter 0
retlw 10000010b ;letter 1
retlw 11011001b ;letter 2 A
retlw 10011011b ;letter 3 ____
retlw 10100011b ;letter 4 F | | B
retlw 00111011b ;letter 5 |_G__|
retlw 01111011b ;letter 6 E | | C
retlw 10010010b ;letter 7 |____|
retlw 11111011b ;letter 8 D
retlw 10110011b ;letter 9
retlw 01110001b ;letter F
retlw 01101000b ;letter L
retlw 01111000b ;letter C
retlw 11110011b ;letter A
retlw 00000000b ;blank
retlw 00000100b ;letter Dp
sleep

;----------------------------------------------------------------------------
start
mov wait_cn,#255
call wait_ms

bsf status,5 ;?1
movlw 01000010b ;RB?;prescaler 1/8 set ;bit5=???
movwf option

movlw 00010000b ;ra0-ra3 inputoutput
movwf 5
bcf status,5 ;?0
clr ra

mov dsp[5],#0eh ; 1mv ?Dp blink/???
bcf porta,3
mov wait_cn,#255
call wait_ms

mv
clr v[0]
clr v[1]
clr v[2]
clr v[3]

bsf K1
bsf K2
bsf K3

bsf status,5 ;?1
movlw 11111111b ;rb.0-rb.7?in  !rb,#11111111b
movwf 6 ;trisb
bcf status,5 ;?0
clr rb
nop
movf portb,0 ;portb ?
movwf mode

mv1 ;720usec ;??

bsf status,5 ;?1
movlw 00011000b ;ra3 outputinput; 0.068F*200k
movwf 5
bcf status,5 ;?0
bcf intcon,2 ;clr TOIF
clrf tmr0 ;TMR0?
clrwdt ;prescaler?

mv2
movf intcon,0 ;1cycle | |
movwf overf ;1cycle | |
btfsc overf,2 ;2cycle | |
incf v[1],1 ;0 | |
btfsc overf,2 ;2cycle | |
bcf intcon,2 ;0cycle | |

btfsc v[1],4 ;2 step;---if overflow(V>4095mV), goto mv3
goto mv3 ;0 |
; | 1Loop=11step
btfss porta,4 ;1step |
goto mv2 ;2step---|

mv3 movf tmr0,0 ;W TRM0
movwf v[0]

btfsc intcon,2
incf v[1],1

bsf status,5 ;?1
movlw 00010000b ;ra3 inputoutput
movwf 5
bcf status,5 ;?0
clr ra
bcf porta,3 ;0.068F 

movlw 20
subwf v[0],1 ;v[0]=v[0]+(256-20)

movlw 1
btfss c ;if C=0 ,W=1
subwf v[1],1 ;v[1]=v[1]+(256-1)

btfsc c ;if C=0 ,then v[0]=v[1]=0
goto mv4
movlw 0
movwf v[1]
movwf v[0]

mv4 mov val[0],v[0]
mov val[1],v[1] ; ;0  4095mV
clrf val[2]
clrf val[3]

call dcmain
movf dec[6],1
btfsc z ;if dec[6]=not zero, ?/1?V?Dp??
goto dpmV
mov dsp[5],#0fh ;?;;1?V?Dp??

;dec[6]=1000mv,dec[7]=100mv,dec[8]=10mv,dec[9]=1mv

dpmV mov dsp[3],dec[7] ; 100mv?
mov dsp[2],dec[8] ; 10mv ?
mov dsp[1],dec[9] ; 1mv ?
mov dsp[4],#0eh ; 10mv ?Dp blank
mov dsp[0],#0eh ; 100mv ?Dp blank

btfss mode,2 ;if SW-2 ON, 100mv?Dp
goto dp1000
btfss mode,3 ;if SW-1 ON, 10mv?Dp
goto dp100
goto dpend

dp1000 mov dsp[0],#0fh ; 100mv?Dp 
btfsc mode,3 ;if SW-1 ON, 10mv?Dp
goto dpend
mov dsp[4],#0fh ; 10mv ?Dp 
goto dpend

dp100 mov dsp[4],#0fh ; 10mv ?Dp 

dpend bsf status,5 ;?1
movlw 00000000b ;rb.0-rb.7?out  !rb,#00000000b
movwf 6 ;trisb
bcf status,5 ;?0
clr rb

call wt500ms ;LEDdynamic drive
goto mv
;-----------------------

;----------------------------------
wt500ms mov cn,#160
wt_1ms call display
decfsz cn,1
goto wt_1ms

mov dsp[5],#0eh ; 1mv ?Dp blink/???
mov cn,#160
wt_2ms call display
decfsz cn,1
goto wt_2ms
return

display ;ca.3700steps
movf dsp[3],0 ;100mV? ;1
call tablenum ;2cycle /3cycle ;2+4
movwf portb ;1
bcf K1 ;1
call delay244 ;2+610
clrf portb ;1
bsf K1 ;1 (=623)

movf dsp[2],0 ;10mV?
call tablenum ;2cycle /3cycle
movwf portb
bcf K2
call delay244 ;2+610
clrf portb
bsf K2 ;1 (=623)

movf dsp[1],0 ;1mV?
call tablenum ;2cycle /3cycle
movwf portb
bcf K3
call delay244 ;2+610
clrf portb
bsf K3 ;1 (=623)

movf dsp[0],0 ;Dp 100mV?
call tablenum ;2cycle /3cycle
movwf portb
bcf K1
call delay244 ;2+610
clrf portb
bsf K1 ;1 (=623)

movf dsp[4],0 ;Dp 10mV?
call tablenum ;2cycle /3cycle
movwf portb
bcf K2
call delay244 ;2+610
clrf portb
bsf K2 ;1 (=623)

movf dsp[5],0 ;Dp 1mV?
call tablenum ;2cycle /3cycle
movwf portb
bcf K3
call delay244 ;2+610
clrf portb
bsf K3 ;1 (=623)

ret ;2 (=4)
;--------------------------------------------
delay244 ;------------------------605steps=240.0 usec??------------
movlw 200 ;1+(200*3cycle+2+2)=605---------------------
movwf wait_cn ;1cycle | |
call wait_us ;2cycle | |
ret ;2cycle-----------------------
; ;-----------------------------------------------------------------
; -------------------------------------------------------------------
wait_us ;3 steps=1.2??
wait_us0 decfsz wait_cn,1
goto wait_us0
ret

;
; ??
;
wait_ms
wait_ms0
mov wait_cn2,#0
wait_ms1
nop
nop
nop
nop
nop
nop
nop

djnz wait_cn2,wait_ms1
djnz wait_cn,wait_ms0
ret

;---------------------------------------------------------
;  ?(32bit)??(32bit)y(32bit)
;
sub_xy
sub x[0],y[0]
movlw 1
btfss c
subwf x[1],1
btfss c
subwf x[2],1
btfss c
subwf x[3],1

sub x[1],y[1]
movlw 1
btfss c
subwf x[2],1
btfss c
subwf x[3],1

sub x[2],y[2]
movlw 1
btfss c
subwf x[3],1

sub x[3],y[3]
ret
;--------------------------------------------------------------------
;  ?(32bit)??(32bit)y(32bit)
;
add_xy
add x[0],y[0]
movlw 1
btfsc c
addwf x[1],1
btfsc c
addwf x[2],1
btfsc c
addwf x[3],1

add x[1],y[1]
movlw 1
btfsc c
addwf x[2],1
btfsc c
addwf x[3],1

add x[2],y[2]
movlw 1
btfsc c
addwf x[3],1

add x[3],y[3]
ret
;---------------------------------------------------------------------
; ?
;
; valval[3]:val[2]:val[1]:va[0])
;
; dcmain?
;
; dec?
; (dec[0]:dec[1]:...:dec[8]:dec[9])
; dec[0]?dec[9]?
;
; val
;
; sample:
; val = 00:00:04:D2 h
; dec = 00:00:00:00:00:00:01:02:03:04
; dec(0):dec(1):(2):(3):(4):(5):(6):(7):(8):dec(9)
; (1,234)
;


dcmain
mov fsr,#dec_top ; ??
call devide ; 
call devide ;10
call devide
call devide
call devide

call devide
call devide
call devide
call devide
call devide ; 
ret

;
; ???
; ?
;
devide
mov cn,#32 ; 

clr val_m
devide0
clc
rl val[0]
rl val[1]
rl val[2]
rl val[3]
rl val_m

movlw 11110110b
addwf val_m,0
btfsc c
mov val_m,w
btfsc c
inc val[0]

djnz cn,devide0

dec fsr
mov indirect,val_m ; 
ret
;----------------------------------------end of 10
;-----------------------------------------------------------------------
;  x[32bit]=y[32bit] * N[8bit]
;
; y32
; y[3]:y[2]:y[1]:y[0])
; N 8咑紕蹬偯
; N ;  #255
;
; x?
; x[3]:x[2]:x[1]:x[0])
;
;  N 
;
;
mult_vN clr x[3]
clr x[2]
clr x[1]
clr x[0]

mov cn,#8
mult0
btfss N,0
goto mutpas
add x[0],y[0]
movlw 1
btfsc c
addwf x[1],1
btfsc c
addwf x[2],1
btfsc c
addwf x[3],1

add x[1],y[1]
movlw 1
btfsc c
addwf x[2],1
btfsc c
addwf x[3],1

add x[2],y[2]
movlw 1
btfsc c
addwf x[3],1

add x[3],y[3]

mutpas clrb c
rl y[0]
rl y[1]
rl y[2]
rl y[3]
btfsc c
bsf y[0],0

clrb c
rr N
btfsc c
bsf N,7

djnz cn,mult0

mov cn,#8
multrot clrb c
rr y[3]
rr y[2]
rr y[1]
rr y[0]
btfsc c
bsf y[3],7
djnz cn,multrot
ret
;---------------------------end of 


發表於: 2010/2/14 14:29
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------