giustraman
Joined: 11 Jun 2007 Posts: 25
|
problem with receiver circuit |
Posted: Wed Oct 28, 2009 4:23 am |
|
|
I'm trying to measure temperature thanks a transmitter-receiver circuit. I have a problem with the receiver: External interrupt setting on rising edge do not function: for example I have introduced a spike to check its execution (output high / low on pin) but I do not view anything on a oscillator. Somebody could help me?? Best regards..
Code: | #include <16F648A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=4000000)
#include "C:\Documents and Settings\Administrator\Desktop\ricevitore\16f648.h"
#include <lcd_16x2.c>
int1 id[16]={1,0,1,0,1,0,1,0,1,1,0,0,1,1,0,0}, vett[48], stato_bit, stato_id, parita;
int i, j, k, h, count, count_k, delay_bits, count_edge, temp, temp_old, temp_int, temp_dec, an2, an2_old, an2_int, an2_dec;
#int_EXT
void EXT_isr(void)
{
output_high(PIN_A4);
output_low(PIN_A4);
if(count_edge!=0)
delay_bits=get_timer0();
set_timer0(0);
delay_us(500);
stato_bit=input_state(pin_B0);
if(((delay_bits<48)||(delay_bits>80))&&(count_edge!=0))
{
count_edge=0;
j=0;
}
if(stato_bit)
vett[j]=1;
else
vett[j]=0;
count_edge++;
if(j==47)
j=0;
else
j++;
}
#int_TIMER0
void TIMER0_isr(void)
{
count_edge=0;
j=0;
}
void controllo_id()
{
for(k=0;k<16;k++)
{
if((vett[k]==id[k]))
count_k++;
}
if(count_k==16)
stato_id=true;
else
stato_id=false;
}
void controllo_parita()
{
parita=false;
count=0;
for(i=0;i<16;i++)
{
if(vett[i]==1)
count++;
}
for(i=17;i<48;i++)
{
if(vett[i]==1)
count++;
}
if(((count%2==1)&&(vett[16]==1))||((count%2==0)&&(vett[16]==0)))
parita=true;
vett[16]=0;
}
void visualizza_temp()
{
for(h=0;h<16;h++)
{
temp+=vett[h+16]*2^(16-h);
}
if(temp!=temp_old)
{
temp_int=temp/10;
temp_dec=temp%10;
printf(lcd_putc,"\fTemperatura in C\n%d.%d 'C",temp_int,temp_dec);
}
else
{
temp_int=temp_old/10;
temp_dec=temp_old%10;
printf(lcd_putc,"\fTemperatura in C\n%d.%d 'C (*)",temp_int,temp_dec);
}
temp_old=temp;
}
void visualizza_an2()
{
for(h=0;h<16;h++)
{
an2+=vett[h+32]*2^(32-h);
}
if(an2!=an2_old)
{
an2_int=an2/10;
an2_dec=an2%10;
//printf(lcd_putc,"\fIngresso an2\n%d.%d",an2_int,an2_dec);
}
else
{
an2_int=an2_old/10;
an2_dec=an2_old%10;
//printf(lcd_putc,"\fIngresso an2\n%d.%d (*)",an2_int,an2_dec);
}
an2_old=an2;
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16); // va in overflow ogni 4ms
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER0);
ext_int_edge(L_TO_H);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
setup_oscillator(OSC_4MHZ);
lcd_init();
while(TRUE)
{
output_high(PIN_A2);
output_low(PIN_A2);
if(count_edge==48)
{
disable_interrupts(INT_EXT);
output_high(PIN_A3);
output_low(PIN_A3);
controllo_id();
if(stato_id)
{
controllo_parita();
}
}
//comandi lcd
if((stato_id==true)&&(parita==true))
{
visualizza_temp();
visualizza_an2();
}
//abilitazione interrupt ext dopo aver visualizzato i dati sull'LCD
enable_interrupts(INT_EXT);
}
} |
|
|