📄 appl2.a51
字号:
;**************
;* APPL2.A51 *
;**************
;
; iDCM 44 Sample Application: Part 2
;
$nolist
$include(dcx51a.ext)
$include(dcx51a.lit)
$include(dcx51a.mac)
$list
;
; Sample Application: Consists of Task 3 and Task 4, which do the following:
;
; Task 3: Loop
; Send message to task 4
; Wait for reply message
; End Loop
;
; Task 4: Loop
; Wait for message
; Send reply
; Flash red led if 256th message
; End Loop
;
; To generate this sample, perform the following:
;
; ASM51 APPL2.A51 DEBUG
; RL51 DCM44I.LIB(DCM44_SPACE), APPL2.OBJ, DCX51I.LIB TO APPL2
; OH APPL2 TO APPL2.HEX
;
; To execute on an Intel iRCB board, place a 2K x 8 SRAM into the empty
; universal memory site, and set the board for memory option B. Next,
; use the Bitbus Monitor to download both APPL1.HEX and APPL2.HEX
; into the SRAM. Upon reset, tasks 1, 2, 3, and 4 will execute (and both
; LEDs will start flashing). Note that since the system clock tick is
; redefined in the IDD below back to 1 msec., the green LED flashed by
; task 2 now toggles 10 times per second rather that once per second as
; when only tasks 1 and 2 are running.
;
; APPL1 and APPL2 can also be executed out of EPROM, or by using an emulator,
; such as ICE5100.
;
APPL2_DATA_SEG SEGMENT DATA
RSEG APPL2_DATA_SEG
MSG_COUNT: DS 1
MSG_PTR: DS 1
CSEG AT 0F800H
ITD3:
%ITD(TASK3, 6, 083H, 000B, 01H, 00000B, ITD4)
ITD4:
%ITD(TASK4, 4, 084H, 000B, 01H, 00000B, IDD)
IDD:
%IDD(-1000, 0, 0, 0, 0) ;set system clock granularity back to 1 msec.
;
; Equates
;
RED_LED EQU 90H
MESSAGE_LENGTH EQU 08H
COMMAND_FLAG EQU 00H
REPLY_FLAG EQU 80H
USER_DEFINED_COMMAND EQU 03H
SAMPLE_DATA_BYTE EQU 06H
;
; The code for Tasks 3 and 4 follows
;
TASK3:
CALL RQALLOCATE ;Get a message buffer
MOV MSG_PTR,A ;Point MSG_PTR to buffer
ADD A,#2 ;
MOV R0,A ;R0 => length field
MOV @R0,#MESSAGE_LENGTH ;Message length = 8
INC R0 ;R0 => flag field
MOV @R0,#COMMAND_FLAG ;set msg type = command
INC R0 ;R0 => dest. node addr field
MOV @R0,#0 ;message to be sent locally
INC R0 ;R0 => source & dest. task ids
MOV A,#84H ;Get task id for fid = 84
ACALL TASK_OF ;"
MOV B,A ;B = dest id
MOV A,RQTASKID ;A = source id
SWAP A ;Place source id in high nibble
ORL A,B ;Place dest id in low nibble
MOV @R0,A ;Insert src & dest task ids
INC R0 ;R0 => command field
MOV @R0,#USER_DEFINED_COMMAND ;Initialize command field
INC R0 ;R0 => data field
MOV @R0,#SAMPLE_DATA_BYTE ;Initialize data field
LOOP3:
MOV DPL,MSG_PTR ;Send message to task 3
MOV DPH,#0
CALL RQSENDMESSAGE ;
MOV A,#MESSAGE_EVENT ;And wait for reply message
MOV B,#WAIT_FOREVER ;indefinitely
CALL RQWAIT ;
MOV MSG_PTR,R7 ;
MOV A,R7 ;
ADD A,#3 ;
MOV R0,A ;R0 => FLAG FIELD
MOV @R0,#COMMAND_FLAG ;Change message back to command
SJMP LOOP3 ;and send it again
TASK_OF:
; Returns the task id for the specified function id, if there is one
; Inputs: ACC = function id
; Outputs: ACC = task id OR 0ffh, if the function id is not found
;
MOV B,A ;B = FID
MOV R1,#8 ;Initialize count
MOV DPTR,#RQFIDTABLE ;Initialize pointer
MOV R2,#0 ;Initialize index
TO_LOOP:
MOVX A,@DPTR ;
CJNE A,B,TO_NO_MATCH ;If not match, jump
MOV A,R2 ;Load acc with task id
RET ;And return
TO_NO_MATCH:
INC DPTR ;Increment pointers etc.
INC R2 ;
DJNZ R1,TO_LOOP ;
MOV A,#0FFH ;If task id not found,
RET ;return with 0ffh
TASK4:
CLR RED_LED ;
MOV MSG_COUNT,#0H ;Init. message counter
LOOP4:
MOV A,#MESSAGE_EVENT ;Wait for a command message
MOV B,#WAIT_FOREVER ;indefinitely
CALL RQWAIT ;
MOV DPL,R7 ;
MOV DPH,#0 ;DPTR => command message
MOV A,R7 ;
ADD A,#3 ;
MOV R0,A ;R0 => flag field
MOV A,@R0 ;A = flag contents
ORL A,#REPLY_FLAG ;Or-in reply flag bit
MOV @R0,A ;Change message to reply and
CALL RQSENDMESSAGE ;Return message to sender
DJNZ MSG_COUNT,LOOP4 ;Decrement message counter
CPL RED_LED ;If zero, toggle red led
SJMP LOOP4 ;Loop
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -