Sunteți pe pagina 1din 13

A51 MACRO ASSEMBLER

STEPPER

01/30/2001 17:15:28 PAGE

MACRO ASSEMBLER A51 V6.10 OBJECT MODULE PLACED IN .\STEPPER.OBJ ASSEMBLER INVOKED BY: C:\Keil\C51\BIN\A51.EXE .\STEPPER.A51 REGISTERBANK(0) SET(SMALL) DEBUG EP LOC OBJ LINE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 SOURCE NAME StepperMotorController

0088 0089 008C 00A8 00E8 0091 00D8 0092 0086

7FE8 7FD4 7FB4 7F00 7EC0 7E80 7FB5 7FC5 7FB7 7FAC 7FA9 7FAD 7FAA 7FAE 7FAB 7FD6 7FA6 7FA5 7F93 7F94 7F95 7F96 7F97 7F98 7F99 7F9A 7F9B 7F9C 7F9D 7F9E

---0020 0000 0001 0002

+1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

;$include (Declare.A51) ; This module declares the variables and constants used in the examples ; It is common to all of the examples ; ; Declare Special Function Registers used TimerControl DATA 088H TimerMode DATA 089H Timer0High DATA 08CH EI DATA 0A8H EIE DATA 0E8H ; EZ-USB specific EXIF DATA 091H ; EZ-USB specific EICON DATA 0D8H ; EZ-USB specific PageReg DATA 092H ; EZ-USB specific, used with MOVX @Ri DPS DATA 086H ; EZ-USB specific, used with dual data pointers ; ; "External" memory locations used, EZ-USB specific ; Note that most of these variables are in Page 7FH SETUPDAT EQU 07FE8H SUDPTR EQU 07FD4H EP0Control EQU 07FB4H EP0InBuffer EQU 07F00H EP0OutBuffer EQU 07EC0H ; Not in Page 7FH EP1InBuffer EQU 07E80H ; Not in Page 7FH IN0ByteCount EQU 07FB5H Out0ByteCount EQU 07FC5H IN1ByteCount EQU 07FB7H IN07IEN EQU 07FACH IN07IRQ EQU 07FA9H OUT07IEN EQU 07FADH OUT07IRQ EQU 07FAAH USBIEN EQU 07FAEH USBIRQ EQU 07FABH USBControl EQU 07FD6H I2CData EQU 07FA6H I2CControl EQU 07FA5H PortA_Config EQU 07F93H PortB_Config EQU 07F94H PortC_Config EQU 07F95H PortA_OUT EQU 07F96H PortB_OUT EQU 07F97H PortC_OUT EQU 07F98H PortA_PINS EQU 07F99H PortB_PINS EQU 07F9AH PortC_PINS EQU 07F9BH PortA_OE EQU 07F9CH PortB_OE EQU 07F9DH PortC_OE EQU 07F9EH ; ; Byte Variables FLAGS: ; Bit Variables Configured STALL SendData DSEG DS EQU EQU EQU AT 20H 1 ; This register is bit-addressable

FLAGS.0 ; Is this device configured FLAGS.1 ; Need to STALL endpoint 0 FLAGS.2 ; Need to send data to PC Host

A51 MACRO ASSEMBLER 2 0003 0021 0040 0041 0042 0043 0046 0046 0047 0047 0048 0049 004A 0047 tim 0047 bus 0047 0047 004D 0053 0004 cycles 0047 0047 0048 High(count) 0047 0047 0047 0047 0048 0049 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

