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

pic16f874步进电机程序

点击数:7516 次   录入时间:03-04 11:47:25   整理:http://www.55dianzi.com   PIC单片机
quit:
    MOVfw    PORTB
    MOVwf    oldb                ; oldb = PORTB
    MOVfw    wtemp1                ; restore W
    bcf    INTCON, RBIF            ; reset interrupt (important)
    retfie


int_timer0_reset:
    btfsc    tmr0o0, 7            ; wait 128 overflows
    goto    a1
    incf    tmr0o0, 1
    goto    a0
a1:
    btfsc    tmr0o1, 6            ; wait 64 overflows
    goto    a4
    incf    tmr0o1, 1
    goto    a0
a4:
    btfsc    PORTB, 7            ; a short hack, so we can measure the impulses
    goto    next1                ; of timer0 with an oscillograph
    bsf    PORTB, 7            ; signal is on bit 7 of portb
    goto    mainl
next1:
    bcf    PORTB, 7
mainl:
    MOVwf    wtemp2                ; save W
    MOVfw    tickL                ; store ticks in result1
    MOVwf    result1L
    MOVfw    tickH
    MOVwf    result1H

    MOVfw    quad                ; and blend the direction bit on MSB of result1
    iorwf    result1H, 1

    clrf    tickH                ; clear tick counter
    clrf    tickL
    clrf    tmr0o0                ; clear timer0 overflow counters
    clrf    tmr0o1
    MOVfw    wtemp2                ; restore W
a0:
    bcf    INTCON, T0IF            ; reset interrupt (important)
    retfie


int_USART_receive:
    MOVwf    wtemp3                ; save W
    MOVlw    COMMAND_3            ; command3 active ?
    subwf    cmdNum, W
    bz    getData_command3        ; yes, handle it
    MOVfw    RCREG                ; store received byte
    clrf    RCREG                ; it’s a good idea to flush the buffer
    clrf    RCREG                ; after receiving a byte, so it’s
    clrf    RCREG                ; forced that we have a new byte in the buffer in the next step
    MOVwf    recByte
    MOVlw    COMMAND_2            ; -execute command2 ?
    subwf    recByte, W
    bz    command2            ;  yes, do it
    MOVlw    COMMAND_3            ; -execute command3 ?
    subwf    recByte, W
    bz    command3            ;  yes, do it
    MOVlw    COMMAND_4            ; -execute command4 ?
    subwf    recByte, W
    bz    command4            ;  yes, do it

commandUnknown:                    ; else, received byte is unknown
    bsf    PORTB, 0            ; show error on LEDs
    MOVfw    wtemp3                ; restore W
    retfie

; --==*[ COMMAND EXEC - transmit motor data in debug mode ]*==--
command2:
    MOVfw    result1H
    call    sendByte

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


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