Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

18F4550 ADC veri okumak

Başlatan ismail.cal, 26 Aralık 2015, 18:06:33

ismail.cal

merhaba 18f4450 serisi pic ile iki kanaldan veri okuyup serial monitöre yazdırmak istiyorum.Aşağıdaki kodlarda kanal 1 de 0.05V kanal2 de 0.35 V gibi bir değer alıyorum. Aynı kodları 16f877A da kullandığımda kanal1 de 0.15V kanal2 de 1,34V alıyorum. Picin Adc ayarlarını yapamadım galiba kodlara bakıp bana yardımcı olabilirmisiniz iyi çalışmalar

#include <18F4550.h>
//#use delay (clock=20000000)
//#FUSES HS,MCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL1,CPUDIV1,VREGEN,NOPBADEN
//#include "flex_lcd.c"
#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES XTPLL                    //Crystal/Resonator with PLL enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
//#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //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 NOPBADEN                 //PORTB pins are configured as digital I/O 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 PLL1                     //No PLL PreScaler
#FUSES CPUDIV1                  //System Clock by 1
#use delay(crystal=4000000,  clock=48000000)


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

#priority  int_timer1, int_ad, int_rda

unsigned long int bilgi1,bilgi2;
float voltaj,voltaj1;
int i,j;

void timer1_kesme()
{
   set_timer1(50536);
   i++;
   if(i==99)
      {
      j++;
      output_toggle(pin_c0);
      fprintf(seri," \%d san\n", j);
      i=0;
      }
 }
#INT_AD
void adc_kesmesi()
{
      fprintf(seri,"\f\%5.2f op\r", voltaj1);
      fprintf(seri,"\%5.2f sen\r", voltaj);
}

 #int_rda
 void seri()
 {
   rx_int=FALSE;
  // output_toggle(pin_c1);
 }

void main()
{
   SET_TIMER0(RTCC_OFF);
   setup_timer_2(T2_DISABLED,0,1);
   SET_TIMER3(T3_DISABLED); 
   setup_CCP1(CCP_OFF);
   setup_CCP2(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
  setup_vref(FALSE);
   set_tris_c(0x00);
   output_c(0x00);
   set_tris_d(0x00);
   output_d(0x00);
   // set_tris_a(0b00000011);
    setup_adc(adc_clock_div_32);
    setup_adc_ports(ALL_ANALOG);
     //setup_adc_ports(AN1);
    enable_interrupts(INT_AD);
    
   //fprintf(iletisim0,'M');//istediginiz pinden m karakterini gonderir
   
    setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
    set_timer1(50536);
    enable_interrupts(INT_timer1);
    
   ///global aktif
    enable_interrupts(GLOBAL);
    
    //lcd
    //lcd_init(); // lcd kullanılmadan önce bu komut
            // işletilmeli yoksa lcd çalışmaz
    
   
     sis_ust_sayici=0;
     sis_alt_sayici=0;
     dideger=0.00;
     sisdeger=0.00;
     //printf(lcd_putc,"\fSis=\ndia=");
     
while(TRUE)
{
    set_adc_channel(0); // RE0/AN5 ucundaki sinyal A/D işlemine tabi tutulacak
    delay_us(20); // Kanal seçiminde sonra bu bekleme süresi verilmelidir
    bilgi1=read_adc(); 
    voltaj=0.0048828125*bilgi1;
    yeniadc=voltaj;
    
    set_adc_channel(1); // RE0/AN5 ucundaki sinyal A/D işlemine tabi tutulacak
    delay_us(20); // Kanal seçiminde sonra bu bekleme süresi verilmelidir
    bilgi2=read_adc(); 
    voltaj1=0.0048828125*bilgi2;

}
}