就是C调用汇编函数得常规问题。但结合该具体问题。
参数传递:
CURRENCE_TIME data 50h
其下得6个字节,分别放年月日,时分秒。
但是汇编程序中,该参数传递用得是R0。
谢谢大家帮忙。
$MOD51
ORG 0000H
LJMP START
ORG 03H
LJMP IntRet
ORG 000BH
; LJMP CLOCK
LJMP IntRet
ORG 13H
LJMP IntRet
ORG 1BH
LJMP IntRet
ORG 23H
LJMP IntRet
ORG 2BH
LJMP IntRet
INTRET:
NOP
RETI
; ;
ORG 100H
START: MOV SP,#62H
MOV PSW,#00
mov 87h,#00h ; PCON
;...initialize SIO and counter
MOV 87H,#00H
MOV TMOD,#21H ; working mode of timer1, timer2
; MOV A,#B1200
;; MOV TH1,A ; auto-reload for baud rate
; MOV TL1,A ; timer 1
; MOV TL0,#TLL0 ; timer0
; MOV TH0,#THH0
SETB TR0
SETB TR1
MOV SCON,#0D0H ; SIO working mode
nop
clr TI
clr RI
mov SCON, #0D0h
lcall init_time
CLR A
mov r0,#CURRENCE_TIME
mov @r0,#0
inc r0
mov @r0,#0
inc r0
mov @r0,#0
inc r0
mov @r0,#0
inc r0
mov @r0,#0
inc r0
mov @r0,#0
inc r0
mov @r0,#0
inc r0
lcall read_time
mov a,r7
loop:
ajmp loop
;*******************
;*** ADDING HERE ***
;*******************
;..................
;......DS1302......
;..................
;input : @r0
;output : no
;trash : no
;
init_time:
mov r0,#CURRENCE_TIME
mov @r0,#30h
inc r0
mov @r0,#31h
inc r0
mov @r0,#16h
inc r0
mov @r0,#21h
inc r0
mov @r0,#12h
inc r0
mov @r0,#02h
mov r0,#CURRENCE_TIME
lcall write_time
ret
;input : @r0
;output : no
;trash : r5 : counter r6 : address r7 : content
;
write_time:
mov a,r7
PUSH ACC
mov a,r6
PUSH ACC
mov a,r5
PUSH ACC
mov r6,#8eh
mov r7,#0
lcall send_t1 ;WP=0
mov a,@r0
mov r7,a
mov r6,#80h
lcall send_t1 ;sec
inc r0
mov a,@r0
mov r7,a
mov r6,#82h
lcall send_t1 ;min
inc r0
mov a,@r0
mov r7,a
mov r6,#84h
lcall send_t1 ;hour
inc r0
mov a,@r0
mov r7,a
mov r6,#86h
lcall send_t1 ;dat
inc r0
mov a,@r0
mov r7,a
mov r6,#88h
lcall send_t1 ;mon
inc r0
mov a,@r0
mov r7,a
mov r6,#8ch
lcall send_t1 ;year
mov r7,#0a0h
mov r6,#90h
lcall send_t1 ;trickle
mov r7,#0
mov r6,#0beh
lcall send_t1 ;burst
mov r7,#0a5h
mov r6,#0c2h
lcall send_t1 ;run flag
mov r7,#5ah
mov r6,#0c4h
lcall send_t1
mov r7,#80h
mov r6,#8eh
lcall send_t1 ;WP = 1
mov r7,#80h
mov r6,#8eh
lcall send_t1 ;WP = 1
POP ACC
mov r5,a
POP ACC
mov r6,a
POP ACC
mov r7,a
ret
;input : no
;output : CURRENCE_TIME
;trash : r0 r5 r6 r7
;
read_time:
mov a,r7
PUSH ACC
mov a,r6
PUSH ACC
mov a,r5
PUSH ACC
mov a,r0
PUSH ACC
mov r7,#80h
mov r6,#8eh
lcall send_t1 ;WP = 1
mov r0,#CURRENCE_TIME
mov r6,#81h
lcall recv_t1
mov a,r7
mov @r0,a ;sec
inc r0
mov r6,#83h
lcall recv_t1
mov a,r7
mov @r0,a ;min
inc r0
mov r6,#85h
lcall recv_t1
mov a,r7
mov @r0,a ;hour
inc r0
mov r6,#87h
lcall recv_t1
mov a,r7
mov @r0,a ;date
inc r0
mov r6,#89h
lcall recv_t1
mov a,r7
mov @r0,a ;mon
inc r0
mov r6,#8dh
lcall recv_t1
mov a,r7
mov @r0,a ;year
POP ACC
mov r0,a
POP ACC
mov r5,a
POP ACC
mov r6,a
POP ACC
mov r7,a
ret
;input : r6 : address r7 : content
;output : no
;trash : r5
;
send_t1:
clr T_SCLK
nop
setb T_RST
nop
mov r5,#08
clr C
mov a,r6
send_t100:
clr T_SCLK
nop
nop
rrc a
mov T_IO,C
nop
nop
setb T_SCLK
nop
nop
djnz r5,send_t100
mov r5,#08
clr C
mov a,r7
send_t101:
clr T_SCLK
nop
nop
rrc a
mov T_IO,C
nop
nop
setb T_SCLK
nop
nop
djnz r5,send_t101
clr T_RST
nop
clr T_SCLK
clr T_IO
ret
;input : r6 : address r7 : content
;output : no
;trash : r5
;
recv_t1:
clr T_SCLK
nop
setb T_RST
mov r5,#08
clr C
mov a,r6
recv_t100:
clr T_SCLK
nop
nop
rrc a
mov T_IO,C
nop
nop
setb T_SCLK
nop
nop
djnz r5,recv_t100
mov r5,#08
clr C
mov a,r7
mov r5,#08
clr C
mov a,#0
recv_t101:
clr T_SCLK
nop
nop
mov C,T_IO
rrc a
nop
nop
setb T_SCLK
nop
nop
nop
djnz r5,recv_t101
nop
clr T_RST
nop
clr T_SCLK
clr T_IO
mov r7,a
ret
T_SCLK BIT P3.4
T_IO BIT P3.3
T_RST BIT P1.4
;
dseg AT 23H
COUNT: DS 1
CURRENCE_TIME data 50h
END
点击回主题参与讨论 > > >
_____________________________________________________________________________
Copyright©,C51BBS论坛 2000-2003