Forum: Mikrocontroller und Digitale Elektronik PIC C-Compiler Fehler


von Tim92 (Gast)


Lesenswert?

Hallo

ich habe versucht für das PIC18 Explorer Board eine lcd.c Datei für 
meine Bedürfnisse umzuschreiben und wollte erstmal einen Prototype 
testen.
1
#include "delays.h"
2
3
#define LCD_CS          (LATAbits.LATA2)
4
#define LCD_CS_TRIS     (TRISAbits.TRISA2)
5
#define LCD_RESET       (LATFbits.LATF6)
6
#define LCD_RESET_TRIS  (TRISFbits.TRISF6)
7
8
#define SPI_SCK_TRIS    (TRISCbits.TRISC3)
9
#define SPI_SDO_TRIS    (TRISCbits.TRISC5)
10
#define SPI_CON1        (SSP1CON1)
11
#define SPI_CON1bits    (SSP1CON1bits)
12
#define SPI_BUF         (SSPBUF)
13
#define SPI_STAT        (SSP1STAT)
14
#define SPI_STATbits    (SSP1STATbits)
15
#define SPI_IF          (PIR1bits.SSPIF) //Übertragung / Empfang erfolgreich
16
#define SPI_TRMT        (TXSTAbits.TRMT) //Transmit Shift Register 0 = full 1 = empty
17
18
19
void init_SPI(void){
20
    SPI_SCK_TRIS = 0;
21
    SPI_SDO_TRIS = 0;
22
23
    SPI_CON1 = 0x22;
24
    SPI_STATbits.CKE = 1;
25
    SPI_IF = 0;
26
}
27
28
void initPORTA(void){
29
   LCD_CS = 0;
30
   SPI_BUF = 0x40;
31
   while(!SPI_IF);
32
   SPI_IF = 0;
33
34
   SPI_BUF = 0x00;
35
   while(!SPI_IF);
36
   SPI_IF = 0;
37
38
   SPI_BUF = 0x00;
39
   while(!SPI_IF);
40
   SPI_IF = 0;
41
42
   LCD_CS = 1;
43
}
44
45
void writePORTA(unsigned char b){
46
   LCD_CS = 0;
47
   SPI_BUF = 0x40;
48
   while(!SPI_IF);
49
   SPI_IF = 0;
50
51
   SPI_BUF = 0x12;
52
   while(!SPI_IF);
53
   SPI_IF = 0;
54
55
   SPI_BUF = b;
56
   while(!SPI_IF);
57
   SPI_IF = 0;
58
59
   LCD_CS = 1;
60
}
61
62
void initPORTB(void){
63
   LCD_CS = 0;
64
   SPI_BUF = 0x40;
65
   while(!SPI_IF);
66
   SPI_IF = 0;
67
68
   SPI_BUF = 0x01;
69
   while(!SPI_IF);
70
   SPI_IF = 0;
71
72
   SPI_BUF = 0x00;
73
   while(!SPI_IF);
74
   SPI_IF = 0;
75
76
   LCD_CS = 1;
77
}
78
79
void writePORTB(unsigned char b){
80
   LCD_CS = 0;
81
   SPI_BUF = 0x40;
82
   while(!SPI_IF);
83
   SPI_IF = 0;
84
85
   SPI_BUF = 0x13;
86
   while(!SPI_IF);
87
   SPI_IF = 0;
88
89
   SPI_BUF = b;
90
   while(!SPI_IF);
91
   SPI_IF = 0;
92
93
   LCD_CS = 1;
94
}
95
96
void LCD_Befehl(unsigned char b){
97
    writePORTA(0x00);
98
    Delay10TCYx(20);
99
    Delay10TCYx(20);
100
    Delay10TCYx(20);
101
    writePORTB(b);
102
    Delay100TCYx(10);
103
    writePORTA(0x40);
104
    Delay100TCYx(10);
105
    Delay100TCYx(10);
106
    writePORTA(0x00);
107
}
108
109
void LCD_Data(unsigned char b){
110
    writePORTA(0x80);
111
    Delay100TCYx(10);
112
    writePORTB(b);
113
    Delay100TCYx(10);
114
    writePORTA(0xC0);
115
    Delay100TCYx(10);
116
    Delay100TCYx(10);
117
    writePORTA(0x00);
118
    TXREG = b;          //carriage return
119
    while(!SPI_TRMT);    //wait for data TX
120
    SPI_TRMT = 0;
121
}
122
123
void LCD_Line1(void){
124
    LCD_Befehl(0x80);
125
}
126
void LCD_Line2(void){
127
    LCD_Befehl(0xc0);
128
}
129
void LCD_Clear(void){
130
    LCD_Befehl(0x01);
131
}
132
void LCD_init(void){
133
    LCD_CS_TRIS = 0;
134
    LCD_CS = 1;
135
    Delay10TCYx(20);
136
    Delay10TCYx(20);
137
    Delay10TCYx(20);
138
139
    LCD_RESET_TRIS = 0;
140
    LCD_RESET = 0;
141
    Delay10TCYx(20);
142
    Delay10TCYx(20);
143
    LCD_RESET = 1;
144
145
    init_SPI();
146
    initPORTA();
147
    initPORTB();
148
149
    Delay10TCYx(20);
150
    Delay10TCYx(20);
151
    LCD_Befehl(0x3c); //0011NFxx
152
153
    Delay10TCYx(20);
154
    Delay10TCYx(20);
155
    LCD_Befehl(0x0c); //Display off
156
157
    Delay10TCYx(20);
158
    Delay10TCYx(20);
159
    LCD_Befehl(0x01); //Display clear
160
161
    Delay10TCYx(20);
162
    Delay10TCYx(20);
163
    LCD_Befehl(0x06);} //Entry Mode

die main dazu:
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <p18f8722.h>
4
#include "lcd.c"
5
6
#pragma config  OSC = HSPLL
7
#pragma config   FCMEN = OFF
8
#pragma config   IESO = OFF
9
#pragma config   PWRT = OFF
10
#pragma config   BOREN = OFF
11
#pragma config   WDT = OFF
12
#pragma config   MCLRE = ON
13
#pragma config   LVP = OFF
14
#pragma config   XINST = OFF
15
16
void main(void) {
17
    LCD_init();
18
    while(1){
19
       LCD_Line1();
20
       LCD_Data('H');
21
       LCD_Data('e');
22
       LCD_Data('l');
23
       LCD_Data('l');
24
       LCD_Data('l');
25
       LCD_Data(' ');
26
       LCD_Data('W');
27
       LCD_Data('o');
28
       LCD_Data('r');
29
       LCD_Data('l');
30
       LCD_Data('d');
31
       LCD_Line2();
32
       LCD_Data('Y');
33
       LCD_Data('E');
34
       LCD_Data('A');
35
       LCD_Data('H');
36
    }
37
    
38
}

Der Compiler MPLAB X IDE v1.6 - C18(v3.44)
(habs erst mit dem xc8 versucht der macht aber probleme mit der 
delays.h)
bringt die Fehlermeldung:
1
Error - symbol 'init_SPI' has multiple definitions.
2
Errors    : 1
3
4
make[2]: Leaving directory `C:/Users/Tim/Documents/Microchip/LCD-selfmade-0.1.X'
5
make[1]: Leaving directory `C:/Users/Tim/Documents/Microchip/LCD-selfmade-0.1.X'
6
make[2]: *** [dist/default/production/LCD-selfmade-0.1.X.production.hex] Error 1
7
make[1]: *** [.build-conf] Error 2
8
make: *** [.build-impl] Error 2
9
10
BUILD FAILED (exit value 2, total time: 2s)

hab nun alles 5 mal angeschaut ich finde nirgends eine doppelte 
definition?

sieht die jemand oder einen anderen fehler?

mfg
tim

von Karl H. (kbuchegg)


Lesenswert?

Tim92 schrieb:



> Der Compiler MPLAB X IDE v1.6 - C18(v3.44)

Genau genommen nicht der Compiler, sondern der Linker

> (habs erst mit dem xc8 versucht der macht aber probleme mit der
> delays.h)
> bringt die Fehlermeldung:
> [code]Error - symbol 'init_SPI' has multiple definitions.
> Errors    : 1

> hab nun alles 5 mal angeschaut ich finde nirgends eine doppelte
> definition?

hier kommt sie zu Stande:

main.c
******

#include "lcd.c"


und wenn du dann lcd.c nochmal kompilierst und dazulinkst, hast du dann 
beim Linken alle Funktionen doppelt.

C-Files werden nicht inkludiert! C-Files werden kompiliert und die 
Einzelteile werden zum kompletten Programm zusammengelinkt.

von Tim92 (Gast)


Lesenswert?

ahhh ok
jetzt gehts - super vielen dank mein abend ist gerettet :D

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.