Koda: |
void LCDstring(uint8_t*, uint8_t, uint8_t); //Outputs string to LCD - na poziciji x,y (12.10.2011)
|
Koda: |
volatile unsigned char tekst [21]; |
Koda: |
LCDstring ("11.12.2020 v1.2", 0, 1);
|
Koda: |
sprintf (tekst, "%03d.%d'C", temp/10, abs(temp%10));
LCDstring(tekst,9,0); |
Koda: |
static char EEMEM eVar[9]= "XYZ"; //primer z zacentno vrednostjo
|
Koda: |
struct EEP_Vars_struct
{ char EEP_Var1[9]; //to bi nastavil na "X" char EEP_Var2[5]; //to bi nastavil na "Y" }; struct EEMEM EEP_Vars_struct EEP_Vars[3]; //v vseh strukturah zelim enako |
Koda: |
char ID[5];
|
Koda: |
struct ID_struct {
char ID[5]; }; ID_struct ID[n]; ali char ID[n][5]; |
mato1111 je napisal/a: | ||||
Tudi jaz imam vprsanje in sicer je povezano z eepromom. Rad bi nastavil zacetne vrednosti eeprom spremenljivk in jih vnesel v MCU ko bi ga sprogramiral z eep datoteko.
V spodnjem primeru mi je jasno:
Ni pa mi jasno kako se to naredi ce imam spremenljivke v strukturi:
|
Koda: |
/* Lahko daš številko v oklepaje da definiraš velikost, drugače se bo definirala pri definiciji */ struct EEMEM EEP_Vars_struct EEP_Vars[] = { {"X", "Y"}, /* Prvi element, < C99 stil */ { .EEP_Var1 = "X", .EEP_Var2 = "Y" } /* >= C99 stil */ } |
mato1111 je napisal/a: | ||||
In se naslednje vprasanje. Zelim n spremenljivk tipa string kot je spodnja
Je boljse uporabit en 2D array ali n struktur?
|
Koda: |
#include <stdio.h> #include "lcd_lib.c" #include <avr\io.h> //ena vrsta definicije je komentirana zaradi možnosti kompilanja //pri tej definiciji vržeta napako oba LCDstringa, sprintf pa ne (NAPAKA1) char tekst [20]; //pri tej definiciji vržeta napako prvi LCDstring in sprintf. //Drugi LCDstring pa ne (NAPAKA2) //unsigned char tekst [20]; int main (void) { while (1) { //Rezultat obojega je izpisana beseda "Napiši" na ekranu (pozicija 0,0) LCDstring ("Napisi",0,0); sprintf (tekst, "Napisi"); LCDstring (tekst,0,0); LCDclr(); } } /* Copy/paste napake 1 (prva definicija)+++++++++++++++++++++ ../Test.c: In function 'main': *./Test.c:22:1: warning: pointer targets in passing argument 1 of 'LCDstring' differ in signedness ../lcd_lib.c:144:6: note: expected 'uint8_t *' but argument is of type 'char *' *./Test.c:25:1: warning: pointer targets in passing argument 1 of 'LCDstring' differ in signedness ../lcd_lib.c:144:6: note: expected 'uint8_t *' but argument is of type 'char *' Copy/paste napake 2 (druga definicija)++++++++++++++++++++ ':../Test.c: In function 'main': *./Test.c:22:1: warning: pointer targets in passing argument 1 of 'LCDstring' differ in signedness ../lcd_lib.c:144:6: note: expected 'uint8_t *' but argument is of type 'char *' *./Test.c:24:1: warning: pointer targets in passing argument 1 of 'sprintf' differ in signedness c:\program files\atmel\avr tools\avr toolchain\bin\../lib/gcc/avr/4.5.1/../../../../avr/include/stdio.h:669:12: note: expected 'char *' but argument is of type 'unsigned char *' */ |
Koda: |
strcpy(tekst,"Napisi"); //Vkljucit moras se knjiznico <string.h>
|
Koda: |
sprintf (tekst, "%s", "Napisi");
|
Koda: |
void PrintString(int8_t*); |
Koda: |
volatile unsigned int Vlaga; |