Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda com Interrupção Externa (TIMER 0) - PIC C Compiler


doracenzi

Pergunta

Olá pessoal, estou com um problema em um projeto que esta a quase uma semana me atrasando, é o seguinte, eu preciso usar uma interrepção externa para que de tempo em tempo o PIC18F4550 envie a temperaturas lidas, esse bloco da leitura das temperaturas tem que ser em uma interrepção externa para não atrapalhar no restante da função principal MAIN, o problema é que eu implementei o TIMER 0 como o fabricante do compilador diz, com toda a sintaxe correta(eu acho) e mesmo assim a interrpução não ocorre, não enviando os dados. Eu não consigo mesmo achar o que esta de errado na implementação, por favor se alguém souber onde esta o erro me ajude, me de uma luz. Obrigado desde já. Deixo aqui em baixo o código implementado em C no PIC C compiler.

#include <18F4550.h>

#device adc=10

#int_RTCC

#FUSES NOWDT //No Watch Dog Timer

#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale

#FUSES INTRC_IO //Internal RC Osc, no CLKOUT

#FUSES NOPROTECT //Code not protected from reading

#FUSES NOBROWNOUT //No brownout reset

#FUSES BORV20 //Brownout reset at 2.0V

#FUSES NOPUT //No Power Up Timer

#FUSES NOCPD //No EE protection

#FUSES STVREN //Stack full/underflow will cause reset

#FUSES NODEBUG //No Debug mode for ICD

#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#FUSES NOWRT //Program memory not write protected

#FUSES NOWRTD //Data EEPROM not write protected

#FUSES IESO //Internal External Switch Over mode enabled

#FUSES FCMEN //Fail-safe clock monitor enabled

#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET

#FUSES NOWRTC //configuration not registers write protected

#FUSES NOWRTB //Boot block not write protected

#FUSES NOEBTR //Memory not protected from table reads

#FUSES NOEBTRB //Boot block not protected from table reads

#FUSES NOCPB //No Boot Block code protection

#FUSES MCLR //Master Clear pin enabled

#FUSES LPT1OSC //Timer1 configured for low-power operation

#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#FUSES PLL12 //Divide By 12(48MHz oscillator input)

#FUSES CPUDIV4 //System Clock by 4

#FUSES USBDIV //USB clock source comes from PLL divide by 2

#FUSES VREGEN //USB voltage regulator enabled

#FUSES ICPRT //ICPRT enabled

#use delay(crystal=8000000)

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#DEFINE AN pin_D3

#DEFINE BN pin_D4

#DEFINE AP pin_D5

#DEFINE BP pin_D6

#DEFINE delay1 500

int b = 0;

char aux[4];

int i = 0;

float valor = 0;

float diferenca = 0;

int flag = 0;

int aux1 = 0;

int aux2 = 0;

int16 valor_anal1 = 0, valor_temp1 = 0, valor_anal2 = 0, valor_temp2 = 0, valor_anal3 = 0, valor_temp3 = 0, valor_anal4 = 0, valor_temp4 = 0;

void RTCC_isr(void)

{

//Sensores de temperatura

set_adc_channel(0); // Canal do ADC 0

delay_ms(1);

valor_anal1 = read_adc(); // Lê o LM35 1

valor_temp1 = (valor_anal1 * 0.00488) * 100; // Converte em graus celsius

set_adc_channel(1); // Canal do ADC 1

delay_ms(1);

valor_anal2 = read_adc(); // Lê o LM35 2

valor_temp2 = (valor_anal2 * 0.00488) * 100; // Converte em graus celsius

set_adc_channel(2); // Canal do ADC 2

delay_ms(1);

valor_anal3 = read_adc(); // Lê o LM35 3

valor_temp3 = (valor_anal3 * 0.00488) * 100; // Converte em graus celsius

set_adc_channel(3); // Canal do ADC 3

delay_ms(1);

valor_anal4 = read_adc(); // Lê o LM35 4

valor_temp4 = (valor_anal4 * 0.00488) * 100; // Converte em graus celsius

//Envia para a porta serial a Temperatura lida do LM35

printf("A%2.1fB%2.1fC%2.1fD%2.1f\n", (float)valor_temp1, (float)valor_temp2, (float)valor_temp3, (float)valor_temp4);

}

void main()

{

setup_adc_ports(AN0_TO_AN3);

setup_adc(ADC_CLOCK_DIV_2);

setup_psp(PSP_DISABLED);

setup_spi(0);;

setup_wdt(WDT_OFF);

setup_timer_1(T1_DISABLED);

setup_timer_2(T2_DISABLED,0,1);

setup_ccp1(CCP_OFF);

setup_comparator(NC_NC_NC_NC);

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);

enable_interrupts(INT_RTCC);

enable_interrupts(GLOBAL);

setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);

set_tris_a(0b11111111);

while(true)

{

/*Captura do pacote enviado pela interface*/

if (kbhit())

{

aux[0] = 0;

aux[1] = 0;

aux[2] = 0;

aux[3] = 0;

aux[4] = 0;

aux[0] = getc(); //inicio do quadro

aux[1] = getc();

aux[2] = getc();

aux[3] = getc();

aux[4] = getc();

putc(aux[0]);

putc(aux[1]);

putc(aux[2]);

putc(aux[3]);

putc(aux[4]);

}

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...