16F877 - Hatayı Bulamıyorum - Derlemiyor

phil

Üye
Katılım
19 Şub 2014
Mesajlar
14
Puanları
1
Arkadaşlar merhaba.

Oldukça önemli bir projem var.

PIC 16F877 DS 18B20 lcd dijital termometre Buradaki hex kodu, isis'te pic'e atınca çalışıyor. Ama yine buradaki c kodunu kendim derlemek istediğimde, (sebebi de şu: rc0'ın farklı değerde çıkış vermesini istiyorum, onu ayarladım) derlemiyor. dev'de de, microc'de de denedim. olmadı.

internetten araştırdım. şu iki satırı, şu şekilde düzelttim:

Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CURSOR_OFF);

----

Lcd_Init();
Lcd_Cmd(_Lcd_CURSOR_OFF);

Bunu yapınca, mikroc'de önceden error verirken derleme işleminde, şimdi hata verip derliyor. Ama derleme sonucunda hex dosyası oluşmuyor? Bu neden kaynaklanıyor, deneme sürümü mü kullanıyorum da 2kb'ın üzerinde mi hex dosyası ondan oluşmuyor acaba? Yoksa hatalardan dolayı mı oluşmuyor?

jt29fl.png


Cidden çok uğraştım ve çözümü bulamadım. Sizden ricam, aşağıda yer alan c kodunun hatasını bulmanız ve derlenip hex dosyası oluşmasını sağlamanız. Çok teşekkür ederim şimdiden.

Kod:

Bold'ladığım kısımdaki kodları yukarıda belirttiğim gibi düzelttikten sonra, paylaştığım resimdeki sorun ortaya çıktı. Bu haliyle error veriyordu.

// Set TEMP_RESOLUTION to the corresponding resolution of your DS18x20 sensor:
// 18S20: 9
// 18B20: 12 (default setting; can be 9,10,11,or 12)
const unsigned short TEMP_RESOLUTION = 12;

const int RES_FACTOR_1[4] = {5000, 2500, 1250, 625};
const unsigned int RES_FACTOR_2[4] = {0x0001, 0x0003, 0x0007, 0x000F};
const unsigned int RES_FACTOR_3[4] = {0x8000, 0xC000, 0xE000, 0xF000};
float alarma;
unsigned temp,temp2,new_temp;
unsigned short j, RES_SHIFT,j2;

void Display_Temperature(unsigned int temp) {
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
unsigned int temp_whole, temp_fraction;
unsigned short i;
char text[8];

// Isolate the fraction and make it a 4-digit decimal integer (for display)
temp_fraction = temp & RES_FACTOR_2[RES_SHIFT - 1];
temp_fraction = temp_fraction * RES_FACTOR_1[RES_SHIFT - 1];
//portc = temp_fraction;
// Handle the whole part of temperature value
temp_whole = temp;

// Is temperature negative?
if ((temp_whole & 0x8000) != 0u) i = 1; // Yes, i = 1
else i = 0; // No, i = 0
// PORTC = i;
// Remove the fractional part
temp_whole >>= RES_SHIFT;

// Correct the sign if necessary
if (i) temp_whole |= RES_FACTOR_3[RES_SHIFT - 1];

//portd = temp_whole;
IntToStr(temp_whole, text); // Convert whole part to string
Lcd_Out(2, 6, text); // Print whole part on LCD
Lcd_Chr_Cp('.'); // Print dot to separate fractional part


IntToStr(temp_fraction, text); // Convert fractional part to string

// Add leading zeroes (we display 4 digits fractional part)
if (temp_fraction < 1000u) Lcd_Chr_Cp('0');
if (temp_fraction < 100u) Lcd_Chr_Cp('0');
if (temp_fraction < 10u) Lcd_Chr_Cp('0');

Lcd_Out_Cp(text); // Print fractional part on LCD

Lcd_Chr_Cp(223); // Print degree character
Lcd_Chr_Cp('C'); // Print 'C' for Centigrades
}//~

void main() {
ADCON1 = 0xFF; // Configure RA5 pin as digital I/O
PORTE = 0xFF;
TRISE = 0x0F; // PORTE is input
PORTB = 0;
TRISB = 0; // PORTB is output
TRISD=0;
PORTD=0;
TRISC=0;
PORTC=0;

// Initialize LCD on PORTB and prepare for output
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CURSOR_OFF);

Lcd_Out(1, 1, "Sicaklik: ");

do { // main loop

Ow_Reset(&PORTE,2); // Onewire reset signal
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0x44); // Issue command CONVERT_T
Delay_us(120);

Ow_Reset(&PORTE,2);
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0xBE); // Issue command READ_SCRATCHPAD
Delay_ms(400);

