📄 i2c.lst
字号:
---- =1 569 CSEG
02C5 =1 570 DeviceDescriptor:
02C5 1201 =1 571 DB 18, 1 ; Length, Type
02C7 0101 =1 572 DW 101H ; USB Rev 1.1
02C9 000000 =1 573 DB 0, 0, 0 ; Class, Subclass and Protocol
02CC 40 =1 574 DB 64 ; EP0 size
02CD 4242 =1 575 DW 4242H, 1, 1 ; Vendor ID, Product ID and Version
02CF 0001
02D1 0001
02D3 010200 =1 576 DB 1, 2, 0 ; Manufacturer, Product & Serial# Names
02D6 01 =1 577 DB 1 ; #Configs
02D7 =1 578 ConfigurationDescriptor:
02D7 0902 =1 579 DB 9, 2 ; Length, Type
02D9 2200 =1 580 DB LOW(ConfigLength), HIGH(ConfigLength)
A51 MACRO ASSEMBLER I2C 22/07/99 12:36:44 PAGE 10
02DB 010100 =1 581 DB 1, 1, 0 ; #Interfaces, Configuration#, Config. Name
02DE 80 =1 582 DB 10000000b ; Attributes = Bus Powered
02DF 32 =1 583 DB 50 ; Max. Power is 50x2 = 100mA
02E0 =1 584 InterfaceDescriptor:
02E0 0904 =1 585 DB 9, 4 ; Length, Type
02E2 000001 =1 586 DB 0, 0, 1 ; No alternate setting, HID uses EP1
02E5 03 =1 587 DB 3 ; Class = Human Interface Device
02E6 0000 =1 588 DB 0, 0 ; Subclass and Protocol
02E8 00 =1 589 DB 0 ; Interface Name
02E9 =1 590 HIDDescriptor:
02E9 0921 =1 591 DB 9, 21H ; Length, Type
02EB 0001 =1 592 DB 0, 1 ; HID Class Specification compliance
02ED 00 =1 593 DB 0 ; Country localization (=none)
02EE 01 =1 594 DB 1 ; Number of descriptors to follow
02EF 22 =1 595 DB 22H ; And it's a Report descriptor
02F0 1F00 =1 596 DB LOW(ReportLength), HIGH(ReportLength)
02F2 =1 597 EndpointDescriptor:
02F2 0705 =1 598 DB 7, 5 ; Length, Type
02F4 81 =1 599 DB 10000001b ; Address = IN 1
02F5 03 =1 600 DB 00000011b ; Interrupt
02F6 4000 =1 601 DB 64, 0 ; Maximum packet size (this example only uses 1)
02F8 64 =1 602 DB 100 ; Poll every 0.1 seconds
0022 =1 603 ConfigLength EQU $ - ConfigurationDescriptor
=1 604
02F9 =1 605 ReportDescriptor: ; Generated with HID Tool, copied to here
02F9 0600FF =1 606 DB 6, 0, 0FFH ; Usage_Page (Vendor Defined)
02FC 0901 =1 607 DB 9, 1 ; Usage (I/O Device)
02FE A101 =1 608 DB 0A1H, 1 ; Collection (Application)
0300 1901 =1 609 DB 19H, 1 ; Usage_Minimum
0302 2902 =1 610 DB 29H, 2 ; Usage_Maximum
0304 1500 =1 611 DB 15H, 0 ; Logical_Minimum (0)
0306 26FF00 =1 612 DB 26H, 255, 0 ; Logical_Maximum (255)
0309 7508 =1 613 DB 75H, 8 ; Report_Size (8)
030B 9501 =1 614 DB 95H, 1 ; Report_Count (1) = Read Address
030D 8102 =1 615 DB 81H, 2 ; Input (Data,Var,Abs)
030F 1901 =1 616 DB 19H, 1 ; Usage_Minimum
0311 2902 =1 617 DB 29H, 2 ; Usage_Maximum
0313 9502 =1 618 DB 95H, 2 ; Report_Count (2) = Write Address + Data
0315 9102 =1 619 DB 91H, 2 ; Output (Data,Var,Abs)
0317 C0 =1 620 DB 0C0H ; End_Collection
001F =1 621 ReportLength EQU $-ReportDescriptor
=1 622
0318 =1 623 String0: ; Declare the UNICODE strings
0318 04030904 =1 624 DB 4, 3, 9, 4 ; Only English language strings supported
031C =1 625 String1: ; Manufacturer
031C 2C03 =1 626 DB (String2-String1),3 ; Length, Type
031E 55005300 =1 627 DB "U",0,"S",0,"B",0," ",0,"D",0,"e",0,"s",0,"i",0,"g",0,"n",0," ", 0
0322 42002000
0326 44006500
032A 73006900
032E 67006E00
0332 2000
0334 42007900 =1 628 DB "B",0,"y",0," ",0,"E",0,"x",0,"a",0,"m",0,"p",0,"l",0,"e",0
0338 20004500
033C 78006100
0340 6D007000
0344 6C006500
0348 =1 629 String2: ; Product Name
0348 1603 =1 630 DB (EndOfDescriptors-String2),3
034A 49003200 =1 631 DB "I",0,"2",0,"C",0," ",0
034E 43002000
0352 42007200 =1 632 DB "B",0,"r",0,"i",0,"d",0,"g",0,"e",0
0356 69006400
035A 67006500
035E =1 633 EndOfDescriptors:
035E 0000 =1 634 DW 0 ; Backstop for String Descriptors
A51 MACRO ASSEMBLER I2C 22/07/99 12:36:44 PAGE 11
=1 635
=1 636
=1 637
638 $INCLUDE(Main.A51)
=1 639 ; This module initializes the microcontroller then executes MAIN forever
=1 640 ;
=1 641
0360 =1 642 Reset:
0360 7581EB =1 643 MOV SP, #235 ; Initialize the Stack at top of internal memory
0363 75927F =1 644 MOV PageReg, #7FH ; Needed to use MOVX @Ri
=1 645
0366 78D6 =1 646 MOV R0, #LOW(USBControl) ; Simulate a disconnect
0368 E2 =1 647 MOVX A, @R0
0369 54F3 =1 648 ANL A, #11110011b ; Clear DISCON, DISCOE
036B F2 =1 649 MOVX @R0, A
036C 120391 =1 650 CALL Wait100msec ; Give the host time to react
036F E2 =1 651 MOVX A, @R0 ; Reconnect with this new identity
0370 4406 =1 652 ORL A, #00000110b ; Set DISCOE to enable pullup resistor
0372 F2 =1 653 MOVX @R0, A ; Set RENUM so that 8051 handles USB requests
0373 E4 =1 654 CLR A
0374 F520 =1 655 MOV FLAGS, A ; Start in Default state
0376 =1 656 InitializeIOSystem: ; This example uses only I2C signals
=1 657 ; No initialization is required
0376 =1 658 InitializeInterruptSystem: ; First initialize the USB level
0376 78AC =1 659 MOV R0, #LOW(IN07IEN)
0378 F2 =1 660 MOVX @R0, A ; Disable interrupts from IN Endpoints 0-7
0379 08 =1 661 INC R0
037A F2 =1 662 MOVX @R0, A ; Disable interrupts from OUT Endpoints 0-7
037B 08 =1 663 INC R0
037C 7403 =1 664 MOV A, #00000011b
037E F2 =1 665 MOVX @R0, A ; Enable (Resume, Suspend,) SOF and SUDAV INTs
037F 08 =1 666 INC R0
0380 7401 =1 667 MOV A, #00000001b
0382 F2 =1 668 MOVX @R0, A ; Enable Auto Vectoring for USB interrupts
0383 78AA =1 669 MOV R0, #LOW(OUT07IRQ)
0385 74FF =1 670 MOV A, #0FFH
0387 F2 =1 671 MOVX @R0, A ; Clear out any pending interrupts
=1 672 ; Now enable the main level
0388 75E801 =1 673 MOV EIE, #00000001b ; Enable INT2 = USB Interrupt (only)
038B 75A8C0 =1 674 MOV EI, #11000000b ; Enable interrupt subsystem (and Ser1 for Dscope)
=1 675
=1 676 ; Initialization Complete.
=1 677 ;
038E =1 678 MAIN:
038E 00 =1 679 NOP ; Not much of a main loop for this example
038F 80FD =1 680 JMP MAIN ; All actions are initiated by interrupts
=1 681 ; We are a slave, we wait to be told what to do
=1 682
0391 =1 683 Wait100msec:
0391 754064 =1 684 MOV Temp, #100
0394 =1 685 Wait1msec: ; A delay loop
0394 90FB50 =1 686 MOV DPTR, #-1200
0397 A3 =1 687 More: INC DPTR ; 3 cycles
0398 E582 =1 688 MOV A, DPL ; + 2
039A 4583 =1 689 ORL A, DPH ; + 2
039C 70F9 =1 690 JNZ More ; + 3 = 10 cycles x 1200 = 1msec
039E D540F3 =1 691 DJNZ Temp, Wait1msec
03A1 22 =1 692 RET
=1 693
03A2 =1 694 Wait4Stop: ; Make sure the STOP from a previous
03A2 E2 =1 695 MOVX A, @R0 ; I2C transaction has completed
03A3 20E6FC =1 696 JB ACC.6, Wait4Stop
03A6 22 =1 697 RET
03A7 =1 698 SendI2Caddress: ; Send the first byte to I2C bus
03A7 71A2 =1 699 CALL Wait4Stop
03A9 7480 =1 700 MOV A, #10000000b ; Set the START bit
A51 MACRO ASSEMBLER I2C 22/07/99 12:36:44 PAGE 12
03AB F2 =1 701 MOVX @R0, A ; I2C engine now primed
03AC =1 702 SendI2Cdatabyte:
03AC E0 =1 703 MOVX A, @DPTR ; Get data and . . .
03AD F3 =1 704 MOVX @R1, A ; . . . send using I2C engine
03AE =1 705 Wait4Done:
03AE E2 =1 706 MOVX A, @R0
03AF 30E0FC =1 707 JNB ACC.0, Wait4Done ; Wait for the data to be transmitted
03B2 22 =1 708 RET
=1 709
03B3 =1 710 ProcessOutputReport: ; A Report has just been received
=1 711 ; The report is two bytes long
=1 712 ; Byte 1, Bits[7:1] = an I2C Address, Bit[0] = direction (0 = Write)
=1 713 ; Byte 2 = DataByte if byte 1 specifies a write
03B3 78A5 =1 714 MOV R0, #LOW(I2CControl) ; Initialize the pointers to be used
03B5 79A6 =1 715 MOV R1, #LOW(I2CData)
03B7 907EC0 =1 716 MOV DPTR, #EP0OutBuffer ; Point to the Report
03BA 71A7 =1 717 CALL SendI2Caddress
03BC E0 =1 718 MOVX A, @DPTR ; Retrieve Report Byte 1
03BD 20E007 =1 719 JB ACC.0, I2C_Read
03C0 =1 720 I2C_Write:
03C0 A3 =1 721 INC DPTR ; Point to data byte to write
03C1 71AC =1 722 CALL SendI2Cdatabyte
03C3 7440 =1 723 MOV A, #01000000b ; Set the STOP bit
03C5 F2 =1 724 MOVX @R0, A
03C6 22 =1 725 RET
03C7 =1 726 I2C_Read:
03C7 7420 =1 727 MOV A, #00100000b ; Set the LASTRD bit
03C9 F2 =1 728 MOVX @R0, A
03CA E3 =1 729 MOVX A, @R1 ; Dummy read of I2C_Data
03CB 71AE =1 730 CALL Wait4Done
03CD 7440 =1 731 MOV A, #01000000b ; Set the STOP bit
03CF F2 =1 732 MOVX @R0, A ; Immediately follow with . . .
03D0 E3 =1 733 MOVX A, @R1 ; . . . read the I2C bus data
=1 734 ; Fall into CreateInputReport
03D1 =1 735 CreateInputReport:
=1 736 ; The report is only one byte long in this example
=1 737 ; It contains the byte read from the I2C bus
03D1 907E80 =1 738 MOV DPTR, #EP1InBuffer ; Point to the buffer
03D4 F0 =1 739 MOVX @DPTR, A ; Update the Report
03D5 907FB7 =1 740 MOV DPTR, #IN1ByteCount
03D8 7401 =1 741 MOV A, #1
03DA F0 =1 742 MOVX @DPTR, A ; Endpoint 1 now 'armed', next IN will get data
03DB 22 =1 743 RET
=1 744
745 $INCLUDE(Timer.A51)
=1 746 ; This module services the real time interrupt
=1 747 ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -