Koda: |
#define LCD_RS_PORT B #define LCD_RS_PIN PINB7 #include "MyMacros.h" |
Koda: |
#define SET_BIT(port,pin) port|=1<<pin #define CLR_BIT(port,pin) port&=~(1<<pin) #define CHECK_BIT(port,pin) (port&(1<<pin)) #define DDR(x) DDR ## x #define PORT(x) PORT ## x #define PIN(x) PIN ## x |
gregoral je napisal/a: | ||
|
Koda: |
#define SET_BIT(port,pin) (port)|=1<<(pin) |
Koda: |
#define SET_BIT(port,pin) (port)|=1<<(pin) |
Koda: |
#define OPERACIJA_A(x) x*2 #define OPERACIJA_B(x) (x)*2 ... int a = OPERACIJA_A(1+1); int b = OPERACIJA_B(1+1); ... // to je isto kot int a = 1+1*2; int b = (1+1)*2; |
gregoral je napisal/a: | ||||
Zakaj pa ne poskusiš v tej smeri?
Vsebina MyMacros.h:
LP, Gregor |
Koda: |
#define SET_BIT(port,pin) (port) |= 1<<(pin)
#define CLR_BIT(port,pin) (port) &=~(1<<(pin)) #define CHECK_BIT(port,pin) ((port)&(1<<(pin))) #define DDRx(x) (DDR ## x) #define PORTx(x) (PORT ## x) #define PINx(x) (PIN ## x) #define DDR(x) DDRx(x) #define PORT(x) PORTx(x) #define PIN(x) PINx(x) #define LCD_RS_PORT B #define LCD_RS_PIN PINB7 |
tilz0R je napisal/a: |
Žal, ampak to je neuporabno za moj problem. |
Koda: |
//typedef uint8_t address_t; //typedef uint8_t index_t; typedef int address_t; typedef int index_t; static inline void SET_BIT(volatile address_t *target, index_t bit){ *target |= (1<<bit); }; static inline void CLR_BIT(volatile address_t *target, index_t bit){ *target &= ~(1<<bit); }; static inline void TOGGLE_BIT(volatile address_t *target, index_t bit){ *target ^= (1<<bit); }; static inline bool CHECK_BIT(volatile address_t *target, index_t bit){ return *target & (1<<bit); }; |
gregoral je napisal/a: | ||
Nisi probal, ne deluje, ti ni všeč, kaj je narobe?? Napiši da bodo tudi drugi vedeli in se morda česa naučili. LP, G |
Koda: |
#ifndef CONCAT1 #define CONCAT1(a, b) CONCAT2(a, b) #endif #ifndef CONCAT2 #define CONCAT2(a, b) a ## b #endif #define SET_BIT(port,pin) (port)|=1<<(pin) #define CLR_BIT(port,pin) (port)&=~(1<<(pin)) #define CHECK_BIT(port,pin) ((port)&(1<<(pin))) #define PINSTATE(port,pin,state) (state==0)?(CLR_BIT((port),(pin))):(SET_BIT((port),(pin))) #define DDR(x) CONCAT1(DDR, x) #define PORT(x) CONCAT1(PORT, x) #define PIN(x) CONCAT1(PIN, x) #define CONCAT(a, b) CONCAT1(a, b) |
Koda: |
DDR(LCD_RS_PORT); |
tilz0R je napisal/a: |
Zdej zakaj je to, da tokrat dela ne vem, če pa kdo ve pa lahko napiše. |
Koda: |
// SPREJEM ZNAKOV // c = uart_getc(); if ( c & UART_NO_DATA ) { /* ni podatkov } else { zastavica=1; sprejem[i]=c; i++; /* * nov podatek */ } // KONEC SPREJEMA // |
Koda: |
char *tmp_rx_data = rx_data; // Zacasni kazalec // Poisci vsebino // Isci do naslednjega ',' while( *tmp_rx_data++ != ',' ); // Izracunaj dolzino int length = tmp_rx_data - rx_data ; // Rezerviraj prostor za vsebino vsebina = (char*)malloc( length ); // Zascitis, da ne vgre cez dovoljene meje vsebina[length-1] = 0; // Prekopiraj vsebino memcpy(vsebina, tmp_rx_data, length-1 ); Hvala! |
klemen88 je napisal/a: |
Naredil sem s to kodo vendar mi ne deluje vedno kot bi morala. |
Koda: |
// Rezerviraj prostor za vsebino
vsebina = (char*)malloc( tmp_rx_data - rx_data ); // Prekopiraj vsebino char *tmp_substr = rx_data; while( tmp_substr != tmp_rx_data ) *(vsebina++) = *(tmp_substr++); *vsebina = 0; // Dodaj null-char na koncu |
Koda: |
// Rezerviraj prostor za vsebino
vsebina = (char*)malloc( length ); // Zascitis, da ne vgre cez dovoljene meje vsebina[--length] = 0; // length je >= 1 // Prekopiraj vsebino while(length--) vsebina[length] = tmp_rx_data[length]; |
Koda: |
// Rezerviraj prostor za vsebino
vsebina = (char*)malloc( length ); // Zascitis, da ne vgre cez dovoljene meje vsebina[--length] = 0; // length je >= 1 // Prekopiraj vsebino memcpy(vsebina, rx_data, length); |