Estou com duas interrupcoes (ext1, timer 0) funcionando, para ler um controle remoto. Ele está funcionando. Só que está acontecendo uma coisa estranha
a) quando eu detecto a borda de descida na ext1, eu desabilito a mesma e passo a ler o sinal do controle remoto com o timer 0.
b) depois que eu leio os 14 pulsos, eu dou um tempinho ( TE = 20 ms) e só ae eu habilito a EX1 de novo. O problema eh que depois desse tempo, mesmo sem borda de descida .....a p* age como se estivesse tido uma interrupção. Oras, se eu ja desabilitei na primeira descida, como é que ela está habilitada de novo antes de chegar novamente o sinal do controle remoto.
Fonte 1:
http://www.ustr.net/infrared/infrared1.shtml
Veja figura 7. Estou lendo a partir de 75% do pulso 1, e depois em intervalos de 1700 ms ....para pegar o bit na parte hachurada. Isso funciona legal.
Veja o que acontece no bagulho
http://br.geocities.com/jeanfernandes_eng/rc5-001.jpg
http://br.geocities.com/jeanfernandes_eng/rc5-002.jpg
http://br.geocities.com/jeanfernandes_eng/rc5-003.jpg
O sinal de cima eh o RC5
O sinal de baixo eh um flag que eu pulso toda vez que vou ler o bit do rc5 dentro do timer....para ilustrar melhor o que está havendo.
Código
Rotina de Interrupcao
- Código: Selecionar todos
void int_externa(void) interrupt 2
{
if (libera_rc5) {
libera_rc5 = FALSE;
EX1 = 0;
ET0 = 0;
TR0 = OFF;
TL0 = (256-112); // 70 us off
TR0 = ON;
ET0 = 1;
frame_rc5 = 0;
tarefa_leitura_rc5 = 14;
conta_padrao_rc5 = 3; // + 220 us
tick_ajuste = 0; // controle do time out
frame_rc5_ok = FALSE;
ajuste_relogio = TRUE;
MCU_LSDAP = ON;
}
}
Timer
- Código: Selecionar todos
void int_timer0(void) interrupt 1
{
// interrupcao a cada 110 us (aproximado)
if (ajuste_relogio) {
if (tarefa_leitura_rc5) {
if (!--conta_padrao_rc5) {
MCU_LSDAP = ~MCU_LSDAP;
time_out_tecla = TEMPO_LIBERA_TECLA;
conta_padrao_rc5 = TEMPO_RC5;
tarefa_leitura_rc5--;
if (!RC5_IN) frame_rc5 |= 0x0001;
if (tarefa_leitura_rc5) {
frame_rc5 <<= 1;
frame_rc5 &= 0xFFFE;
}
else {
frame_rc5_ok = TRUE;
frame_rc5 &= 0x003f;
time_out_tecla = TEMPO_LIBERA_TECLA;
}
}
}
else {
if (!RC5_IN) {
time_out_tecla = TEMPO_LIBERA_TECLA;
}
else {
if (time_out_tecla) {
if (!--time_out_tecla) {
libera_rc5 = ON;
EX1 = 1;
}
}
}
}
/* if (time_out_tecla > 0) {
time_out_tecla--;
if (!time_out_tecla) {
EX1 = ON;
libera_rc5 = ON;
}
} */
if (++tick_ajuste > (word)TEMPO_AJUSTE) {
ajuste_relogio = FALSE;
habilita_edicao_relogio = FALSE;
libera_rc5 = TRUE;
EX1 = ON;
}
if (modo_sdap)
// MCU_LSDAP = ~MCU_LSDAP;
app_ponto = 1 - app_ponto;
}
Inicializacao
- Código: Selecionar todos
/*** TIMER 0 ***/
ET0 = OFF; // Desabilita a interrupcao do timer 0
TR0 = OFF; // desliga timer 0
TMOD = (TMOD & 0xf0) | 0x02; // 11110010
TH0 = TL0 = (256 - 202); // 110 us
ET0 = ON; // habilita a interrupcao do timer 0
TR0 = ON; // liga timer 0
/*** INTERRUPCAO EXTERNA 0 ***/
EX1 = ON; // habilita interrupcao externa 1
IT1 = ON; // interrupcao externa na trans. negativa do sinal
PX1 = ON; // prioridade na interrupcao externa
MCU = Atmel = AT89C51ED2, 22.1184 Mhz, bus = xtal/12
Vê se alguem descobre ae a mizera ehehehehhe