pIC16f874步进电机程序
list p=16f874
include <p16f874.inc>
; --==*[ CONSTANTS ]*==--
#define COMMAND_2 ’B’
#define COMMAND_3 ’C’
#define COMMAND_4 ’D’
; --==*[ VARIABLES ]*==--
cmdNum equ 0x20 ; command number. 0xFF for invalid command
recByte equ 0x21 ; received byte
motorL equ 0x22 ; motor data - low byte
motorH equ 0x23 ; motor data - high byte
byteCnt equ 0x24 ; internal counter for byte counting during reception
tickL equ 0x25 ; ticks: low byte
tickH equ 0x26 ; ticks: high byte
result1L equ 0x27 ; result: this one is needed for storage of ticks
result1H equ 0x28
winkelL equ 0x29 ; winkel: tick counter without overflow check etc.
winkelH equ 0x30
quad equ 0x31 ; quadrature signal, for direction storage
oldb equ 0x32 ; old value of PORTB
newb equ 0x33 ; new value of PORTB
tmr0o0 equ 0x34 ; tmr0 overflow counter 0
tmr0o1 equ 0x35 ; tmr0 overflow counter 1
wtemp1 equ 0x60 ; storage for the W register (rbif)
wtemp2 equ 0x61 ; storage for the W register (CCp2if)
wteMP3 equ 0x62 ; storage for the W register (rcif)
wtemp4 equ 0x63 ; storage for the W register (usart error routines)
org 0x00 ; --==*[ RESET VECTOR ]*==--
b main
org 0x04 ; --==*[ INT VECTOR ]*==--
b int_handler
org 0x05 ; --==*[ MAIN PROGRAM ]*==--
main:
; --==*[ VARIABLES - initialize ]*==--
MOVlw 0xFF
MOVwf cmdNum
clrf motorL
clrf motorH
clrf tickL
clrf tickH
clrf result1L
clrf result1H
clrf winkelL
clrf winkelH
clrf quad
clrf oldb
clrf newb
clrf tmr0o0
clrf tmr0o1
; --==*[ PORTS - setup port B ]*==--
clrf PORTB
bsf STATUS, RP0 ; PIN 4 and 5 as input (photo-interrupter signals)
MOVlw b’00110000’ ; pin 1 has to be an output (direction signal)
MOVwf TRISB ; all other pins are outputs, too (default)
bcf STATUS, RP0
; --==*[ PORTS - setup port C ]*==--
clrf PORTC
bsf STATUS, RP0
MOVlw b’11111011’ ; pin 2 as output (PWM signal)
上一篇:PIC做的红外线遥控接收程序