j = Ow_Read(&PORTE,2); // Get temperature LSB
j2=j;
temp = Ow_Read(&PORTE,2); // Get temperature MSB
temp2=temp;
temp <<= 8; temp += j; // Form the result
temp2<<=5;
j2>>=3;
new_temp=temp2^j2;
portd=new_temp;
// alarma=39;
alarma=((new_temp*127.5)/255);
if(((alarma>=22.5))) { //YESİL LED AKTIF
PORTC.F0=1;
}

else {
portc.f0=0;}

Display_Temperature(temp); // Format and display result on LCD
Delay_ms(500);

} while (1);

}//~!
 
derleme sonrası başarılı da hex dosyası mı alınamıyor ya da varsa derleme sonrası oluşan hata mesajı/mesajları da verilir ise yardım daha kolay olabilir
 
Abi baştan anlatayım, her şeyi ekleyerek..

PIC 16F877 DS 18B20 lcd dijital termometre

Bu projeyi yapmaya çalışıyorum. Hex dosyasını isis'te pic'e attığımda çalışıyor. Ancak bunu benim ödev olarak hazırlamam lazım. Dolayısıyla c kodu ve hex dosyası lazım. Buradaki projeden farklı olarak tek istediğim rc0'ın(alarm - yeşil led diye bahsedilen) 22.5 dereceden sonra aktif olması. Bir satırını değiştireceğim yani.

Sorun orada değil ama.

Dev'de, MikroC'de, CCS'de c kodunu derlemeyi denedim olmadı. Her birinde farklı hata verdi. İnternette araştırdığıma göre

şunu:

Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CURSOR_OFF);

Şöyle yap yazıyordu:

Lcd_Init();
Lcd_Cmd(_Lcd_CURSOR_OFF);

Yaptım. mikroC'de değişiklik oldu bir tek. Hatalar bulup derledi. Hex oluşmadı bu sefer de.

En son CCS'de derleyince, (iki şekilde de) bu hatayı verdi.

295fij8.png

İnternette araştırdığımda şu yazıyordu bununla ilgili:

"Only the main source file should be put in the "Source Files" list.
Don't put any #include files in that list. You can add them to the
"Other files" list.

Look at the Project window in the lower left corner of your screen shot.
You have your main file, PIC16F690.c in the list. But you also have
temperature.c in the list. Remove it. Add it to the "Other Files" list."

Ama dediğini yapamadım.

Kodu bu şekilde yazdığımda; mikroC'de verilen hatalar ise şunlar. Hex oluşmuyor.
Lcd_Init();
Lcd_Cmd(_Lcd_CURSOR_OFF);

jt29fl.png


Her yerde aradım, denedim bulamadım çözümü. Lütfen yardım edin.

Linkteki projenin 22,5 dereceyi geçince rc0'ın aktif olduğu halini, bunun c kodunu ve hex dosyasını istiyorum.

Çok teşekkür ederim şimdiden.
 
Akşama eve gidince kişisel bilgisayarımdan programı derlemeye çalışıp denerim arkadaşım.

