i don't know how give parameters function. wrote body, can see in program below. answers , explanations appreciated!
#include <avr/io.h> #include <stdint.h> // ceramic resonator #ifndef f_cpu #define f_cpu 3686400 // 4mhz #endif // uart #define uart_baud_rate 9600 #define uart_baud_calc(uart_baud_rate,f_osc) ((f_cpu)/((uart_baud_rate)*16l)-1) int decode( int rcv[i], ... ){ !!! int returnvalue; if ((rcv[0] == rcv[1]) && (rcv[0] == rcv[2]) && (rcv[1] == rcv[2])){ returnvalue = 0; //return udr0; } else if (rcv[1] != rcv[2] && (rcv[0] == rcv[1])){ returnvalue = 1; //udr0 = 01; } else if (rcv[1] != rcv[2] && (rcv[0] == rcv[2])){ returnvalue = 2; //udr0 = 02; } else if (rcv[0] != rcv[1] && (rcv[1] == rcv[2])){ returnvalue = 3; //udr0 = 03; } return returnvalue; } int main(void){ // usart ubrr0h =(uint8_t) (uart_baud_calc(uart_baud_rate,f_cpu) >>8); ubrr0l =(uint8_t) uart_baud_calc(uart_baud_rate,f_cpu); ucsr0b = (1<<rxen0) | (1<<txen0); // enable receiver , transmitter, ucsr0c = (3<<ucsz00); // 8 bit (default: asynchronous, no parity, 1 stop-bit) ddrc = (1<<5); // set data direction register bit 5 one, means pc5 configured output portc = (1<<5); // set output value of pc5 high-level (source current, 5v ground) // variables //uint8_t get; // program unsigned char code[3] = {'x','y','z'}; // here need write code unsigned char rcv[3]={'0','0','0'}; // received data int = 0; int retval; while(1){ = 0; for(i=0;i<=2;i++){ // wait empty transmit buffer //while (!(ucsr0a & (1<<udre0))); // wait data received while (!(ucsr0a & (1<<rxc0))); /* put data buffer, sends data*/ { code[i]= udr0 ; } //while(1) // forever //{ portc ^= (1<<5); //this led // received data buffer rcv[i] = code[i]; } retval = decode(int rcv[i], ... ); !!! // wait empty transmit buffer while (!(ucsr0a & (1<<udre0))); // put data buffer, sends data /*if ((rcv[0] == rcv[1]) && (rcv[0] == rcv[2]) && (rcv[1] == rcv[2]))*/ udr0 = retval; } }
you should put pointer array , maybe size of it:
change:
int decode( int rcv[i], ...)
to
int decode( unsigned char* rcv)
and
retval = decode(int rcv[i], ... ); !!!
to
retval = decode(rcv); //rcv pointer
Comments
Post a Comment