⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picservo.lst

📁 Code ASM for PIC16F628. Use for CNC/Servo Motor. With simulatio in Proteus (7.0)
💻 LST
📖 第 1 页 / 共 5 页
字号:
                      00495 
                      00496         ; Offset Part of the Pulse 
005A   0800           00497         MOVF    INDF, w                         ; (1) Load the offset count
005B   3E01           00498         ADDLW   1                                       ; (1) Incremnt the count - 255->0, 0->1 because 
                            of 
                      00499                                                                 ; calling convention of DelayWByFour
005C   204F           00500         CALL    DelayWByFour            ; (8+) Delay 
                      00501 
                      00502         ; Position Part of the Pulse
005D   0A84           00503         INCF    FSR, f                          ; (1) Access the next value which is the 
                      00504                                                                 ; position loop count
MPASM  4.02 Released                             PICSERVO.ASM   12-31-2006  11:50:00         PAGE 11


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00505 
005E   0800           00506         MOVF    INDF, w                         ; (1) Load the variable loop count
005F   3E01           00507         ADDLW   1                                       ; (1) Incremnt the count - 255->0, 0->1 because 
                            of 
                      00508                                                                 ; calling convention of DelayWByFour
0060   204F           00509         CALL    DelayWByFour            ; (8+) Delay
                      00510         
                      00511 
                      00512         ; Turn off the output bit to end the pulse
0061   0829           00513         MOVF    CurrentServoMask, w     ; (1) Get the mask
0062   0686           00514         XORWF   PORTB, f                        ; (1) Turn of the pulse
                      00515                 
                      00516         ; and return from the call.
0063   0008           00517         RETURN
                      00518 
                      00519 
                      00520 ;+-----------------------------------------------------------------------------
                      00521 ;| SUBROUTINE: DisableInterrupts
                      00522 ;| 
                      00523 ;| Disable interrupts. This is not just as simple as BCF GIE because of the way
                      00524 ;| that interrupts are triggered it is possible for an interrupt to occur 
                      00525 ;| during the execution of the BCF GIE instruction which causes the PIC to start
                      00526 ;| the interrupt handler which then returns with RETFIE which sets the GIE flag
                      00527 ;| again!
                      00528 ;+-----------------------------------------------------------------------------
0064                  00529 DisableInterrupts
0064   138B           00530         BCF             INTCON, GIE                     ; disable the interrupt
0065   1B8B           00531         BTFSC   INTCON, GIE                     ; check if GIE is still disabled
0066   2864           00532         GOTO    DisableInterrupts       ; it isn't, so try again
0067   0008           00533         RETURN
                      00534 
                      00535 
                      00536 ;+-----------------------------------------------------------------------------
                      00537 ;| Main Program, Setup and Constantly Loop
                      00538 ;+-----------------------------------------------------------------------------
0068                  00539 Main
0068   1283           00540         BCF             STATUS, RP0                             ; Set the lower RAM bank as the default.
0069   2064           00541         CALL    DisableInterrupts               ; disable interrupts until were setup
                      00542         
                      00543 
                      00544         ; Setup the PIC's ports, PortB is all outputs, PortA is the Serial interface
006A   0185           00545         CLRF    PORTA                                   ; Clear the port outputs
006B   0186           00546         CLRF    PORTB                           
                      00547 
006C   1683           00548         BSF             STATUS, RP0                             ; Set the Upper RAM bank while we init t
                            he ports
006D   300A           00549         MOVLW   0Ah                                             ; All outputs except RA3 and RA1
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
006E   0085           00550         MOVWF   TRISA                                   ; Set the port directional flags        
                      00551                                 
006F   3000           00552         MOVLW   00h                                             ; Port B All outputs
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0070   0086           00553         MOVWF   TRISB                                   ; Set the port directional flags
MPASM  4.02 Released                             PICSERVO.ASM   12-31-2006  11:50:00         PAGE 12


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00554         
0071   1283           00555         BCF             STATUS, RP0                             ; Set the lower RAM bank as the default.
                      00556 
                      00557         ; Turn off the LED
0072   1605           00558         BSF             LED_Drive
                      00559 
                      00560         ; initialise the serial port
0073   2143           00561         CALL    InitSerialPort
                      00562 
                      00563         ; Transmit the power on welcome message (interrupts already disabled)
0074   01AA           00564         CLRF    DataByte
0075                  00565 PwrOnMsgLoop
0075   082A           00566         MOVF    DataByte, w
0076   200F           00567         CALL    GetPWROnMsg
0077   39FF           00568         ANDLW   0ffh                                    ; check for end of message
0078   1903           00569         BTFSC   STATUS, Z
0079   287D           00570         GOTO    EndPwrOnMsgLoop                 ; was 0, exit
007A   214D           00571         CALL    TransmitDataByte
007B   0AAA           00572         INCF    DataByte, f
007C   2875           00573         GOTO    PwrOnMsgLoop
007D                  00574 EndPwrOnMsgLoop
                      00575 
                      00576         ; Initialise the Servo values to resonable defaults and set their
                      00577         ; mask values