Ama eklediğin fotoğraftaki uyarıyı görünce direk olarak LCD kütüphanesinde bir sorun olup olmadığı aklıma geldi. (Hata mesajı LCD'nin pinleriyle alakalı gibi geldi bana; LCD enable ucu, RS vb...) PIC programlama konusunda pek bilgili ve yetenekli değilim, o yüzden seni yanlış yönlendirmiş olmak da istemiyorum. Ama olaya da kayıtsız kalamadım; LCD kütüphaneni bir kontrol etmeni tavsiye ediyorum arkadaşım.

Ben de akşama eve gidince vaktim olursa bir derlemeye çalışırım bu kodları.
 
Çok teşekkür ederim, haber bekliyorum sizden.
 
Arkadaşlar çözebilecek, müsait olan, ilgilenebilecek bir arkadaş daha yok mu?
 
Arkadaşlar, istediğim şu devrenin PIC 16F877 DS 18B20 lcd dijital termometre » 320volt Elektronik Sitesi azıcık değişik hali.

Hex'i çalışan kod derlenmiyor. Kod'da sadece 1 satırı değiştirmem gerek. 21,5 dereceyi geçerse rc0 ucundan 5v alayım. if'teki bir satır değişecek. Ama derlenmiyor işte.

Lütfen arkadaşlar.

Yardım edebilecek yok mu?

Uğraştım yapamadım.

Rica ediyorum.
 
"Only the main source file should be put in the "Source Files" list.
Don't put any #include files in that list. You can add them to the
"Other files" list.

Look at the Project window in the lower left corner of your screen shot.
You have your main file, PIC16F690.c in the list. But you also have
temperature.c in the list. Remove it. Add it to the "Other Files" list."
Bir proje oluştururken pic.c, ana dosya içinde include ile tanıtılır, ana dosya ise (derlenen) projeye kullan diye tanıtılır, yani ana dosya pic gibi include diye programa girilmez.
Bunun çevirisi şu, dosyanda hem pic.c alt dosyası hem de temperature.c dosyası mevcut derleme sendeki temperature.c dosyasını tanımaz, bu dosyayı, ilave edersen de "otherfiles" diye bir kısım var onun altına atman gerekir. Sonuç, include temperature satırını çıkart. Mesajına yeni bakabildim tekrar bakalım, hata bulmak yazmaktan zor.
 
Merhaba.
mikroC'de derlemeyi başardım. LCD için kullanılan pinlerin tanımlanması gerekiyormuş. Jkramer adlı arkadaşım buldu bunu.
https://forum.mikroe.com/viewtopic.php?f=88&t=48270#p186784
ANCAK 2 PROBLEM VAR

1: mikroe linkinde verilen şekilde, pinleri benim şemama göre tanımladığımda -1,93 değerini gösteriyor lcd, sürekli olarak.
347cjs6.png

Neden böyle oldu? Şemada, hangi uçlar birbirine bağlıysa, linkteki gibi yaptım?

2: Alarm, yani rc0'ın belli bir ısı değerinden sonra aktif olması konusu çalışmıyor. Hatalı mı kod? Bunun baştaki lcd pinleriyle alakası nedir ve alarm değerine başta ne atamalıyım ki 21,5'tan sonra çalışsın?
PROGRAMIN KOD HALİ - BOLDLADIĞIM İLK KISIM LCD PİN TANIMLAMALARI, İKİNCİ KISIM ALARM KISMI

// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

// Set TEMP_RESOLUTION to the corresponding resolution of your DS18x20 sensor:
// 18S20: 9
// 18B20: 12 (default setting; can be 9,10,11,or 12)
const unsigned short TEMP_RESOLUTION = 12;

const int RES_FACTOR_1[4] = {5000, 2500, 1250, 625};
const unsigned int RES_FACTOR_2[4] = {0x0001, 0x0003, 0x0007, 0x000F};
const unsigned int RES_FACTOR_3[4] = {0x8000, 0xC000, 0xE000, 0xF000};
float alarma;
unsigned temp,temp2,new_temp;
unsigned short j, RES_SHIFT,j2;

void Display_Temperature(unsigned int temp) {
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
unsigned int temp_whole, temp_fraction;
unsigned short i;
char text[8];

// Isolate the fraction and make it a 4-digit decimal integer (for display)
temp_fraction = temp & RES_FACTOR_2[RES_SHIFT - 1];
temp_fraction = temp_fraction * RES_FACTOR_1[RES_SHIFT - 1];
//portc = temp_fraction;
// Handle the whole part of temperature value
temp_whole = temp;

// Is temperature negative?
if ((temp_whole & 0x8000) != 0u) i = 1; // Yes, i = 1
else i = 0; // No, i = 0
// PORTC = i;
// Remove the fractional part
temp_whole >>= RES_SHIFT;

// Correct the sign if necessary
if (i) temp_whole |= RES_FACTOR_3[RES_SHIFT - 1];

//portd = temp_whole;
IntToStr(temp_whole, text); // Convert whole part to string
Lcd_Out(2, 6, text); // Print whole part on LCD
Lcd_Chr_Cp('.'); // Print dot to separate fractional part


IntToStr(temp_fraction, text); // Convert fractional part to string

// Add leading zeroes (we display 4 digits fractional part)
if (temp_fraction < 1000u) Lcd_Chr_Cp('0');
if (temp_fraction < 100u) Lcd_Chr_Cp('0');
if (temp_fraction < 10u) Lcd_Chr_Cp('0');

Lcd_Out_Cp(text); // Print fractional part on LCD

Lcd_Chr_Cp(223); // Print degree character
Lcd_Chr_Cp('C'); // Print 'C' for Centigrades
}//~

void main() {
ADCON1 = 0xFF; // Configure RA5 pin as digital I/O
PORTE = 0xFF;
TRISE = 0x0F; // PORTE is input
PORTB = 0;
TRISB = 0; // PORTB is output
TRISD=0;
PORTD=0;
TRISC=0;
PORTC=0;

// Initialize LCD on PORTB and prepare for output
Lcd_Init();
Lcd_Cmd(_Lcd_CURSOR_OFF);
Lcd_Out(1, 1, "Sicaklik: ");

do { // main loop

Ow_Reset(&PORTE,2); // Onewire reset signal
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0x44); // Issue command CONVERT_T
Delay_us(120);

Ow_Reset(&PORTE,2);
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0xBE); // Issue command READ_SCRATCHPAD
Delay_ms(400);

j = Ow_Read(&PORTE,2); // Get temperature LSB
j2=j;
temp = Ow_Read(&PORTE,2); // Get temperature MSB
temp2=temp;
temp <<= 8; temp += j; // Form the result
temp2<<=5;
j2>>=3;
new_temp=temp2^j2;
portd=new_temp;
// alarma=39;
alarma=((new_temp*127.5)/255);
if(((alarma>=21.5))) { //YESİL LED AKTIF
PORTC.F0=1;
}


else {
portc.f0=0;}

Display_Temperature(temp); // Format and display result on LCD
Delay_ms(500);

} while (1);

}//~!
 
