PIC16F877A ile Voltmetre ve Ampermetre yapımı

seslan

Hectopat
Katılım
25 Mart 2016
Mesajlar
70
Makaleler
1
Yer
Dünya
Daha fazla  
Cinsiyet
Erkek
Merhabalar,

Bitirme projemde, projemdeki devrenin cikis portundaki voltaji ve yukten gecen akimi PIC16F877A ile olcmem gerekiyor. PIC'i kodlamak icin CSS C Compiler kullandim ve devreyi Proteus'ta kurup simule etmeye calistim ancak dogru sonuc elde edemiyorum. Bilgisi olan arkadaslar yardim edebilirler ise cok sevinirim. Gerekli ekran goruntulerini ve kodlari assagiya birakiyorum.



Kod:
#include <16F877A.h>
#define LCD_DATA4    PIN_D4
#define LCD_DATA5    PIN_D5
#define LCD_DATA6    PIN_D6
#define LCD_DATA7    PIN_D7

#define LCD_RW_PIN      PIN_D2
#define LCD_ENABLE_PIN   PIN_D0
#define LCD_RS_PIN       PIN_D1
#device adc = 10
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, NOLVP, NOPUT, NOWRT, NODEBUG, NOCPD
#use delay(clock=16000000)

#include <lcd.c>

void main()
{
   float v;
   float v1;
   float i;
   set_tris_a(0xFF); //0xFF defines A port as input.
   set_tris_d(0x00); //0x00 defines D port as output.
   lcd_init(); //Initialization of the LCD
   delay_ms(5);
   setup_adc_ports(AN0);//Set the pin where input is connected
   setup_adc(ADC_CLOCK_DIV_64);
   set_adc_channel(0);//set the channel from which the ADC will be reading the data from
   setup_vref(FALSE);
   while(true)
   {                                     
   delay_ms(10);
   read_adc(ADC_START_ONLY);//Start reading the ADC value
   delay_ms(2);
   v1 = read_adc();                                     
   v = v1 * (40*(2/20)) * (5/1023); // 5/1023=0.004887585532746823069403714565 is the resolution of ADC
   i = v1 / 2000 * (5/1023);
   lcd_gotoxy(1,1);
   printf(lcd_putc,"Voltage:%2.1f"v);                           
   delay_ms(100);                                         
   printf(lcd_putc,"V");
   delay_ms(100);
   lcd_gotoxy(1,2);
   printf(lcd_putc, "Current:%2.1f"i);
   delay_ms(100);
   printf(lcd_putc, "A");
   delay_ms(100);
   };
}

Sorunu cozdum ve baskalarina yardimci olmasi acisindan aciklama geregi duydum.

Kodda v1 float point olarak tanimlandigi icin integer bir sayi ile carpimi sifir sonucunu veriyor. Ayni sorun i icin de gecerli. Duzeltilmis kodu assagiya birakiyorum.

Kod:
#include <16F877A.h>
#define LCD_DATA4    PIN_B3
#define LCD_DATA5    PIN_B2
#define LCD_DATA6    PIN_B1
#define LCD_DATA7    PIN_B0

#define LCD_RW_PIN      PIN_D2
#define LCD_ENABLE_PIN   PIN_B5
#define LCD_RS_PIN       PIN_B4
#device adc = 10
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, NOLVP, NOPUT, NOWRT, NODEBUG, NOCPD
#use delay(clock=16000000)

#include <lcd.c>

void main()
{
   float v;
   float v1, v2;
   float i;
   set_tris_a(0xFF); //0xFF defines A port as input.
   set_tris_b(0x00); //0x00 defines B port as output.
   lcd_init(); //Initialization of the LCD
   delay_ms(5);
   setup_adc_ports(AN0);//Set the pin where input is connected
   setup_adc(ADC_CLOCK_DIV_64); //Setting up Tad
   set_adc_channel(0);//channel from which the ADC will be reading the data
   setup_vref(FALSE);
   while(true)
   {                                     
   delay_ms(10);
   read_adc(ADC_START_ONLY);
   delay_ms(2);
   v1 = read_adc();                                     
   v = v1 * 250.0 * (5.0/1023.0);
   v2 = v1 * (5.0/1023.0);
   i = v2 / 4000.0;
   lcd_gotoxy(1,1);
   printf(lcd_putc,"V:%2.4f"v);                           
   delay_ms(100);                                         
   printf(lcd_putc,"V");
   delay_ms(100);
   lcd_gotoxy(1,2);
   printf(lcd_putc, "I:%2.9f"i);
   delay_ms(100);
   printf(lcd_putc, "A");
   delay_ms(100);
   };
}



Simulasyondaki Vin voltaji 1kV.
 
ISIS programına çok benziyor.
 
Bu siteyi kullanmak için çerezler gereklidir. Siteyi kullanmaya devam etmek için çerezleri kabul etmelisiniz. Daha Fazlasını Öğren.…