007D   3001           00578         MOVLW   01h
007E   008C           00579         MOVWF   Servo0_Mask
007F   3002           00580         MOVLW   02h
0080   008F           00581         MOVWF   Servo1_Mask
0081   3004           00582         MOVLW   04h
0082   0092           00583         MOVWF   Servo2_Mask
0083   3008           00584         MOVLW   08h
0084   0095           00585         MOVWF   Servo3_Mask
0085   3010           00586         MOVLW   10h
0086   0098           00587         MOVWF   Servo4_Mask
0087   3020           00588         MOVLW   20h
0088   009B           00589         MOVWF   Servo5_Mask
0089   3040           00590         MOVLW   40h
008A   009E           00591         MOVWF   Servo6_Mask
008B   3080           00592         MOVLW   80h
008C   00A1           00593         MOVWF   Servo7_Mask
008D   01A6           00594         CLRF    Flags                           ; initialise all flags
008E   20D8           00595         CALL    ResetState                      ; initialise all outputs and state
                      00596 
                      00597         ; Setup the Real time counter so it runs on the instruction
                      00598         ; clock and triggers and interrupt every 20ms or so. This
                      00599         ; then calls the interrupt routine which serives all the servo
                      00600         ; outputs. This is then enabled or disabled by the main loop when
                      00601         ; it is bit banging the serial input.
                      00602 
                      00603         ; Assign the prescaler to the timer and to 1:128 scale. This
                      00604         ; also enables the PORTB pullups.
008F   1683           00605         BSF             STATUS, RP0                             ; Set the Upper RAM bank while we init t
                            he ports
MPASM  4.02 Released                             PICSERVO.ASM   12-31-2006  11:50:00         PAGE 13


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0090   3086           00606         MOVLW   86h                                             ; binary: 0000 0110
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0091   0081           00607         MOVWF   OPTION_REG                              ; Set the OPTION register
0092   1283           00608         BCF             STATUS, RP0                             ; Set the lower RAM bank as the default.
                      00609 
                      00610         ; Setup the RTCC for the 19ms interrupts
0093   306B           00611         MOVLW   RTCC_19msValue
0094   0081           00612         MOVWF   TMR0
0095   110B           00613         BCF             INTCON, T0IF
                      00614         
                      00615         ; Enable the Timer 0 Interrupt and disable all others
0096   018B           00616         CLRF    INTCON                          ; mask out all interrupts
0097   168B           00617         BSF             INTCON, T0IE            ; unmask the timer interrupt
                      00618 
                      00619         ; Enable interrupts
0098   178B           00620         BSF             INTCON, GIE
                      00621 
                      00622         ; Set the CTS signal active so the host can send us data
0099   1105           00623         BCF             Serial_CTS      
                      00624 
                      00625         ; Wait for the start bit (a high to low transition on Serial_RX)
                      00626         ; or for the servo pulse safe flag to be activated.
009A                  00627 StartBitLoop
009A   1D85           00628         BTFSS   Serial_RX
009B   289F           00629         GOTO    StartReceiveData
                      00630 
                      00631         ; Test for servo pulse safe flag. If set, start the servo pulses, otherwise
                      00632         ; go back and test for a start bit again.
009C   1D26           00633         BTFSS   Flag_ServoPulseSafe
009D   289A           00634         GOTO    StartBitLoop
009E   28AB           00635         GOTO    ProcessServos
                      00636 
009F                  00637 StartReceiveData
                      00638         ; possible start bit, receive a byte
009F   2064           00639         CALL    DisableInterrupts
00A0   2167           00640         CALL    ReceiveDataByte
00A1   00AA           00641         MOVWF   DataByte
00A2   178B           00642         BSF             INTCON, GIE
                      00643 
                      00644         ; check if it is valid. If it is send it straight back
00A3   1C26           00645         BTFSS   Serial_ReceiveValid
00A4   289A           00646         GOTO    StartBitLoop            ; invalid, continue looking for a start bit
                      00647         
                      00648         ; light the LED
00A5   300A           00649         MOVLW   LED_Drive_Time
00A6   00A8           00650         MOVWF   LED_Drive_Count
00A7   1205           00651         BCF             LED_Drive
                      00652 
00A8   082A           00653         MOVF    DataByte, w
00A9   20F7           00654         CALL    ParseCommand
                      00655 
00AA   289A           00656         GOTO    StartBitLoop
                      00657 
MPASM  4.02 Released                             PICSERVO.ASM   12-31-2006  11:50:00         PAGE 14


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -