您当前的位置:五五电子网电子知识单片机-工控设备PIC单片机pic16f874步进电机程序 正文
pic16f874步进电机程序

pic16f874步进电机程序

点击数:7516 次   录入时间:03-04 11:47:25   整理:http://www.55dianzi.com   PIC单片机
    MOVfw    result1L
    call    sendByte
    MOVfw    winkelH
    call    sendByte
    MOVfw    winkelL
    call    sendByte
    MOVfw    wtemp3                ; restore W
    retfie

; --==*[ COMMAND INIT - setup for receive motor data (part 1/2) ]*==--
command3:                    ; command3
    MOVlw    COMMAND_3
    MOVwf    cmdNum                ; cmdNum contains now the current command value
    MOVlw    .2
    MOVwf    byteCnt                ; we want exactly 2 bytes from the pc
    MOVfw    wtemp3                ; restore W
    retfie

; --==*[ COMMAND EXEC - receive motor data (part 2/2) ]*==--
getData_command3:
    decf    byteCnt, 1            ; handle byte counter
    bz    c3_b2                ; if byte counter is 0 then it is the 2nd byte
    MOVfw    RCREG                ; else, 1st byte receive
    MOVwf    motorL                ; store in motorL
    b    outhere                ; and exit
c3_b2:
    MOVfw    RCREG                ; 2nd byte receive
    MOVwf    motorH                ; store in motorH
    MOVlw    0xFF                ; reset cmdNum to undefined value (0xFF)
    MOVwf    cmdNum
                        ; reconfigure PWM
    MOVfw    motorH
    MOVwf    CCPR1L                ; store high byte (8; bits 9 - 2)
    bcf    CCP1CON, CCP1Y
    btfsc    motorL, 0            ; store low byte (2; bits 0)
    bsf    CCP1CON, CCP1Y
    bcf    CCP1CON, CCP1X
    btfsc    motorL, 1            ; store low byte (2; bits 1)
    bsf    CCP1CON, CCP1X
    btfss    motorL, 2            ; motorL<2> bit is significant for motor direction
    b    turn_left
    bsf    PORTB, 1            ; turn motor right
    b    outhere
turn_left:
    bcf    PORTB, 1            ; turn motor left
outhere:
    MOVfw    wtemp3                ; restore W
    retfie


; --==*[ COMMAND EXEC - transmit motor data ]*==--
command4:
    MOVfw    result1H            ; transmit high byte
    call    sendByte
    MOVfw    result1L            ; transmit low byte
    call    sendByte
    MOVfw    wtemp3                ; restore W
    retfie


; --==*[ ERROR HANDLING - for the serial communication ]*==--
err_Overflow:                    ; handle overflow error
    MOVwf    wtemp4                ; save W
    bsf    PORTB, 7            ; show error on leds (10)
    bcf    PORTB, 6
    bcf    RCSTA, CREN            ; dISAble continuous reception
    MOVf    RCREG, W            ; flush receive fifo buffer (3 bytes deep)
    MOVf    RCREG, W
    MOVf    RCREG, W
    bsf    RCSTA, CREN            ; reenable continuous reception

上一页  [1] [2] [3] [4] [5] [6]  下一页


本文关键字:步进电机  程序  PIC单片机单片机-工控设备 - PIC单片机