Sorunlar şunlar:

LCD sürekli Sıcaklık: -1,93 gösteriyor.

RC0 ucu hep aktif.

Isis simülasyonda verilen uyarı mesajı şu:

kedgdl.png


Ne yapmam lazım?


Kodum şöyle, tekrar belirtmem gerekirse (mikroC ile derliyorum). Asıl yapmak istediğim 21,5 dereceden fazla olduğunda rc0'ın aktif olmasını sağlamak ve tabi ki derecenin lcd'de doğru gösterilmesi.

------------------------

// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
// Set TEMP_RESOLUTION to the corresponding resolution of your DS18x20 sensor:
// 18S20: 9
// 18B20: 12 (default setting; can be 9,10,11,or 12)
const unsigned short TEMP_RESOLUTION = 12;

const int RES_FACTOR_1[4] = {5000, 2500, 1250, 625};
const unsigned int RES_FACTOR_2[4] = {0x0001, 0x0003, 0x0007, 0x000F};
const unsigned int RES_FACTOR_3[4] = {0x8000, 0xC000, 0xE000, 0xF000};
float alarma;
unsigned temp,temp2,new_temp;
unsigned short j, RES_SHIFT,j2;

void Display_Temperature(unsigned int temp) {
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
unsigned int temp_whole, temp_fraction;
unsigned short i;
char text[8];

// Isolate the fraction and make it a 4-digit decimal integer (for display)
temp_fraction = temp & RES_FACTOR_2[RES_SHIFT - 1];
temp_fraction = temp_fraction * RES_FACTOR_1[RES_SHIFT - 1];
//portc = temp_fraction;
// Handle the whole part of temperature value
temp_whole = temp;

// Is temperature negative?
if ((temp_whole & 0x8000) != 0u) i = 1; // Yes, i = 1
else i = 0; // No, i = 0
// PORTC = i;
// Remove the fractional part
temp_whole >>= RES_SHIFT;

// Correct the sign if necessary
if (i) temp_whole |= RES_FACTOR_3[RES_SHIFT - 1];

//portd = temp_whole;
IntToStr(temp_whole, text); // Convert whole part to string
Lcd_Out(2, 6, text); // Print whole part on LCD
Lcd_Chr_Cp('.'); // Print dot to separate fractional part


IntToStr(temp_fraction, text); // Convert fractional part to string

// Add leading zeroes (we display 4 digits fractional part)
if (temp_fraction < 1000u) Lcd_Chr_Cp('0');
if (temp_fraction < 100u) Lcd_Chr_Cp('0');
if (temp_fraction < 10u) Lcd_Chr_Cp('0');

Lcd_Out_Cp(text); // Print fractional part on LCD

Lcd_Chr_Cp(223); // Print degree character
Lcd_Chr_Cp('C'); // Print 'C' for Centigrades
}//~

void main() {
ADCON1 = 0xFF; // Configure RA5 pin as digital I/O
PORTE = 0xFF;
TRISE = 0x0F; // PORTE is input
PORTB = 0;
TRISB = 0; // PORTB is output
TRISD=0;
PORTD=0;
TRISC=0;
PORTC=0;

// Initialize LCD on PORTB and prepare for output
Lcd_Init();
Lcd_Cmd(_Lcd_CURSOR_OFF);
Lcd_Out(1, 1, "Sicaklik: ");

do { // main loop

Ow_Reset(&PORTE,2); // Onewire reset signal
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0x44); // Issue command CONVERT_T
Delay_us(120);

Ow_Reset(&PORTE,2);
Ow_Write(&PORTE,2,0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTE,2,0xBE); // Issue command READ_SCRATCHPAD
Delay_ms(400);

j = Ow_Read(&PORTE,2); // Get temperature LSB
j2=j;
temp = Ow_Read(&PORTE,2); // Get temperature MSB
temp2=temp;
temp <<= 8; temp += j; // Form the result
temp2<<=5;
j2>>=3;
new_temp=temp2^j2;
portd=new_temp;
// alarma=39;
alarma=((new_temp*127.5)/255);
if(((alarma>=36.5))) { //YESİL LED AKTIF
PORTC.F0=1;
}

else {
portc.f0=0;}

Display_Temperature(temp); // Format and display result on LCD
Delay_ms(500);

} while (1);

}//~!
 

Forum istatistikleri

Konular
127,950
Mesajlar
913,850
Kullanıcılar
449,598
Son üye
kadir12366

Yeni konular

Geri
Üst