📄 fs511.src.bak
字号:
;*******************************************************;
;model: scale ;
;author: henny ;
;create date: 2007/1/13 ;
;modify date: 2007/3/1 ;
;chip: samsung s3f9488 ;
;note: copyright (c) 2007 chas electronics co. ;
;*******************************************************;
.include "s3c9488.reg"
.include "memory.h"
.include "macro.src"
.org 0100h
reset:
di
ld wdtcon,#10101010b ; disable watch dog
ld clkcon,#00011000b ; fxx/1(4mhz)
ld sp,#0c0h
call fs511_init
;ld r0,#neta
;call fs511_read
;ld r0,#netb
;call fs511_read
;ld r0,#netc
;call fs511_read
;ld r0,#netd
;call fs511_read
call get_scale_zero
call calcul_gain
main:
call get_ad_average_data
call calcul_count
jr main
;---------------------------------------;
test_addr_bit:
jr z,test_addr_bit_out_0
setb fs511,di
dly
jr test_addr_bit_out_1
test_addr_bit_out_0:
clrb fs511,di
dly
test_addr_bit_out_1:
sk_pls
ret
;---------------------------------------;
;fs511 write function
;address:r0,data:r1
;---------------------------------------;
out_a_byte:
ld r8,#8
out_loop:
rlc r1
jr c,out_bit1
clrb fs511,di
jp out_bit0
out_bit1:
setb fs511,di
out_bit0
sk_pls
dec r8
jr nz,out_loop
ret
;---------------------------------------;
fs511_write:
clrb fs511,cs
dly
clrb fs511,di
dly
sk_pls
tmb r0,1
call test_addr_bit
tmb r0,0
call test_addr_bit
clrb fs511,di
sk_pls
call out_a_byte
setb fs511,cs
clrb fs511,di
dly
ret
;---------------------------------------;
;fs511 read function
;address:r0,return value:r1
;---------------------------------------;
get_a_byte:
push r8
ld r8,#8
get_loop:
tmb fs511,do
jr nz,get_bit1
rcf
jr get_bit0
get_bit1:
scf
get_bit0:
rlc r1
sk_pls
dec r8
jr nz,get_loop
pop r8
ret
;---------------------------------------;
fs511_read:
clrb fs511,cs
dly
tmb r0,2
call test_addr_bit
tmb r0,1
call test_addr_bit
tmb r0,0
call test_addr_bit
setb fs511,di
sk_pls
call get_a_byte
setb fs511,cs
clrb fs511,di
dly
ret
;---------------------------------------;
;fs511 init function
;---------------------------------------;
fs511_init:
ld p3conh,#00101010b
ld p3int,#00h
setb fs511,cs
dly
setb fs511,sk
dly
setb fs511,di
dly
clrb fs511,do
dly
setb fs511,do
dly
setb fs511,cs
dly
ld r0,#neta
ld r1,#88h
call fs511_write
ld r0,#netb
ld r1,#0e0h
call fs511_write
ld r0,#netc
ld r1,#93h
call fs511_write
ld r0,#netd
ld r1,#57h
call fs511_write
ret
;---------------------------------------;
;get ad convert data function
;24 bit ad data:data_buf,data_buf+1,data_buf+2
;---------------------------------------;
get_ad_convert_data:
tmb fs511,rdby
jr nz,get_ad_convert_data
clrb fs511,cs
dly
setb fs511,di
dly
sk_pls
clrb fs511,di
dly
sk_pls
clrb fs511,di
dly
sk_pls
setb fs511,di
dly
sk_pls
call get_a_byte
ld ad_data,r1
call get_a_byte
ld ad_data+1,r1
call get_a_byte
ld ad_data+2,r1
setb fs511,cs
clrb fs511,di
dly
ret
;---------------------------------------;
get_ad_average_data:
call get_ad_convert_data
rcf
rlc ad_data+2
rlc ad_data+1
rlc ad_data
rcf
rlc ad_data+2
rlc ad_data+1
rlc ad_data
jr nc,normal_proess
com ad_data ;negative number
com ad_data+1
add ad_data+1,#1
adc ad_data,#0
normal_proess:
ld buf7_h,buf6_h
ld buf7_l,buf6_l
ld buf6_h,buf5_h
ld buf6_l,buf5_l
ld buf5_h,buf4_h
ld buf5_l,buf4_l
ld buf4_h,buf3_h
ld buf4_l,buf3_l
ld buf3_h,buf2_h
ld buf3_l,buf2_l
ld buf2_h,buf1_h
ld buf2_l,buf1_l
ld buf1_h,buf0_h
ld buf1_l,buf0_l
ld buf0_h,ad_data
ld buf0_l,ad_data+1
clr r7
clr data_h
clr data_l
rcf
add data_l,buf7_l
adc data_h,buf7_h
adc r7,#0
add data_l,buf6_l
adc data_h,buf6_h
adc r7,#0
add data_l,buf5_l
adc data_h,buf5_h
adc r7,#0
add data_l,buf4_l
adc data_h,buf4_h
adc r7,#0
add data_l,buf3_l
adc data_h,buf3_h
adc r7,#0
add data_l,buf2_l
adc data_h,buf2_h
adc r7,#0
add data_l,buf1_l
adc data_h,buf1_h
adc r7,#0
add data_l,buf0_l
adc data_h,buf0_h
adc r7,#0
push r8
ld r8,#3
div4:
rcf
rrc r7
rrc data_h
rrc data_l
dec r8
jr nz,div4
pop r8
ret
;---------------------------------------;
repeat_get_ad_data:
ld data2_h,data1_h
ld data2_l,data1_l
ld data1_h,data_h
ld data1_l,data_l
get_ad_stable_data:
call get_ad_average_data
cp data_h,data1_h
jr nz,repeat_get_ad_data
cp data_l,data1_l
jr nz,repeat_get_ad_data
cp data_h,data2_h
jr nz,repeat_get_ad_data
cp data_l,data2_l
jr nz,repeat_get_ad_data
ret
;---------------------------------------;
clear_data_buf:
clr data_h
clr data_l
clr data1_h
clr data1_l
clr data2_h
clr data2_l
ret
get_scale_zero:
call clear_data_buf
call get_ad_stable_data
ld zero_h,data_h
ld zero_l,data_l
ret
;---------------------------------------;
;Gain=Cal_Weight/(Weight_AD-Zero)
;---------------------------------------;
calcul_gain:
call clear_data_buf
call get_ad_stable_data
ld bufa_h,data_h
ld bufa_l,data_l
ld bufb_h,zero_h
ld bufb_l,zero_l
call int_sub ;Weight_AD-Zero
ld bufb_h,bufa_h
ld bufb_l,bufa_l
ld bufa_h,#13h ;eg:Cal_Weight=5000g
ld bufa_l,#88h ;define at eeprom
ld r8,#4
call int_div ;Cal_Weight/(Weight_AD-Zero)
ld gain_h,bufc_h
ld gain_l,bufc_l
ret
;---------------------------------------;
;Count=(Weight_AD-Zero)*Gain*10
;Weight=(Weight_AD-Zero)*Gain
;1 g=10 data
;---------------------------------------;
calcul_count:
ld bufa_h,gain_h
ld bufa_l,gain_l
ld r1,#10
call int_mul16x8 ;gain*10
ld r8,#8
calcul_count_loop1:
rcf
rlc r1
rlc bufa_l
rlc bufa_h
dec r8
jr nz,calcul_count_loop1
ld temp_h,bufa_h
ld temp_l,bufa_l
ld bufa_h,data_h
ld bufa_l,data_l
ld bufb_h,zero_h
ld bufb_l,zero_l
call int_cmp_a_b
tmb r0,7
jr z,calcul_count_l1
ld bufb_h,data_h
ld bufb_l,data_l
ld bufa_h,zero_h
ld bufa_l,zero_l
calcul_count_l1:
call int_sub ;Weight_AD-Zero
;ld bufb_h,gain_h
;ld bufb_l,gain_l
ld bufb_h,temp_h
ld bufb_l,temp_l
call int_mul16x16 ;(Weight_AD-Zero)*Gain*10
ld r8,#4
calcul_count_loop2:
rcf ;result=result*16
rlc bufb_l
rlc bufb_h
rlc bufa_l
rlc bufa_h
dec r8
jr nz,calcul_count_loop2
cp bufb_h,#80h
jr c,count_no_round
add bufa_l,#1
adc bufa_h,#0
count_no_round:
ld count_h,bufa_h
ld count_l,bufa_l
ld r10,bufa_h
ld r11,bufa_l
ret
;---------------------------------------;
;bufa(int)+bufb(int)=bufa(int)
;---------------------------------------;
int_add:
add bufa_l,bufb_l
adc bufa_h,bufb_h
ret
;---------------------------------------;
;bufa(int)-bufb(int)=bufa(int)
;---------------------------------------;
int_sub:
sub bufa_l,bufb_l
sbc bufa_h,bufb_h
ret
;---------------------------------------;
;add for mul,result at bufa
;---------------------------------------;
int_add_for_mul:
add bufa_l,bufc_l
adc bufa_h,bufc_h
ret
;---------------------------------------;
;bufb(int)-bufa(int) => r0(result)
;---------------------------------------;
int_cmp_b_a:
push bufb_h
push bufb_l
sub bufb_l,bufa_l
sbc bufb_h,bufa_h
ld r0,bufb_h
pop bufb_l
pop bufb_h
ret
;---------------------------------------;
;bufa(int)-bufb(int) => r0(result)
;---------------------------------------;
int_cmp_a_b:
push bufa_h
push bufa_l
sub bufa_l,bufb_l
sbc bufa_h,bufb_h
ld r0,bufa_h
pop bufa_l
pop bufa_h
ret
;---------------------------------------;
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -