Merhaba arkadaşlar,
CCS C ile programlama yapıyordum, XC8'e geçme kararı aldım. Basit bir led uygulaması ile başlamak istedim 18F452 ile. Derleme hatası alıyorum. Araştırma yaptım ama çözüme ulaşamadım, yardımcı olursanız çok sevinirim. Kodlar ve hata aşağıda.
main.h
#include <xc.h>
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//END CONFIG
#define _XTAL_FREQ 20000000
main.c
#include <main.h>
int main()
{
TRISB0 = 0; //RB0 as Output PIN
while(1)
{
RB0 = 1; // LED ON
__delay_ms(1000); // 1 Second Delay
RB0 = 0; // LED OFF
__delay_ms(1000); // 1 Second Delay
}
return 0;
}
Aldığım hata;
make[2]: *** [build/default/production/main.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
main.c:8: error: (141) can't open include file "main.h": No such file or directory
(908) exit status = 1
nbproject/Makefile-default.mk:94: recipe for target 'build/default/production/main.p1' failed
make[2]: Leaving directory 'C:/XC8/led_blink.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/XC8/led_blink.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUİLD FAILED (exit value 2, total time: 379ms)
Görünüşe göre main.h dosyası bulunamıyor. Derleyici ayarları hatalı olabilir.
Ayrıca yapmam gereken bir ayar mı var ki ?
main.h ve main.c proje klasörünün içinde ve tanıttım da.
Şu aşağıdaki hatayı da anlayabilmiş değilim, Microchip'in kendi sitesindeki çözümü uyguladım aşağıdaki hata için yine değişmedi sonuç :(
:: warning: (1459) peripheral library support is missing for the 18F452
deneyemiyorum tahminim main.h ismini degiştir .yada içerigini void main in üzerine kopyala.
Kodları aşağıdaki gibi yaptım...
#include <xc.h>
#define _XTAL_FREQ 20000000
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//END CONFIG
int main()
{
TRISB0 = 0; //RB0 as Output PIN
while(1)
{
RB0 = 1; // LED ON
__delay_ms(1000); // 1 Second Delay
RB0 = 0; // LED OFF
__delay_ms(1000); // 1 Second Delay
}
return 0;
}
Bu hatalar oluştu...
:: warning: (1459) peripheral library support is missing for the 18F452
main.c:12: error: (1363) unknown configuration setting/register (FOSC = HS) used
main.c:13: error: (1363) unknown configuration setting/register (WDTE = ON) used
main.c:14: error: (1363) unknown configuration setting/register (PWRTE = OFF) used
main.c:15: error: (1363) unknown configuration setting/register (BOREN = ON) used
main.c:18: error: (1363) unknown configuration setting/register (WRT = OFF) used
main.c:19: error: (1363) unknown configuration setting/register (CP = OFF) used
main.c:27: warning: (1385) variable "RB0" is deprecated (declared at main.c:27)
main.c:29: warning: (1385) variable "RB0" is deprecated (declared at main.c:29)
make[2]: *** [build/default/production/main.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
(908) exit status = 1
nbproject/Makefile-default.mk:94: recipe for target 'build/default/production/main.p1' failed
make[2]: Leaving directory 'C:/XC8/led_blink.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/XC8/led_blink.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUİLD FAILED (exit value 2, total time: 306ms)
Peripheral Library ile ilgili sorun galiba. Microchip'in sitesinden yüklemiştim değişen bir şey olmadı yine.
Kaçırdığım bir nokta mı var acaba ?
Çalışan kodlarımdan yollamaya çalışırım eve gidince.
Ek:
Customize:
Conf->XC8 global options->XC8 linker
Additional options: --runtime=-plib ilave edilecek,
Option for XC8->Runtime
Link in Peripheal Library işaretli olacak...
Alttaki bölümde uyarı olarak çıkıyor.
:: advisory: (1233) Employing 18F452 errata work-arounds:
:: advisory: (1234) * Address 4000h boundary
:: advisory: (1234) * Faulty table reads at -40 degrees C
:: advisory: (1234) * GOTO instruction at reset vector must be preceded by NOP
:: advisory: (1234) * Peripherals can misbehave if BSR = 15
:: advisory: (1234) * DAW instruction may improperly clear CARRY bit
:: advisory: (1234) * Specifically disable interrupt sources during tblwt instruction
:: advisory: (1234) * Writes to flash must target opposite side of 4000h boundary
Ayrıca 80245a.pdf->6.2 nolu bölümde PIC18F4520 kullanılması öneriliyor...
#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */
// PIC18F452 Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG1H
#pragma config OSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config OSCS = OFF // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is disabled (main oscillator is source))
// CONFIG2L
#pragma config PWRT = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOR = ON // Brown-out Reset Enable bit (Brown-out Reset enabled)
#pragma config BORV = 42 // Brown-out Reset Voltage bits (VBOR set to 4.2V)
// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 128 // Watchdog Timer Postscale Select bits (1:128)
// CONFIG3H
#pragma config CCP2MUX = ON // CCP2 Mux bit (CCP2 input/output is multiplexed with RC1)
// CONFIG4L
#pragma config STVR = ON // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause RESET)
#pragma config LVP = OFF // Low Voltage ICSP Enable bit (Low Voltage ICSP disabled)
// CONFIG5L
#pragma config CP0 = ON // Code Protection bit (Block 0 (000200-001FFFh) code protected)
#pragma config CP1 = ON // Code Protection bit (Block 1 (002000-003FFFh) code protected)
#pragma config CP2 = ON // Code Protection bit (Block 2 (004000-005FFFh) code protected)
#pragma config CP3 = ON // Code Protection bit (Block 3 (006000-007FFFh) code protected)
// CONFIG5H
#pragma config CPB = ON // Boot Block Code Protection bit (Boot Block (000000-0001FFh) code protected)
#pragma config CPD = ON // Data EEPROM Code Protection bit (Data EEPROM code protected)
// CONFIG6L
#pragma config WRT0 = ON // Write Protection bit (Block 0 (000200-001FFFh) write protected)
#pragma config WRT1 = ON // Write Protection bit (Block 1 (002000-003FFFh) write protected)
#pragma config WRT2 = ON // Write Protection bit (Block 2 (004000-005FFFh) write protected)
#pragma config WRT3 = ON // Write Protection bit (Block 3 (006000-007FFFh) write protected)
// CONFIG6H
#pragma config WRTC = ON // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) write protected)
#pragma config WRTB = ON // Boot Block Write Protection bit (Boot Block (000000-0001FFh) write protected)
#pragma config WRTD = ON // Data EEPROM Write Protection bit (Data EEPROM write protected)
// CONFIG7L
#pragma config EBTR0 = ON // Table Read Protection bit (Block 0 (000200-001FFFh) protected from Table Reads executed in other blocks)
#pragma config EBTR1 = ON // Table Read Protection bit (Block 1 (002000-003FFFh) protected from Table Reads executed in other blocks)
#pragma config EBTR2 = ON // Table Read Protection bit (Block 2 (004000-005FFFh) protected from Table Reads executed in other blocks)
#pragma config EBTR3 = ON // Table Read Protection bit (Block 3 (006000-007FFFh) protected from Table Reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = ON // Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) protected from Table Reads executed in other blocks)
#define _XTAL_FREQ 20000000UL
void my_delay_ms(uint16_t ms)
{
while(--ms)
{
__delay_ms(1);
}
}
void main(void)
{
ADCON1 = 0x07;
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
while(1)
{
LATAbits.LATA0 = 1; // LED on
my_delay_ms(50);
LATAbits.LATA0 = 0; // LED off
my_delay_ms(950);
}
}
Konfigürasyon bitlerinin hepsini OFF yapınca çalıştı enteresan bir şekilde.
Şimdi de buton ile ilgili problemler yaşıyorum.
Butonu A0,A1,A2,A3 e bağladım sırasıyla denemek için. Bastığımda led yansın istiyorum fakat yanmıyor. Aynı şekilde A4'e bağladığımda ise çalışıyor.
Buraya çok uğrayacağım sanırsam :D
main.h dosyasını görmemesinin nedenini buldum.
#include <main.h>
yerine;
#include "main.h"
yazınca main.h dosyasını gördü.