01/30/2001 17:15:28 PAGE IsDescriptor EQU FLAGS.3 ; Enable a shortcut reply ; MonitorSpace: DS 1FH ; Used by Dscope Temp: DS 1 ; A temporary working register Idle_Time: DS 1 ; The time the PC host wants us to wait Expired_Time: DS 1 ; A downcounter for timed Reports ReplyBuffer: DS 3 ; First byte is Count CurrentConfiguration: DS 1 ; Some examples support > 1 configurations ; ; Declare the specific variables used by each of the examples Overlay EQU $ Old_Buttons: DS 1 ; Used by BAL: stores current button position LEDstrobe: DS 1 ; Used by BAL: strobe one LED on at a time LEDvalue: DS 1 ; Used by BAL: stores current LED value Msec_Counter: DS 1 ; Used by BAL: counts up to 4 msec ORG Overlay e) I2CDataByte: DS 1 ; Overlay the variables (only one set in use at any one ; Used by I2C: keep a local copy of data read from I2C

LightValues: WorkingValues: Mask: LastCycle

ORG Overlay DS 6 DS 6 DS 1 EQU FLAGS.4

; ; ; ;

Used Used Used Used

by by by by

LP: LP: LP: LP:

local buffer for light brightness counted down each half cycle TurnON mask for Triacs Tracks Positive & Negative Mains half

ORG Overlay CurrentPosition:DS 1 MotorControl: DS 3 ORG Overlay DS 12

; Used by Stepper: motor has 16 stable positions ; Used by Stepper: direction, Low(count) and

LimitValues:

; Used by Temps: local buffer for limits

ORG Overlay ButtonsValue: DS 1 DisplayPosition:DS 1 LEDBuffer: DS 42 ;

; Used by RB: buttons are read each full scan ; Used by RB: holds current display position ; Used by RB: local buffer for reader board

---0000 020353

;$include (Vectors.A51) ; This module is common to all of the examples. ; It contains all of the interrupt vector declarations and ; the first level interrupt servicing (register save, call subroutine, ; clear interrupt source, restore registers, return) ; Suspend and Resume are handled totally in this module ; ; A Reset sends us to Program space location 0 CSEG AT 0 ; Code space USING 0 ; Reset forces Register Bank 0 LJMP Reset ; ; The interrupt vector table is also located here ; EZ-USB has two levels of USB interrupts: ; 1-the main level is described in this table (at ORG 43H) ; 2-there are 21 sources of USB interrupts and these are described in USB_ISR ; This means that two levels of acknowledgement and clearing will be required ; LJMP INT0_ISR ; Features not used are commented out ; ORG 0BH ; LJMP Timer0_ISR ; ORG 13H ; LJMP INT1_ISR ; ORG 1BH ; LJMP Timer1_ISR ; ORG 23H

A51 MACRO ASSEMBLER 3 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; LJMP ORG LJMP ORG LJMP ORG LJMP ORG LJMP ORG LJMP ORG LJMP ORG LJMP ORG LJMP ORG UART0_ISR 2BH Timer2_ISR 33H WakeUp_ISR 3BH UART1_ISR 43H USB_ISR 4BH I2C_ISR 53H INT4_ISR 5BH INT5_ISR 63H INT6_ISR 0E0H

01/30/2001 17:15:28 PAGE

0043 0043 020100

; Auto Vector will replace byte 45H

00E0 0100 0100 0103 0104 0107 0108 010B 010C 010F 0110 0113 0114 0117

; Keep out of the way of dScope monitor ; If you are not using dScope then this memory hole ; may be used for useful routines.

02013C 00 020157 00 020118 00 020129 00 020120 00 020118 00

ORG 100H USB_ISR:LJMP SUDAV_ISR DB 0 ; Pad entries to 4 bytes LJMP SOF_ISR DB 0 LJMP SUTOK_ISR DB 0 LJMP Suspend_ISR DB 0 LJMP USBReset_ISR DB 0 LJMP Reserved DB 0 ; LJMP EP0In_ISR ; Endpoint Interrupts are not used in these examples ; DB 0 ; Comment out features not used ; LJMP EP0Out_ISR ; DB 0 ; LJMP EP1In_ISR ; DB 0 ; LJMP EP1Out_ISR ; DB 0 ; LJMP EP2In_ISR ; DB 0 ; LJMP EP2Out_ISR ; DB 0 ; LJMP EP3In_ISR ; DB 0 ; LJMP EP3Out_ISR ; DB 0 ; LJMP EP4In_ISR ; DB 0 ; LJMP EP4Out_ISR ; DB 0 ; LJMP EP5In_ISR ; DB 0 ; LJMP EP5Out_ISR ; DB 0 ; LJMP EP6In_ISR ; DB 0 ; LJMP EP6Out_ISR ; DB 0 ; LJMP EP7In_ISR ; DB 0 ; LJMP EP7Out_ISR ; End of Interrupt Vector tables

A51 MACRO ASSEMBLER 4 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

01/30/2001 17:15:28 PAGE

0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 0118 32 0119 0119 011B 011D 011F E591 C2E4 F591 22

; When a feature is used insert the required interrupt processing here ; The example use only used Endpoints 0 and 1 and also SOF for timing Reserved: INT0_ISR: Timer0_ISR: INT1_ISR: Timer1_ISR: UART0_ISR: Timer2_ISR: UART1_ISR: I2C_ISR: INT4_ISR: INT5_ISR: INT6_ISR: SUTOK_ISR: EP0In_ISR: EP0Out_ISR: EP1In_ISR: EP1Out_ISR: EP2In_ISR: EP2Out_ISR: EP3In_ISR: EP3Out_ISR: EP4In_ISR: EP4Out_ISR: EP5In_ISR: EP5Out_ISR: EP6In_ISR: EP6Out_ISR: EP7In_ISR : EP7Out_ISR: Not_Used: ; Should not get any of these RETI ClearINT2: MOV CLR MOV RET USBReset_ISR: PUSH CLR CALL POP RETI Suspend_ISR: PUSH MOV ORL MOV NOP NOP NOP CALL POP RETI WakeUp_ISR: CLR RETI EICON.4 ; Tell the hardware that we're done A, EXIF ACC.4 EXIF, A ; Clear the Interrupt 2 bit

0120 0120 C0E0 0122 C200 0124 3119 0126 D0E0 0128 32 0129 0129 012B 012D 012F 0131 0132 0133 0134 0136 0138 0139 0139 C2DC 013B 32 C0E0 E587 4401 F587 00 00 00 3119 D0E0 32

; Bus has been Reset, move to DEFAULT state ACC Configured ClearINT2 ; No need to clear source of interrupt ACC ; SIE detected an Idle bus ACC A, PCON A, #1 PCON, A

; Go to sleep! ; Wake up here due to a USBResume

ClearINT2 ACC ; Not using external WAKEUP in these examples ; So this must be due to a USBResume ; Clear the wakeup interrupt source

A51 MACRO ASSEMBLER 5 013C 013C 013E 0140 0142 0144 0146 0148 014A 014D 014E 0150 0152 0154 0156 0157 0157 0159 015B 015D 015F 0161 C0D0 C0E0 C082 C083 3167 3119 7401 907FAB F0 D083 D082 D0E0 D0D0 32 C0D0 C0E0 C082 C083 71AA 3119 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 1] SUDAV_ISR: PUSH PUSH PUSH PUSH CALL CALL MOV ExitISR:MOV MOVX POP POP POP POP RETI SOF_ISR: PUSH PUSH PUSH PUSH CALL CALL MOV JMP

