📄 1620temp.lst
字号:
03C8 F2 =1 715 MOVX @R0, A ; Disable interrupts from OUT Endpoints 0-7
03C9 08 =1 716 INC R0
03CA 7403 =1 717 MOV A, #00000011b
03CC F2 =1 718 MOVX @R0, A ; Enable (Resume, Suspend,) SOF and SUDAV INTs
03CD 08 =1 719 INC R0
03CE 7401 =1 720 MOV A, #00000001b
03D0 F2 =1 721 MOVX @R0, A ; Enable Auto Vectoring for USB interrupts
=1 722 ; Now enable the main level
03D1 75E801 =1 723 MOV EIE, #00000001b ; Enable INT2 = USB Interrupt (only)
03D4 75A8C0 =1 724 MOV EI, #11000000b ; Enable interrupt subsystem (and Ser1 for dScope)
=1 725
=1 726 ; Initialization Complete.
=1 727 ;
03D7 =1 728 MAIN:
03D7 00 =1 729 NOP ; Not much of a main loop for this example
03D8 80FD =1 730 JMP MAIN ; All actions are initiated by interrupts
=1 731 ; We are a slave, we wait to be told what to do
=1 732
03DA =1 733 Wait100msec:
03DA 754064 =1 734 MOV Temp, #100
03DD =1 735 Wait1msec: ; A delay loop
03DD 90FB50 =1 736 MOV DPTR, #-1200
03E0 A3 =1 737 More: INC DPTR ; 3 cycles
03E1 E582 =1 738 MOV A, DPL ; + 2
03E3 4583 =1 739 ORL A, DPH ; + 2
03E5 70F9 =1 740 JNZ More ; + 3 = 10 cycles x 1200 = 1msec
03E7 D540F3 =1 741 DJNZ Temp, Wait1msec
03EA 22 =1 742 RET
=1 743
03EB =1 744 ProcessOutputReport: ; A Report has just been received
=1 745 ; The report is 12 bytes long in this example
=1 746 ; It contains a new limits values
03EB 907EC0 =1 747 MOV DPTR, #EP0OutBuffer ; Point to the Report
03EE 7846 =1 748 MOV R0, #LimitValues
03F0 7F0C =1 749 MOV R7, #12
03F2 E0 =1 750 CopyOR: MOVX A, @DPTR ; Get the Data
03F3 F6 =1 751 MOV @R0, A ; Update the local variable
03F4 A3 =1 752 INC DPTR
03F5 08 =1 753 INC R0
03F6 DFFA =1 754 DJNZ R7, CopyOR
03F8 22 =1 755 RET
=1 756
03F9 =1 757 CreateInputReport: ; Called from TIMER which detected the need
=1 758 ; The report is seven bytes long in this example
=1 759 ; It contains the temperature readings
03F9 907FB7 =1 760 MOV DPTR, #IN1ByteCount
03FC 7407 =1 761 MOV A, #7
03FE F0 =1 762 MOVX @DPTR, A ; Endpoint 1 now 'armed', next IN will get data
03FF 22 =1 763 RET
=1 764
765 $INCLUDE(1620Timr.A51)
A51 MACRO ASSEMBLER 1620TEMP 22/07/99 11:19:38 PAGE 13
=1 766 ; This module services the real time interrupt
=1 767 ; It is also responsible for the "real world" thermometers
=1 768 ;
=1 769 ; CHANGE SINCE THE BOOK TEXT WAS FINALIZED: Idle_Time is used by the Operating System
=1 770 ; to override the report times defined in the Endpoint Descriptor. A device driver
=1 771 ; will modify Idle_Time to change the reporting characteristics of a HID device.
=1 772 ; During initialization the OS sets Idle_Time = 0 which turns reporting OFF unless
=1 773 ; a change is detected; an application that starts to poll a HID device will appear
=1 774 ; to hang. While it is possible to write extra PCHost application code to re-enable
=1 775 ; Idle_Time is it simpler to defeat this mechanism by IGNORRING the Idle_Time value.
=1 776 ;
=1 777 ; Get a Real Time interrupt every One millisecond (using SOF interrupt)
=1 778 ;
=1 779 ; We have one task = Read the thermometers
=1 780 ; We will poll the thermometers at 100msec intervals and store the temperatures
=1 781 ; directly in the EP1InBuffer. This way the PCHost will always get the latest
=1 782 ; temperature readings.
=1 783 ;
=1 784 ; The hardware for this example is shown in Figure 9-7.
=1 785 ; We are using Port A for Output
=1 786 ; CLK is on Bit0, DQ is on Bit1 and the thermometers are selected by Bits[7:2]
=1 787 ;
=1 788 ; The registers used in this routine are:
=1 789 ; A = Value written to Port A
=1 790 ; DPTR = Pointer to EP1InBuffer
=1 791 ; R0 = Pointer to PortA_Out
=1 792 ; R1 = Pointer to PortA_Config then PortA_Pins
=1 793 ; R2 = a save register
=1 794 ; R5 = Data to be sent, or received
=1 795 ; R6 = Thermometer selector
=1 796 ; R7 = Bit counter
=1 797 ;
---- =1 798 CSEG
0400 =1 799 ServiceTimerRoutine:
0400 D5496F =1 800 DJNZ Msec_counter, Done ; Only need to check every 100msec
0403 754964 =1 801 MOV Msec_counter, #100 ; Reinitialize
=1 802 ;
0406 907E80 =1 803 MOV DPTR, #EP1InBuffer
0409 7896 =1 804 MOV R0, #Low(PortA_Out)
040B 7404 =1 805 MOV A, #00000100b ; Select pattern
040D FE =1 806 Loop: MOV R6, A
040E 7401 =1 807 MOV A, #00000001b ; Port A idle state
0410 4E =1 808 ORL A, R6
0411 F2 =1 809 MOVX @R0, A ; Select one of the thermometers
0412 7DAA =1 810 MOV R5, #0AAH ; Get temperature command
0414 120448 =1 811 CALL SendByte
0417 120457 =1 812 CALL ReceiveByte
041A EE =1 813 MOV A, R6 ; Get select pattern
041B C3 =1 814 CLR C ; Need to zero fill
041C 33 =1 815 RLC A ; Rotate pattern
041D 70EE =1 816 JNZ Loop
=1 817 ; Check for ALARMs
041F 907E80 =1 818 MOV DPTR, #EP1InBuffer ; Current temperature values
0422 7846 =1 819 MOV R0, #LimitValues ; Low limits
0424 794C =1 820 MOV R1, #LimitValues+6 ; High limits
0426 7D00 =1 821 MOV R5, #0 ; Alarm Value
0428 7E01 =1 822 MOV R6, #00000001b ; Alarm mask
042A 7F06 =1 823 MOV R7, #6 ; Counter
042C E0 =1 824 LCLoop: MOVX A, @DPTR
042D C3 =1 825 CLR C
042E 96 =1 826 SUBB A, @R0 ; Check low limit
042F 5003 =1 827 JNC Over1
0431 ED =1 828 MOV A, R5 ; Need to set this ALARM bit
0432 4E =1 829 ORL A, R6
0433 FD =1 830 MOV R5, A
0434 E0 =1 831 Over1: MOVX A, @DPTR
A51 MACRO ASSEMBLER 1620TEMP 22/07/99 11:19:38 PAGE 14
0435 C3 =1 832 CLR C
0436 97 =1 833 SUBB A, @R1 ; Check upper limit
0437 4003 =1 834 JC Over2
0439 ED =1 835 MOV A, R5 ; Need to set this ALARM bit
043A 4E =1 836 ORL A, R6
043B FD =1 837 MOV R5, A
043C EE =1 838 Over2: MOV A, R6 ; Rotate Alarm mask
043D 23 =1 839 RL A
043E FE =1 840 MOV R6, A
043F A3 =1 841 INC DPTR ; Update pointers
0440 08 =1 842 INC R0
0441 09 =1 843 INC R1
0442 DFE8 =1 844 DJNZ R7, LCLoop
0444 ED =1 845 MOV A, R5 ; Get Alarm byte
0445 F0 =1 846 MOVX @DPTR, A ; Store in Byte 7 of Report
0446 80B1 =1 847 JMP CreateInputReport ; RETurn via CreateInputReport
=1 848
0448 =1 849 SendByte: ; Transmit a byte to a thermometer
0448 7F08 =1 850 MOV R7, #8
044A 14 =1 851 SLoop: DEC A
044B F2 =1 852 MOVX @R0, A ; Set CLK low
044C CD =1 853 XCH A, R5 ; Get the data to be sent
044D 13 =1 854 RRC A ; Put LS bit in Carry
044E CD =1 855 XCH A, R5
044F 92E1 =1 856 MOV ACC.1, C ; Put data bit in DQ
0451 F2 =1 857 MOVX @R0, A
0452 04 =1 858 INC A
0453 F2 =1 859 MOVX @R0, A ; Set CLK high
0454 DFF4 =1 860 DJNZ R7, SLoop
0456 22 =1 861 RET
0457 =1 862 ReceiveByte: ; Receive a byte from a thermometer
0457 7F09 =1 863 MOV R7, #9 ; Actually we get 9 bits and discard bit0
0459 FA =1 864 MOV R2, A ; Save A while we reconfigure
045A 799C =1 865 MOV R1, #Low(PortA_OE)
045C 74FD =1 866 MOV A, #11111101b
045E F3 =1 867 MOVX @R1, A ; Set bit 1 as input
045F 7999 =1 868 MOV R1, #Low(PortA_Pins)
0461 EA =1 869 MOV A, R2 ; Retreive A
0462 14 =1 870 GLoop: DEC A
0463 F2 =1 871 MOVX @R0, A ; Set CLK low
0464 00 =1 872 NOP ; Give thermomemter time to respond
0465 E3 =1 873 MOVX A, @R1 ; Read the data bit
0466 A2E1 =1 874 MOV C, ACC.1 ; Copy DQ into Carry
0468 CD =1 875 XCH A, R5
0469 13 =1 876 RRC A ; Copy DQ into MSB
046A CD =1 877 XCH A, R5
046B 04 =1 878 INC A
046C F2 =1 879 MOVX @R0, A ; Set CLK high
046D DFF3 =1 880 DJNZ R7, GLoop
046F ED =1 881 MOV A, R5 ; Get the received temperature
0470 F0 =1 882 MOVX @DPTR, A ; Save in EPOInBuffer
0471 A3 =1 883 INC DPTR
0472 22 =1 884 Done: RET
=1 885
886
887 END
A51 MACRO ASSEMBLER 1620TEMP 22/07/99 11:19:38 PAGE 15
SYMBOL TABLE LISTING
------ ----- -------
N A M E T Y P E V A L U E ATTRIBUTES
ACC . . . . . . . . . . . D ADDR 00E0H A
B . . . . . . . . . . . . D ADDR 00F0H A
BADREQUEST. . . . . . . . C ADDR 01C6H A
BUMPDPTR. . . . .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -