4. PRÁTICA 04: ACIONAMENTO DO MOTOR POR TEMPORIZAÇÃO
Referencial Teórico: Estudo das Interrupções; Interrupção por tempo; Timer 0.
Objetivo: Controlar o estado de funcionamento de um motor por meio das funções de atraso.
Materiais: Utilizar motor de corrente contínua ligado à saída A e fonte de alimentação.
4.1 Arquivo Principal
#include "iniciog.h"
#include "pratica.h"
void main(){
configura_portas();
habilita_ponteh();
while(1){
MTR1_CW = 1;
MTR1_CC = 0;
espere_por(250); // 100ms
MTR1_CW = 0;
MTR1_CC = 0;
espere_por(250); // 100ms
}
}
4.2 Arquivo Secundário
// acrescentar ao iniciog.h ou arquivo pratica.h
void habilita_ponteh(){
MOTOR_AB_EN = 1;
MTR1_EN = 1;
MTR2_EN = 1;
}
void configura_relogio(){
INTCON = 0b10100000;
T0CON = 0x80; // 20ms
TMR0H = 0x15; // 20ms
TMR0L = 0xA0; // 20ms
}
void zera_relogio(){
INTCONbits.TMR0IF = 0;
TMR0H = 0x15; // 20ms
TMR0L = 0xA0; // 20ms
}
#pragma code int_hr = 0x1848
#pragma interrupt trata_interrupcao
void trata_interrupcao(){
MTR1_EN = ~MTR1_EN;
led = ~led;
zera_relogio();
}