我没有任何编程经验,我迫切需要做这项工作,我父亲最近去世了,他是我们家族公司的代码,请帮助!
我需要在控制步进电机的“PROX_ETIQ”例程之前为该程序添加延迟,这是一个旧程序,它被多次更改并且其中有许多禁用功能。在移动步进电机之前我需要等待1秒钟。
;*************************************************
; PROGRAMA PARA ETIQUETADORA LASER
;
; CLIENTE : OPERACIONAL
; MODELO :
; PLACA(S): PCI-1
#DEFINE VERSAO "JLE V1.0"
; DATA : 01/04/09
;*************************************************
; LIST P=PIC16C84
LIST P=PIC16F84
; LIST P=PIC16F84A
; INCLUDE "P16C84.INC"
INCLUDE "P16F84.INC"
; INCLUDE "P16F84A.INC"
__CONFIG (_CP_ON & _PWRTE_ON & _WDT_OFF & _HS_OSC)
IPORTA EQU B'00011101'
PPORTA EQU B'00011100'
IPORTB EQU B'00001111'
PPORTB EQU B'00001111'
POPTION EQU B'00000100'
PINTCON EQU B'10110000'
;*************************************************
; DEFINICAO DE CONTANTES
;*************************************************
CLOCK EQU .16000000 ;original .16000000
PRESCALER EQU .32
FCLOCK EQU CLOCK/4/PRESCALER
FINT EQU .1000 ;1ms = 1/1000
CR EQU 0DH
LF EQU 0AH
MSB EQU 7
LSB EQU 0
VTMR0 EQU -(FCLOCK/FINT)
ACK EQU 6
;*************************************************
; DEFINICAO DOS BITS EXTERNOS
;*************************************************
;PORT A
TX EQU 0 ;TRANSMISSÃO SERIAL
RTS EQU 1 ;CONTROLE RTS
CTS EQU 2 ;CONTROLE CTS
S_ETIQ EQU 3 ;SENSOR DE ETIQUETA PRESENTE
JUMPER EQU 4 ;JUMPER PARA SELEÇÃO
;PORT B
RX EQU 0 ;RECEPÇÃO SERIAL
PULS2 EQU 4 ;GERA PULSO PARA O MOTOR 2
;*************************************************
; DEFINIÇÕES AUXILIARES
;*************************************************
#DEFINE _Z STATUS,Z
#DEFINE _C STATUS,C
#DEFINE BANCO0 BCF STATUS,RP0
#DEFINE BANCO1 BSF STATUS,RP0
#DEFINE PULSO2_1 BSF PORTB,PULS2
#DEFINE PULSO2_0 BCF PORTB,PULS2
#DEFINE TX_1 BSF PORTA,TX
#DEFINE TX_0 BCF PORTA,TX
#DEFINE RTS_1 BSF PORTA,RTS
#DEFINE RTS_0 BCF PORTA,RTS
;*************************************************
; DEFINICAO DOS TEMPOS
;*************************************************
TMP1 EQU -.2 ;TEMPO DO SINAL EM 1 NA BUSCA DO ZERO
TMP2 EQU -.2 ;TEMPO DO SINAL EM 0 NA BUSCA DO ZERO
TMP3 EQU -.200 ;TEMPO PARA RECONHECER O JUMPER
TMP4 EQU -.255 ;DELAY P/ GERAR PULSO
TMP5 EQU -.255
;*************************************************
; DEFINICAO DAS FLAGS
;*************************************************
;*** FLAGS
TZERO EQU 0 ;INDICA QUE "CONT" CHEGOU A ZERO
RXMEN EQU 1 ;INDICA MENSAGEM RECEBIDA
TZERO2 EQU 7 ;INDICA QUE DEVE BLOQUEAR
;*************************************************
; AREA DE DADOS NA EEPROM
;*************************************************
CBLOCK 0
E2INICIO
ENDC
;*************************************************
; AREA DE DADOS
;*************************************************
CBLOCK 0CH
;*** POSIÇÕES PARA SALVAR NA INTERRUPÇÃO
W_TEMP
STATUS_TEMP
;*** CONTADORES
CONT
CONT_CARAC
CONT_PULSO
CONT_PULSO1
CONT_RS
CONT_RTX
CONT_DELAY:2
CONT_ESTAB
;*** POSIÇÕES AUXILIARES DO MOVIMENTO
POS_ATUAL
PROX_CARAC
DESL_NCARAC
;*** FLAGS INDICATIVAS DE ESTADOS
FLAGS
;*** POSICOES PARA A COMUNICACAO SERIAL
TXBUF
TXRXDATA
RXPONT
RXBUFF:.10
ENDC
;*************************************************
; PROGRAMA PRINCIPAL
;*************************************************
ORG 0
RESET
MOVLW IPORTA ;VALORES INICIAIS DO PORTA
MOVWF PORTA
MOVLW IPORTB ;VALORES INICIAIS DO PORTB
GOTO CRESET
;*** INTERRUPÇÃO
RELOGIO
MOVWF W_TEMP ;SALVA POSICAO ATUAL DOS REGISTROS
SWAPF STATUS,W
BANCO0
MOVWF STATUS_TEMP
RELOGIO0
BTFSC INTCON,INTF
GOTO RECEBE
MOVLW VTMR0
MOVWF TMR0
BTFSC FLAGS,TZERO
GOTO RELOGIO_FIM
INCFSZ CONT,F
GOTO RELOGIO_FIM
BSF FLAGS,TZERO
RELOGIO_FIM
BCF INTCON,T0IF
RELOGIO_FIM1
SWAPF STATUS_TEMP,W
MOVWF STATUS
SWAPF W_TEMP,F
SWAPF W_TEMP,W
RETFIE ;RETORNA DA INTERRUPCAO
;**************************************
;*** ROTINAS DE COMUNICAÇÃO SERIAL ***
;**************************************
DELAY0
CALL DELAY1
CALL DELAY1
CALL DELAY1
DELAY2
CALL DELAY1
RETURN
DELAY1
MOVLW -.135
MOVWF CONT_DELAY
DELAY
INCFSZ CONT_DELAY,F
GOTO DELAY
RETLW .0
RECEBE
CALL DELAY2
MOVLW .8 ;RECEBE 8 BITS
MOVWF CONT_RS
RX_PROX
CALL DELAY0
RRF TXRXDATA,F ;RODA O BUFFER DE RECEPCAO
BTFSS PORTB,RX
BCF TXRXDATA,MSB
BTFSC PORTB,RX
BSF TXRXDATA,MSB
RX_PROX1
DECFSZ CONT_RS,F ;FICA NO LOOP ATE TERMINAR
GOTO RX_PROX
MOVLW '*'
XORWF TXRXDATA,W
BTFSC _Z
GOTO RX_PROX2
RX_FIM
BCF INTCON,INTF
GOTO RELOGIO_FIM1
RX_PROX2
BSF PORTA,RTS
BSF FLAGS,RXMEN
GOTO RX_FIM
;*** TRANSMITE VIA RS-232
TRANSMITE
BCF PORTA,TX ;GERA O START DE TRANSMISSAO
MOVLW .8 ;TRANSMITE 8 BITS
MOVWF CONT_RTX
TX_PROX
CALL DELAY0
BTFSS TXBUF,LSB ;TRANSFERE TXRXBUF.0 -> TX
GOTO TX_PROX1
BSF PORTA,TX
GOTO TX_PROX2
TX_PROX1
BCF PORTA,TX
TX_PROX2
RRF TXBUF,F ;RODA O BUFFER DE TRANSMISSAO
DECFSZ CONT_RTX,F ;FICA NO LOOP 8 VEZES
GOTO TX_PROX
CALL DELAY0
BSF PORTA,TX ;GERA 1 STOP
CALL DELAY0
RETLW .0
;********************************
;*** CONTINUA A INICIALIZAÇÃO ***
;********************************
CRESET
MOVWF PORTB
BANCO1
MOVLW PPORTA ;INICIALIZA BITS DO PORTA
MOVWF TRISA
MOVLW PPORTB ;INICIALIZA BITS DO PORTB
MOVWF TRISB
MOVLW POPTION ;PROGRAMA REGISTRO OPTION
MOVWF OPTION_REG
BANCO0
MOVLW VTMR0 ;INICIALIZA TEMPORIZADOR
MOVWF TMR0
CLRF FLAGS
MOVLW PINTCON
MOVWF INTCON
MOVLW .10
MOVWF CONT_ESTAB
ESTAB2
MOVLW TMP3
MOVWF CONT
BCF FLAGS,TZERO
ESTAB
BTFSS FLAGS,TZERO
GOTO ESTAB
DECFSZ CONT_ESTAB,F
GOTO ESTAB2
BANCO0
;*********************************************
;*** LOOP PRINCIPAL DE FUNCOES DO PROGRAMA ***
;*********************************************
PRINC
BTFSS FLAGS,RXMEN ;ESPERA MENSAGEM RECEBIDA
GOTO PRINC
BCF FLAGS,RXMEN
CALL PROX_ETIQ
GOTO PRINC
PROX_ETIQ
MOVLW .200
CALL DESLOCA_POS
MOVLW .200
CALL DESLOCA_POS
MOVLW .128
CALL DESLOCA_POS
MOVLW .200
CALL DESLOCA_POS
MOVLW .200
CALL DESLOCA_POS
MOVLW .128
CALL DESLOCA_POS
MOVLW ACK
MOVWF TXBUF
CALL TRANSMITE
RETURN
DESLOCA_POS
MOVWF CONT_PULSO1
DESL_POS_0
PULSO2_1 ;PULSO EM 1
MOVLW TMP4 ;TEMPO EM 1
MOVWF CONT
DESL_POS_1
INCFSZ CONT,F
GOTO DESL_POS_1 ;ESPERA CONTADOR
MOVLW TMP4 ;TEMPO EM 1
MOVWF CONT
DESL_POS_1A
INCFSZ CONT,F
GOTO DESL_POS_1A ;ESPERA CONTADOR
PULSO2_0 ;PULSO EM 0
MOVLW TMP5 ;TEMPO EM 0
MOVWF CONT ;DISPARA CONTADOR
DESL_POS_2
INCFSZ CONT,F
GOTO DESL_POS_2
MOVLW TMP5 ;TEMPO EM 0
MOVWF CONT ;DISPARA CONTADOR
DESL_POS_2A
INCFSZ CONT,F
GOTO DESL_POS_2A
DECFSZ CONT_PULSO1,F
GOTO DESL_POS_0
RETURN
END
答案 0 :(得分:1)
我的哀悼。
自从我编写PIC以来已经有很长一段时间了,但这个资源似乎很相关:
http://www.nomad.ee/PIC/picprog.shtml
在“TIMING”下,有一个似乎与您的问题类似的延迟例程。
或者,AFAIK在PIC16F84A中有一个'看门狗定时器',可用于更精确的定时任务。
无论如何,你应该考虑你正在使用的水晶的频率。