01/30/2001 17:15:28 PAGE ; A Setup packet has been received PSW ; Save Registers before the service routine ACC DPL DPH ServiceSetupPacket ClearINT2 ; Clear the source of the interrupt A, #00000001b DPTR, #USBIRQ @DPTR, A DPH ; Restore Registers DPL ACC PSW

0163 7402 0165 80E3

; A Start-Of-Frame packet has been received PSW ; Save Registers before the service routine ACC DPL DPH ServiceTimerRoutine ClearINT2 ; Clear the source of the interrupt A, #00000010b ExitISR

---0167 0167 907FE8 016A E0 016B A2E7 to P 016D 9202 016F 545C BadRequest 0171 7050 0173 E0 0174 A2E0 0176 82E1 0178 4049 017A 30E502 [1, 017D 017F 0181 0182 0184 0185 0186 0188 018A 7403 5403 C4 F540 A3 E0 540F 4540 31D2

;$include (USB_INT.A51) ; This module is common to all of the examples. ; It services USB Requests from the SIE. ; Interpretation of the Output Reports is handled by MAIN ; CSEG ServiceSetupPacket: MOV DPTR, #SETUPDAT ; Point to Setup Packet data MOVX A, @DPTR ; Get the RequestType MOV C, ACC.7 ; Bit 7 = 1 means IO device needs to send data C Host MOV ANL JNZ MOVX MOV ANL JC JNB SendData, C A, #01011100b BadRequest A, @DPTR C, ACC.0 C, ACC.1 BadRequest ACC.5, NotB5 ; IF RequestType[6.4.3.2] = 1 THEN goto ; IF RequestType[1&0] = 1 THEN goto BadRequest

; IF RequestType[5] = 1 THEN RequestType[1,0] =

018C 200134 018F 300218 0192 200320 0195 907F02

+1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319

NotB5:

MOV ANL SWAP MOV INC MOVX ANL ORL CALL JB JNB JB MOV

A, #00000011b A, #00000011b A Temp, A DPTR A, @DPTR A, #00001111b A, Temp CorrectSubroutine

; Set CommandIndex[5,4] = RequestType[1,0] ; Save HI nibble of CommandIndex ; Set CommandIndex[3,0] = Request[3,0] ; Point to Request ; Only 13 are defined today, handle in table ; goto CommandTable(CommandIndex) ; Returns STALL=1 if a stall is required

STALL, BadRequest SendData, HandShake IsDescriptor, LoadSUDPTR; EZ-USB has a short cut for descriptors ; Send data in ReplyBuffer DPTR, #EP0InBuffer+2

A51 MACRO ASSEMBLER 6 0198 019A 019D 019E 019F 01A1 01A2 01A5 01A6 01A6 01A9 01A9 01AA 01AA 01AD 01AD 01B0 01B1 01B3 01B4 01B5 01B5 01B8 01BA 01BD 01BE 01C0 01C1 01C3 01C3 01C6 01C8 01C8 01C9 01C9 01CB 01CD 01CF 01D1 7846 754003 E6 F0 1582 18 D540F8 E6 907FB5 F0 754002 907FB4 E0 4540 F0 22 858240 E583 907FD4 F0 E540 A3 80E6 754003 80E5 E0 2582 F582 5002 0583 22 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 MOV R0, #ReplyBuffer+3 MOV Temp, #3 CopyRB: MOV A, @R0 MOVX @DPTR, A DEC DPL DEC R0 DJNZ Temp, CopyRB MOV A, @R0 SendEP0InBuffer: MOV DPTR, #In0ByteCount StartXfer: MOVX @DPTR, A HandShake: MOV Temp, #00000010b SetEP0Control: MOV DPTR, #EP0Control MOVX A, @DPTR ORL A, Temp MOVX @DPTR, A RET LoadSUDPTR: MOV Temp, DPL MOV A, DPH MOV DPTR, #SUDPTR MOVX @DPTR, A MOV A, Temp INC DPTR JMP StartXfer BadRequest: MOV Temp, #00000011b JMP SetEP0Control NextDPTR: MOVX BumpDPTR: ADD MOV JNC INC Skip: RET A, @DPTR

01/30/2001 17:15:28 PAGE

; Copy maximum byte count

; Get real byte count

; This write initiates the transfer ; Handshake with host ; Set HSNAK to tell the SIE that we're done

; Send the data pointed to by DPTR

; Invalid Request was received ; Set EP0STALL and HSNAK ; Returns (DPTR + byte DPTR is pointing to) ; Returns (DPTR + ACC)

A, DPL DPL, A Skip DPH

; Need 16 bit arithmetic here

01D2 to 01D2 9001F7 01D5 31C9 01D7 E0 01D8 9001F7 01DB 31C9 01DD C082 01DF C083 needed 01E1 7845 01E3 E4 01E4 F6 01E5 18 01E6 F6 01E7 18 01E8 7601 01EA 907FEA 01ED E0 01EE F5F0 01F0 A3 01F1 E0 01F2 C201 01F4 C203 01F6 22 are

CorrectSubroutine: MOV CALL MOVX MOV CALL PUSH PUSH MOV CLR MOV DEC MOV DEC MOV MOV MOVX MOV INC MOVX CLR CLR RET DPTR, #CommandTable BumpDPTR A, @DPTR DPTR, #CommandTable BumpDPTR DPL DPH R0, #ReplyBuffer+2 A @R0, A R0 @R0, A R0 @R0, #1 DPTR, #SETUPDAT+2 A, @DPTR B, A DPTR A, @DPTR STALL IsDescriptor

; Jump to the subroutine that DPTR is pointing ; Point to entry ; Get the offset ; Get the routine address ; Create a RETURN address on stack ; Note: JMP @A+DPTR not used since A, DPTR

; Clear ReplyBuffer

; ; ; ;

Default non-descriptor reply Point to LOW(wValue) Many of the routines need these LOW(wValue) in B

; HIGH(wValue) in A

; Go to service routine

; Since the table only contains byte offsets, it is important that all these routines

A51 MACRO ASSEMBLER 7 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451

01/30/2001 17:15:28 PAGE ; within one page (100H) of CommandTable ; CommandTable: ; First 16 commands are for the Device DB Device_Get_Status - CommandTable DB Device_Clear_Feature - CommandTable DB Invalid - CommandTable DB Device_Set_Feature - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable ; SIE implements Device_Set_Address DB Get_Descriptor - CommandTable DB Set_Descriptor - CommandTable DB Get_Configuration - CommandTable DB Set_Configuration - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable ; Next 16 commands are for the Interface DB Interface_Get_Status - CommandTable DB Interface_Clear_Feature - CommandTable DB Invalid - CommandTable DB Interface_Set_Feature - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Get_Class_Descriptor - CommandTable DB Set_Class_Descriptor - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Get_Interface - CommandTable DB Set_Interface - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable ; Next 16 commands are for the Endpoint DB Endpoint_Get_Status - CommandTable DB Endpoint_Clear_Feature - CommandTable DB Invalid - CommandTable DB Endpoint_Set_Feature - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Endpoint_Sync_Frame - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable ; Next 16 commands are Class Requests DB Invalid - CommandTable DB Get_Report - CommandTable DB Get_Idle - CommandTable DB Get_Protocol - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Invalid - CommandTable DB Set_Report - CommandTable DB Set_Idle - CommandTable

01F7 01F7 01F8 01F9 01FA 01FB 01FC 01FD 01FE 01FF 0200 0201 0202 0203 0204 0205 0206 0207 0208 0209 020A 020B 020C 020D 020E 020F 0210 0211 0212 0213 0214 0215 0216 0217 0218 0219 021A 021B 021C 021D 021E 021F 0220 0221 0222 0223 0224 0225 0226 0227 0228 0229 022A 022B 022C 022D 022E 022F 0230 0231 6C 40 40 40 40 40 80 40 69 73 40 40 40 40 40 40 70 40 40 40 40 40 A4 40 40 40 40 40 40 40 40 40 70 42 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 55 62 40 40 40 40 40 40 43 5C

A51 MACRO ASSEMBLER 8 0232 0233 0234 0235 0236 0237 0237 0237 0237 0237 0237 0237 0237 0237 0237 0237 0237 0237 0237 D201 0239 0239 22 023A 023A 3000FA 023D 907FC5 0240 F0 0241 907FAA 0244 E0 0245 5401 0247 60FB 0249 F0 024A 619C 024C 024C 3000E8 024F 08 0250 7618 0252 22 0253 talk 0253 3000E1 0256 F541 0258 22 0259 do 0259 3000DB 025C 08 025D A641 025F 22 0260 0260 300004 0263 0263 0263 08 0264 7601 Powered(=1) 0266 22 0267 0267 0267 0267 7602 0269 22 026A 026A E5F0 40 40 40 40 40 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 DB DB DB DB DB Set_Protocol - CommandTable Invalid - CommandTable Invalid - CommandTable Invalid - CommandTable Invalid - CommandTable

01/30/2001 17:15:28 PAGE

; ; Many requests are INVALID for this example Get_Protocol: ; We are not a Boot device Set_Protocol: ; We are not a Boot device Set_Descriptor: ; Our Descriptors are static Set_Class_Descriptor: ; Our Descriptors are static Set_Interface: ; We only have one Interface Get_Interface: ; We do not have an Alternate setting Device_Set_Feature: ; We have no features that can be set Interface_Set_Feature: ; We have no features that can be set Endpoint_Set_Feature: ; We have no features that can be set Device_Clear_Feature: ; We have no features that can be set Interface_Clear_Feature: ; We have no features that can be set Endpoint_Sync_Frame: ; We are not an Isonchronous device Invalid: SETB STALL ; Endpoint_Clear_Feature: ; Reply: RET Set_Report: ; The ONLY case JNB MOV MOVX MOV Wait4D: MOVX ANL JZ MOVX JMP Get_Report: JNB INC MOV RET Set_Idle: JNB MOV RET Get_Idle:

or or or or or

cleared cleared cleared cleared cleared

; Invalid Request made, STALL the Endpoint ; We have no features that can be set or cleared

; Host wants to sent us a Report. in this example where host sends data to us Configured, Invalid ; Need to be Configured to do this command DPTR, #Out0ByteCount ; Enable EP0OutBuffer to receive data @DPTR, A ; Any value will do DPTR, #OUT07IRQ ; Wait for valid data in EP0OutBuffer A, @DPTR A, #00000001b Wait4D @DPTR, A ; Clear the interrupt ProcessOutputReport ; RETurn via this subroutine ; Host wants a Report Configured, Invalid ; Need to be Configured to do this command R0 ; Point to ReplyBuffer(1) @R0, #18H ; Reply with a recognizable (arbitary) value ; Host wants to tell us how often we should Configured, Invalid Idle_Time, A ; Need to be Configured to do this command ; Handshake with host ; Host must have forgotten what he told us to

JNB Configured, Invalid ; Need to be Configured to do this command INC R0 ; Point to ReplyBuffer(1) MOV @R0, Idle_Time RET Get_Configuration: ; Need to return 0 or 1 JNB Configured, Configuration0 Configuration1: ; Same bit pattern as Device_Get_Status Device_Get_Status: ; Only two bits of Device Status are defined INC R0 ; Point to ReplyBuffer(1) MOV @R0, #1 ; Bit 1=Remote Wakeup(=0), Bit 0=Self RET Configuration0: Interface_Get_Status: Endpoint_Get_Status: MOV @R0, #2 RET Set_Configuration: MOV A, B ; Same bit pattern as Interface_Get_Status ; Interface Status is currently defined as 0

; Valid values are 0 and 1 ; Get LOW(wValue)

A51 MACRO ASSEMBLER 9 026C 026E 026F 0271 0273 0274 0274 0276 0277 0277 0279 027A 027D 027F 0280 0283 0285 0286 6006 14 70C6 D200 22 C200 22 D203 14 9002C1 60BA 14 9002D3 60B4 14 70AF +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543

01/30/2001 17:15:28 PAGE JZ Deconfigured DEC A JNZ Invalid SETB Configured RET Deconfigured: CLR Configured RET Get_Descriptor: ; Host wants to know who/what we are SETB IsDescriptor DEC A ; Valid Values are 1, 2 and 3 MOV DPTR, #DeviceDescriptor JZ Reply DEC A MOV DPTR, #ConfigurationDescriptor JZ Reply DEC A JNZ Invalid ; Request is for a String Descriptor MOV DPTR, #String0 ; Point to String 0 MOV A, B ; Get String Index NextString: JZ FixUpthenReply MOV Temp, A ; Save String Index CALL NextDPTR MOVX A, @DPTR ; Get the String Length (= 0 means we're at p)

0288 900305 028B E5F0 028D 028D 601E 028F F540 0291 31C8 0293 E0 Backsto 0294 60A1 0296 E540 0298 14 0299 80F2 029B Request 029B D203 029D C3 029E 9421 02A0 9002E5 02A3 6094 02A5 14 02A6 9002EE 02A9 608E Descriptors 02AB 808A 00B6 02AD 02AD 02AE 02AF 02B1 02B3 02B4 02B5 02B6 02B7 02B9 02BB 02BD 02BF E0 FF F5F0 7800 F2 08 A3 E0 DFFA D0E0 D0E0 E5F0 21A6

+1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582

JZ Invalid MOV A, Temp DEC A JMP NextString Get_Class_Descriptor: SETB CLR SUBB MOV JZ DEC MOV JZ DEC JZ JMP

; Asked for a string I don't have ; Check if we are there yet ; Valid values are 21H, 22H, 23H for Class

; ;

IsDescriptor C A, #21H DPTR, #HIDDescriptor Reply A DPTR, #ReportDescriptor Reply A ; This example does not use Physical Send_Physical_Descriptor Invalid

; ; Error check: this MUST be on within a page of CommandTable WithinSamePage EQU $ - CommandTable ; FixUpthenReply: ; EZ-USB Rev D has a String Descriptor bug ; Need to fill the IN0BUF (@ 7F00H) myself MOVX A, @DPTR ; Get the string length MOV R7, A ; Save counter MOV B, A MOV R0, #LOW(EP0InBuffer) ; PageReg = 7FH = HIGH(EP0InBuffer) CopySD: MOVX @R0, A INC R0 INC DPTR MOVX A, @DPTR DJNZ R7, CopySD ; Fixup complete, get back to the program flow POP ACC ; Get rid of the return address POP ACC MOV A, B ; Retrieve byte count JMP SendEP0InBuffer ;$include (DTables.A51) ; This module declares the descriptors

A51 MACRO ASSEMBLER 10 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640

01/30/2001 17:15:28 PAGE ; ; This example has one Device Descriptor with: ; One Configuration - single IN port and single OUT port ; One Interface - there is only one method of accessing the ports ; One HID Descriptor - to make PC host software simpler ; No Endpoint Descriptors - HID Output Reports use EP0 ; One Report Descriptor - three bytes OUT ; Multiple Sting Descriptors - to aid the user ; CSEG DeviceDescriptor: DB 18, 1 ; Length, Type DW 101H ; USB Rev 1.1 DB 0, 0, 0 ; Class, Subclass and Protocol DB 64 ; EP0 size DW 4242H, 1, 1 ; Vendor ID, Product ID and Version DB 1, 2, 0 ; Manufacturer, Product & Serial# Names DB 1 ; #Configs ConfigurationDescriptor: DB 9, 2 ; Length, Type DB LOW(ConfigLength), HIGH(ConfigLength) DB 1, 1, 0 ; #Interfaces, Configuration#, Config. Name DB 10000000b ; Attributes = Bus Powered DB 50 ; Max. Power is 50x2 = 100mA InterfaceDescriptor: DB 9, 4 ; Length, Type DB 0, 0, 0 ; No alternate setting, HID OUTPUT uses EP0 DB 3 ; Class = Human Interface Device DB 0, 0 ; Subclass and Protocol DB 0 ; Interface Name HIDDescriptor: DB 9, 21H ; Length, Type DB 0, 1 ; HID Class Specification compliance DB 0 ; Country localization (=none) DB 1 ; Number of descriptors to follow DB 22H ; And it's a Report descriptor DB LOW(ReportLength), HIGH(ReportLength) ConfigLength EQU $ - ConfigurationDescriptor ReportDescriptor: ; Generated with HID Tool, copied to here DB 6, 0, 0FFH ; Usage_Page (Vendor Defined) DB 9, 1 ; Usage (I/O Device) DB 0A1H, 1 ; Collection (Application) DB 19H, 1 ; Usage_Minimum DB 29H, 2 ; Usage_Maximum DB 15H, 0 ; Logical_Minimum (0) DB 26H, 255, 0 ; Logical_Maximum (255) DB 75H, 8 ; Report_Size (8) DB 95H, 3 ; Report_Count (3) = Motor Control DB 91H, 2 ; Output (Data,Var,Abs) DB 0C0H ; End_Collection ReportLength EQU $-ReportDescriptor String0: DB String1: DB DB ; Declare the UNICODE strings ; Only English language strings supported ; Manufacturer (String2-String1),3 ; Length, Type "U",0,"S",0,"B",0," ",0,"D",0,"e",0,"s",0,"i",0,"g",0,"n",0," ", 0 4, 3, 9, 4

---02C1 02C1 1201 02C3 0101 02C5 000000 02C8 40 02C9 4242 02CB 0001 02CD 0001 02CF 010200 02D2 01 02D3 02D3 0902 02D5 1B00 02D7 010100 02DA 80 02DB 32 02DC 02DC 0904 02DE 000000 02E1 03 02E2 0000 02E4 00 02E5 02E5 0921 02E7 0001 02E9 00 02EA 01 02EB 22 02EC 1700 001B 02EE 02EE 0600FF 02F1 0901 02F3 A101 02F5 1901 02F7 2902 02F9 1500 02FB 26FF00 02FE 7508 0300 9503 0302 9102 0304 C0 0017 0305 0305 0309 0309 030B 030F 0313 0317 031B 031F 0321 04030904 2C03 55005300 42002000 44006500 73006900 67006E00 2000 42007900

+1

641

DB

"B",0,"y",0," ",0,"E",0,"x",0,"a",0,"m",0,"p",0,"l",0,"e",0

A51 MACRO ASSEMBLER 11 0325 0329 032D 0331 0335 0335 0337 033B 033F 0343 0347 034B 034F 0351 0351 20004500 78006100 6D007000 6C006500 1C03 53007400 65007000 70006500 72002000 4D006F00 74006F00 7200 0000 +1 +1 +1

STEPPER

01/30/2001 17:15:28 PAGE

642 643 644

String2: DB DB

; Product Name (EndOfDescriptors-String2),3 "S",0,"t",0,"e",0,"p",0,"p",0,"e",0,"r",0," ",0

+1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698

DB

"M",0,"o",0,"t",0,"o",0,"r",0

EndOfDescriptors: DW 0

; Backstop for String Descriptors

;$include (Main.A51) ; This module initializes the microcontroller then executes MAIN forever ; Reset: MOV MOV SP, #235 PageReg, #7FH ; Initialize the Stack at top of internal ; Needed to use MOVX @Ri ; Simulate a disconnect ; Clear DISCON, DISCOE ; ; ; ; Give the host time to react Reconnect with this new identity Set DISCOE to enable pullup resistor Set RENUM so that 8051 handles USB requests

0353 0353 7581EB memory 0356 75927F 0359 035B 035C 035E 035F 0361 0362 0364 0365 0366 0368 0368 036A 036B 036C 036E 036F 0370 0370 0372 0373 0374 0375 0376 0378 0379 037A 037C 037D 037F 0381 78D6 E2 54F3 F2 718B E2 4406 F2 E4 F520 7893 E4 F2 799C F4 F3 78AC F2 08 F2 08 7403 F2 08 7401 F2 78AA 74FF F2

MOV R0, #LOW(USBControl) MOVX A, @R0 ANL A, #11110011b MOVX @R0, A CALL Wait100msec MOVX A, @R0 ORL A, #00000110b MOVX @R0, A CLR A MOV FLAGS, A InitializeIOSystem: MOV R0, #LOW(PortA_Config) CLR A MOVX @R0, A MOV R1, #LOW(PortA_OE) CPL A MOVX @R1, A InitializeInterruptSystem: MOV R0, #LOW(IN07IEN) MOVX @R0, A INC R0 MOVX @R0, A INC R0 MOV A, #00000011b MOVX @R0, A INC R0 MOV A, #00000001b MOVX @R0, A MOV R0, #LOW(OUT07IRQ) MOV A, #0FFH MOVX @R0, A MOV MOV EIE, #00000001b EI, #11000000b

; Start in Default state ; This example uses only Port A output ; PageReg = 7F = HIGH(PortA_Config) ; No alternate functions ; = 0FFH ; Enable PortA for Output ; First initialize the USB level ; Disable interrupts from IN Endpoints 0-7 ; Disable interrupts from OUT Endpoints 0-7

; Enable (Resume, Suspend,) SOF and SUDAV INTs ; Enable Auto Vectoring for USB interrupts ; ; ; ; Clear out any pending interrupts Now enable the main level Enable INT2 = USB Interrupt (only) Enable interrupt subsystem (and Ser1 for

0382 75E801 0385 75A8C0 Dscope)

0388 0388 00

; Initialization Complete. ; MAIN: NOP

; Not much of a main loop for this example

A51 MACRO ASSEMBLER 12 0389 80FD +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764

01/30/2001 17:15:28 PAGE JMP MAIN ; All actions are initiated by interrupts ; We are a slave, we wait to be told what to do Wait100msec: MOV Wait1msec: MOV More: INC MOV ORL JNZ DJNZ RET

038B 038B 038E 038E 0391 0392 0394 0396 0398 039B 039C

754064 90FB50 A3 E582 4583 70F9 D540F3 22

Temp, #100 ; A delay loop DPTR, #-1200 DPTR A, DPL A, DPH More Temp, Wait1msec ; ; ; ; 3 + + + cycles 2 2 3 = 10 cycles x 1200 = 1msec

039C 039E 03A1 03A3 03A4 03A5 03A6 03A7 03A9 03AA

7848 907EC0 7F03 E0 F6 A3 08 DFFA 22

ProcessOutputReport: ; A Report has just been received ; The report is three bytes long ; Save the values for the INTERRUPT service routine MOV R0, #MotorControl ; Initialize the pointers to be used MOV DPTR, #EP0OutBuffer ; Point to the Report MOV R7, #3 CopyOR: MOVX A, @DPTR ; Retrieve Report Byte 1 MOV @R0, A INC DPTR INC R0 DJNZ R7, CopyOR RET CreateInputReport: ; Not used in this example

03AA 03AA D54A24 03AD 754A0A 03B0 03B2 03B4 03B5 03B6 03B8 03B8 03B9 03BA 03BB 03BD 03BE 03C0 03C2 03C4 03C4 03C6 03C8 03CA 7849 794A E6 47 6019 16 E6 F4 6001 17 E548 7002 74FF 2547 540F F547 9003D2

;$include (Timer.A51) ; This module services the real time interrupt ; ; Get a Real Time interrupt every One millisecond (using SOF interrupt) ; ; Pulse the stepper motor every 10msec (100Hz) if required ; EZ-USB PortA drives an Allegro 8219 ; Phase A is connected to bits 5,4 & 3, Phase B to bits 2,1 & 0 ; Bits 5 and 2 are PHASE ; Bits 4:3 and 1:0 are I1:I0 current inputs ; ServiceTimerRoutine: DJNZ Msec_counter, Done ; Only need to step every 10msec MOV Msec_counter, #10 ; Reinitialize MOV MOV MOV ORL JZ StepTheMotor: DEC MOV CPL JZ DEC STM1: MOV JNZ MOV Clockwise: ADD ANL MOV MOV R0, #MotorControl+1 R1, #MotorControl+2 A, @R0 A, @R1 Done @R0 A, @R0 A STM1 @R1 A, MotorControl Clockwise A, #-1 A, CurrentPosition A, #0FH CurrentPosition, A DPTR, #StepperTable ; Point to LS byte of count ; Point to MS byte of count

; No stepping required ; Unfortunately, no flags are set ; Test for LS = FF ; Underflow on LS, therefore adjust MS byte ; Get the direction indicator ; CounterClockwise = backup one

; Table is only 16 entries long

A51 MACRO ASSEMBLER 13 03CD 03CE 03D0 03D1 03D2 03D2 03D3 03D4 03D5 03D6 03D7 03D8 03D9 03DA 03DB 03DC 03DD 03DE 03DF 03E0 03E1 93 7899 F2 22 07 02 09 10 18 30 29 22 23 26 2D 34 3C 14 0D 06 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1

STEPPER 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 MOVC MOV MOVX RET A, @A + DPTR R0, #Low(PortA_Pins) @R0, A ; Index into table

01/30/2001 17:15:28 PAGE

; Select the new step position

Done:

StepperTable: DB 000111b DB 000010b DB 001001b DB 010000b DB 011000b DB 110000b DB 101001b DB 100010b DB 100011b DB 100110b DB 101101b DB 110100b DB 111100b DB 010100b DB 001101b DB 000110b

; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

= Up

= Right

= Down

= Left

END

S-ar putea să vă placă și