/*################################################################################################# Für : Vorlage Version : 1.1 autor : Martin Junghans jtronics@gmx.de www.jtronics.de License : GNU General Public License Hardware: AT90CAN128, 16MHz, Aufgabe: //################################################################################################*/ #include "main.h" #include "can.h" #include "uart.h" #include "lcd.h" #include "fat.h" #include "fat_config.h" #include "partition.h" #include "sd_raw.h" #include "sd_raw_config.h" struct partition_struct* partition; struct fat_fs_struct* fs; struct fat_dir_struct* dd; struct fat_dir_entry_struct directory; struct fat_file_struct* fd; struct fat_dir_entry_struct dir_entry; struct fat_dir_entry_struct file_entry; // float in 4 bytes zerlegen float Buffer_wert = 1234.1234; unsigned char * float_pointer = (unsigned char*) & Buffer_wert; //########################################################################################## Variablen volatile int timer_Taster =0, // timer für echtzeit ausführung timer_ADC =11, timer_lcd_display =99, timer_send_CAN =90, timer_send_Uart1 =12, timer_blink =1000, timer_loggen =100, timer_send_Uart =13; uint8_t sd_log = 0; char buffer[12]; // Buffer für Text Displays oder UART Funktionen int info_can_8bit =0, // sonstige Variablen info_can_16bit =0; unsigned int MessTmin =0, // Variablen Zeit MessTsec =0, MessTzeh =0, MessTtau =0; //########################################################################################## initialisierung void initialisierung(void) { cli(); //####################################### Ports // DDRG = 0b00000000; /*Eingang*/ PORTG = 0b11111111; // Pull-Ups aktiviert --> für Taster cbi(DDRG,0); sbi(PORTG,0); // Taster Eingang + pullup cbi(DDRG,1); sbi(PORTG,1); // Taster Eingang + pullup sbi(DDRG,2); sbi(PORTG,2); // LED off Ausgang //####################################### Externe Interrupts // EICRA |= _BV(ISC01)| _BV(ISC21); // Register A steigende flanke // EICRB |= _BV(ISC60)| _BV(ISC70);//| _BV(ISC60)| _BV(ISC70); // Register B steigende flanke // EIMSK |= _BV(INT6 )| _BV(INT7 ); // Interrupts aktivieren //####################################### Zeit in ms-- 8 Bit Timer0 TCCR0A |= _BV(CS00)| _BV(CS01); // Prescaller TCNT0 = 5; // zählregister TIMSK0 |= _BV(TOIE0); // interrupt aktivieren //####################################### 8 Bit Timer2 // TCCR2 |= _BV(CS22);//| _BV(CS20); // Prescaller // TCNT2 = 0; // zählregister // TIMSK |= _BV(TOIE2); // interrupt aktivieren //####################################### 16 Bit Timer1 // TCCR1B |= _BV(CS10); // timer1 prescaller // TCNT1 = 239; //####################################### UART uart_init ( UART_BAUD_SELECT_DOUBLE_SPEED( UART_BAUD_RATE,F_CPU) ); // Initialize UART,baudrate and AVRcpuclock with macro UART_BAUD_SELECT() (normal speed mode) or UART_BAUD_SELECT_DOUBLE_SPEED() ( double speed mode) */ uart1_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART1_BAUD_RATE,F_CPU) ); // Initialize UART library, pass baudrate and AVR cpu clock with the macro UART_BAUD_SELECT() (normal speed mode ) or UART_BAUD_SELECT_DOUBLE_SPEED() ( double speed mode) //####################################### I2C // i2c_init(); //####################################### CAN can_init(BITRATE_500_KBPS); // Initialize at90can can_filter_t filter = // create a new filter for receiving all { .id = 0x00, .mask = 0x00, .flags = { .rtr = 0b00, // receiving alle Nachrichten .extended = 0b00 // receiving alle Nachrichten } }; can_set_filter(0, &filter); // Filter einstellungen in filter 1(0) von 15 schreiben //####################################### Text LCD //lcd_init(LCD_DISP_ON); //initialize display, cursor off sei(); // now enable interrupt, since UART library is interrupt controlled } //########################################################################################## uint32_t strtolong(const char* str) { uint32_t l = 0; while(*str >= '0' && *str <= '9') l = l * 10 + (*str++ - '0'); return l; } //########################################################################################## uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry) { while(fat_read_dir(dd, dir_entry)) { if(strcmp(dir_entry->long_name, name) == 0) { fat_reset_dir(dd); return 1; } } return 0; } //########################################################################################## struct fat_file_struct* open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name) { struct fat_dir_entry_struct file_entry; if(!find_file_in_dir(fs, dd, name, &file_entry)) return 0; return fat_open_file(fs, &file_entry); } //########################################################################################## uint8_t print_disk_info(const struct fat_fs_struct* fs) { if(!fs) return 0; struct sd_raw_info disk_info; if(!sd_raw_get_info(&disk_info)) return 0; uart1_puts("############################################################\n"); uart1_puts("manuf : 0x"); uart1_putc_hex(disk_info.manufacturer); uart1_putc('\n'); uart1_puts("oem : "); uart1_puts((char*) disk_info.oem); uart1_putc('\n'); uart1_puts("prod : "); uart1_puts((char*) disk_info.product); uart1_putc('\n'); uart1_puts("rev : "); uart1_putc_hex(disk_info.revision); uart1_putc('\n'); uart1_puts("serial: 0x"); uart1_putdw_hex(disk_info.serial); uart1_putc('\n'); uart1_puts("date : "); uart1_putw_dec(disk_info.manufacturing_month); uart1_putc('/'); uart1_putw_dec(disk_info.manufacturing_year); uart1_putc('\n'); uart1_puts("size : "); uart1_putdw_dec(disk_info.capacity / 1024 / 1024); uart1_puts("MB\n"); uart1_puts("copy : "); uart1_putw_dec(disk_info.flag_copy); uart1_putc('\n'); uart1_puts("wr.pr.: "); uart1_putw_dec(disk_info.flag_write_protect_temp); uart1_putc('/'); uart1_putw_dec(disk_info.flag_write_protect); uart1_putc('\n'); uart1_puts("format: "); uart1_putw_dec(disk_info.format); uart1_putc('\n'); uart1_puts("free : "); uart1_putdw_dec(fat_get_fs_free(fs)); uart1_putc('/'); uart1_putdw_dec(fat_get_fs_size(fs)); uart1_putc('\n'); uart1_puts("############################################################\n"); return 1; } //########################################################################################## #if FAT_DATETIME_SUPPORT void get_datetime(uint16_t* year, uint8_t* month, uint8_t* day, uint8_t* hour, uint8_t* min, uint8_t* sec) { *year = 2007; *month = 1; *day = 1; *hour = 0; *min = 0; *sec = 0; } #endif //########################################################################################## blink void blink(void) { static uint8_t status_led = 0; if (status_led == 0) { sbi(PORTG,2); // LED aus status_led =1; timer_blink = 500; } else { cbi(PORTG,2); // LED an status_led = 0; timer_blink = 400; } } //########################################################################################## void SD_loggen_header(void) { // Header schreiben sprintf(sd_buffer,"gps time;gps latitude;gps N/S;gps longitude;gps E/W;gps satellites;gps altitude;gps course;gps speed_KNT;gps speed_KMH;mess time;"); if(fat_write_file(fd, (uint8_t*) sd_buffer, strlen(sd_buffer)) != strlen(sd_buffer)) {uart1_puts("Fehler beim schreiben\n\r"); } sprintf(sd_buffer,"Sensor01;Sensor02;Sensor03;Sensor04;Sensor05;Sensor06;Sensor07;Sensor08;Sensor09;Sensor10;Sensor11;Sensor12;Sensor13;Sensor14;Sensor15;Sensor16;Sensor17;Sensor18;Sensor19;Sensor20\n"); if(fat_write_file(fd, (uint8_t*) sd_buffer, strlen(sd_buffer)) != strlen(sd_buffer)) {uart1_puts("Fehler beim schreiben\n\r"); } // Einheiten sprintf(sd_buffer,"hhmmss:ss;ddmm.mmmm;E/W;dddmm.mmmm;N/S;satelliten;m;°;knt;km/h;hhmmss:ss;"); if(fat_write_file(fd, (uint8_t*) sd_buffer, strlen(sd_buffer)) != strlen(sd_buffer)) {uart1_puts("Fehler beim schreiben\n\r"); } sprintf(sd_buffer,"Sensor01;Sensor02;Sensor03;Sensor04;Sensor05;Sensor06;Sensor07;Sensor08;Sensor09;Sensor10;Sensor11;Sensor12;Sensor13;Sensor14;Sensor15;Sensor16;Sensor17;Sensor18;Sensor19;Sensor20\n"); if(fat_write_file(fd, (uint8_t*) sd_buffer, strlen(sd_buffer)) != strlen(sd_buffer)) {uart1_puts("Fehler beim schreiben\n\r"); } sd_raw_sync(); } //########################################################################################## Logging File auf SD-Karte oeffnen und auf das Ende positionieren. void SD_loggen_open(void) { //############# setup sd card slot if(!sd_raw_init() ) {uart1_puts("MMC/SD initialization failed\n");} else { //############# open first partition partition = partition_open( sd_raw_read,sd_raw_read_interval,sd_raw_write,sd_raw_write_interval,0); // If the partition did not open, assume the storage device is a "superfloppy", i.e. has no MBR. if(!partition) { partition = partition_open(sd_raw_read,sd_raw_read_interval,sd_raw_write,sd_raw_write_interval,-1); if(!partition) { uart1_puts("opening partition failed\n");} } //############# open file system fs = fat_open(partition); if(!fs) { uart1_puts("opening filesystem failed\n");} //############# open root directory fat_get_dir_entry_of_path(fs, "/", &directory); dd = fat_open_dir(fs, &directory); if(!dd) { uart1_puts("opening root directory failed\n");} //############# print some card information as a boot message print_disk_info(fs); //############# print directory entry uart1_puts("Directory:\n\r"); while(fat_read_dir(dd, &dir_entry)) { uint8_t spaces = sizeof(dir_entry.long_name) - strlen(dir_entry.long_name) + 4; uart1_puts(dir_entry.long_name); uart1_putc(dir_entry.attributes & FAT_ATTRIB_DIR ? '/' : ' '); while(spaces--) uart1_putc(' '); uart1_putdw_dec(dir_entry.file_size); uart1_puts("\n\r"); } // Logger File oeffnen und an das Ende spulen, so dass etwas angehaengt werden kann // Wenn das File noch nicht besteht, es erstellen uart1_puts("Oeffne File \"logger.txt\":\n\r"); fd = open_file_in_dir(fs, dd, "logger.txt"); if(!fd) { uart1_puts("Fehler beim oeffnen von: \"logger.txt\"\n\r"); // Nun ein neues File erstellen if(!fat_create_file(dd, "logger.txt", &file_entry)) { uart1_puts("Fehler beim anlegen von: \"logger.txt\"\n\r"); } else { uart1_puts("File: \"logger.txt\" erfolgreich angelegt\n\r"); sd_raw_sync(); } fd = open_file_in_dir(fs, dd, "logger.txt"); if(!fd) { uart1_puts("2. Fehler beim oeffnen von: \"logger.txt\"\n\r"); } } if(fd) { // Auf das Ende des Files positionieren // FAT_SEEK_END und offset=0 heissen, vom Ende der Datei aus 0 Bytes lesen, // mit anderen Worten, an das Ende des Files gehen. int32_t write_offset = 0; if(!fat_seek_file(fd, &write_offset, FAT_SEEK_END)) { uart1_puts("Fehler bei \"fat_seek_file\": \"logger.txt\"\n\r"); fat_close_file(fd); } else { // Header schreiben SD_loggen_header(); } } //############ } } //################################################################################################## void SD_loggen_close(void) { sd_raw_sync(); // Zur Sicherheit noch mal einen sync, damit ist das FS konsistent fat_close_dir(dd); // close directory fat_close(fs); // close file system partition_close(partition); // close partition } //################################################################################################## empf_UART void empf_UART_GPS(void) { //-------------------------------------------------------------------GPD Variablen static char False=9,GPRMC=1,GPGGA=2,GPVTG=3,sentence_type=9; static char gps_Time_Temp[10]; static char gps_Latitude_Temp[12]; static char gps_Northsouth_Temp[1]; static char gps_Longitude_Temp[12]; static char gps_Eastwest_Temp[1]; static char gps_Satellites_Temp[3]; static char gps_Altitude_Temp[8]; static char gps_Course_Temp[8]; static char gps_Speed_KNT_Temp[8]; static char gps_Speed_KMH_Temp[8]; static uint8_t gps_Time_index =0; static uint8_t gps_Latitude_index =0; static uint8_t gps_Northsouth_index =0; static uint8_t gps_Longitude_index =0; static uint8_t gps_Eastwest_index =0; static uint8_t gps_Satellites_index =0; static uint8_t gps_Altitude_index =0; static uint8_t gps_Course_index =0; static uint8_t gps_Speed_KNT_index =0; static uint8_t gps_Speed_KMH_index =0; uint8_t j; //------------------------------------------------------------------- unsigned int newchar; static unsigned char commas; // Number of commas for far in sentence static unsigned char index; // Individual array index newchar = uart_getc(); // Get received character from ringbuffer uart_getc() returns in the lower byte the received character and if(newchar & UART_NO_DATA) // in the higher byte (bitmask) the last receive error UART_NO_DATA is returned when no data is available. { // Wenn keine Daten dann gibts auch nix zu tun } else { // new data available from UART check for Error if (newchar & UART_FRAME_ERROR || newchar & UART_OVERRUN_ERROR || newchar & UART_BUFFER_OVERFLOW) { //uart1_puts_P("Transmission Error!"); } else { //############ Ankommende Daten auswerten if (newchar == 0 ) {commas = 25; sentence_type = False; return;} // A NULL character resets GPS decoding + Set to an outrageous value + Clear local parse variable if (newchar == '$') {commas = 0; sentence_type = False; return;} // Start Sentence character,reset + No commas detected in sentence for far + Clear local parse variable if (newchar == ',') {commas += 1; index = 0; return;} // If there is a comma + Increment the comma count + And reset the field index if (commas == 0) { switch(newchar) { case ('S'): // Only GPRMC sentence contains a "C" sentence_type = 'S'; // Set local parse variable return; case ('D'): // Only GPRMC sentence contains a "C" sentence_type = 'D'; // Set local parse variable return; case ('C'): // Only GPRMC sentence contains a "C" sentence_type = GPRMC; // Set local parse variable return; case ('A'): // The GPGGA sentence ID contains "GA" if (sentence_type == 'G') {sentence_type = GPGGA;} // Set local parse variable return; case ('T'): // The GPVTG sentence ID contains "TG" sentence_type = 'T'; // Set local variable return; case ('G'): // The GPVTG sentence ID contains "TG" if (sentence_type == 'T') // {sentence_type = GPVTG;} // Set local parse variable else sentence_type = 'G'; // if it is not VTG, store "G" return; default: return; } } //--------------------------------------------------------------------------------------- GPGGA if (sentence_type == GPGGA) // GPGGA sentence decode initiated { switch (commas) { case (1): // Time field, grab characters gps_Time_Temp[index++] = newchar; gps_Time_index++; return; case (2): // Latitude field, grab chars gps_Latitude_Temp[index++] = newchar; gps_Latitude_index++; return; case (3): gps_Northsouth_Temp[index++] = newchar; gps_Northsouth_index++; return; case (4): // Longitude field, grab chars gps_Longitude_Temp[index++] = newchar; gps_Longitude_index++; return; case (5): gps_Eastwest_Temp[index++] = newchar; gps_Eastwest_index++; return; case (7): // Satellite field, grab chars gps_Satellites_Temp[index++] = newchar; gps_Satellites_index++; return; case (9): // Altitude field, grab chars gps_Altitude_Temp[index++] = newchar; gps_Altitude_index++; return; case (10): // Altitude field, grab chars j=0; for (uint8_t i=0;i< gps_Time_index; i++) {sd_buffer[j++ ]=gps_Time_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Latitude_index; i++) {sd_buffer[j++ ]=gps_Latitude_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Northsouth_index; i++) {sd_buffer[j++ ]=gps_Northsouth_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Longitude_index; i++) {sd_buffer[j++ ]=gps_Longitude_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Eastwest_index; i++) {sd_buffer[j++ ]=gps_Eastwest_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Satellites_index; i++) {sd_buffer[j++ ]=gps_Satellites_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Altitude_index; i++) {sd_buffer[j++ ]=gps_Altitude_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Course_index; i++) {sd_buffer[j++ ]=gps_Course_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Speed_KNT_index; i++) {sd_buffer[j++ ]=gps_Speed_KNT_Temp[i];} sd_buffer[j++ ]= ';'; for (uint8_t i=0;i< gps_Speed_KMH_index; i++) {sd_buffer[j++ ]=gps_Speed_KMH_Temp[i];} sd_buffer[j++ ]= ';'; sd_buffer_lng= gps_Time_index +gps_Latitude_index +gps_Northsouth_index +gps_Longitude_index +gps_Eastwest_index +gps_Satellites_index +gps_Altitude_index +gps_Course_index +gps_Speed_KNT_index +gps_Speed_KMH_index +10; gps_Time_index =0; gps_Latitude_index =0; gps_Northsouth_index=0; gps_Longitude_index =0; gps_Eastwest_index =0; gps_Satellites_index=0; gps_Altitude_index =0; gps_Course_index =0; gps_Speed_KNT_index =0; gps_Speed_KMH_index =0; return; default: return; } } // end if (sentence_type == GPGGA) //--------------------------------------------------------------------------------------- GPRMC if (sentence_type == GPRMC) // GPGGA sentence decode initiated { switch (commas) { case (7): // Speed in KNT field, grab characters gps_Speed_KNT_Temp[index++] = newchar; gps_Speed_KNT_index++; return; case (8): // Course field, grab characters gps_Course_Temp[index++] = newchar; gps_Course_index++; return; default: return; } } // end if (sentence_type == GPRMC) //--------------------------------------------------------------------------------------- GPVTG if (sentence_type == GPVTG) // GPVTG sentence decode initiated { switch (commas) { case (7): // Speed in KMH field, grab characters gps_Speed_KMH_Temp[index++] = newchar; gps_Speed_KMH_index++; return; default: return; } } // end if (sentence_type == GPVTG) //############## ende uart auswertung } } } //################################################################################################## check_taster void check_taster(void) { static uint8_t sd_card=0; if (!(PING & (1<>> open connetion\n"); SD_loggen_open(); sd_card=1; } else if (sd_card==1) { uart1_puts("<<< close connection\n"); SD_loggen_close(); sd_card=0; } timer_Taster =1000; } if (!(PING & (1<>>\n"); sd_log=1; time=0; } else if (sd_log==1) { uart1_puts("\n<<< log off >>>\n"); sd_log=0; } timer_Taster =1000; } } //########################################################################################## void SD_loggen(void) { if (sd_log == 1) // Wenn das Logging eingeschaltet ist { sprintf(sd_buffer + sd_buffer_lng, "%08.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f;%06.2f\n", time,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45); time+=0.01; if(fat_write_file(fd, (uint8_t*) sd_buffer, strlen(sd_buffer)) != strlen(sd_buffer)) { uart1_puts("Fehler beim schreiben\n\r"); } else { uart1_puts(".."); } sd_raw_sync(); } } //################################################################################################## /* void empf_UART1_CAN(void) { //test # I0012 K01 Wi D1234.0000EZ0 $ unsigned int newchar; newchar = uart1_getc(); // Get received character from ringbuffer uart_getc() returns in the lower byte the received character and if(newchar & UART_NO_DATA) // in the higher byte (bitmask) the last receive error UART_NO_DATA is returned when no data is available. { // Wenn keine Daten dann gibts auch nix zu tun } else// new data available from UART check for Error { if (newchar & UART_FRAME_ERROR || newchar & UART_OVERRUN_ERROR || newchar & UART_BUFFER_OVERFLOW) { //uart1_puts_P("Transmission Error!"); } else { uart_putc(newchar); return; //####################################################### Ankommende Daten von Uart auswerten 1. Schritt static unsigned int index = 0; static unsigned int buchstabe = 0; static unsigned int start = 0; static char Buffer_D[10] = {0,0,0,0,0,0,0,0,0,0}; static unsigned int Buffer_ID = 0; static unsigned int Buffer_was = 0; static float Buffer_Daten = 0; static unsigned int Buffer_kanal = 0; static unsigned int Buffer_zusatz = 0; if (newchar == 0x23) { start=1;} // # - start if (newchar == '$') // $ = send CAN Data { start=0; can_t msg; msg.flags.rtr = 0; msg.flags.extended = 0; msg.id = Buffer_ID; msg.length = 7; // Länge msg.data[0] = Buffer_kanal; // Kanal msg.data[1] = Buffer_was; // Was // float in 4 bytes zerlegen unsigned char * float_pointer = (unsigned char*) & Buffer_Daten; msg.data[2] = *float_pointer++; msg.data[3] = *float_pointer++; msg.data[4] = *float_pointer++; msg.data[5] = *float_pointer++; msg.data[6] = Buffer_zusatz; can_send_message(&msg); //msg.id = Buffer_ID; //msg.length = Buffer_L; //msg.data[0] = Buffer_kanal; //msg.data[1] = Buffer_was; return; } if (start==1) { switch(newchar) { case ('I'): // I = CAN ID buchstabe = 'I'; index = 0; Buffer_ID = 0; break; case ('K'): // K = Kanal buchstabe = 'K'; index = 0; Buffer_kanal= 0; break; case ('W'): // W = Was buchstabe = 'W'; index = 0; Buffer_was = 0; break; case ('D'): // D = Data buchstabe = 'D'; index = 0; Buffer_Daten= 0; break; case ('Z'): // Z = zusatz buchstabe = 'Z'; index = 0; Buffer_zusatz= 0; break; default: //#####################Information verarbeiten switch(buchstabe) { case ('I'): // I = CAN ID if (index<=3) { Buffer_D[index]=newchar; //info auslesen index++; } if (index>3) // ASCII ID in INterger umrechnen { Buffer_ID=Buffer_ID+(Buffer_D[0]-48)*1000; Buffer_ID=Buffer_ID+(Buffer_D[1]-48)*100; Buffer_ID=Buffer_ID+(Buffer_D[2]-48)*10; Buffer_ID=Buffer_ID+(Buffer_D[3]-48); buchstabe='x'; } break; case ('K'): // K = Kanal if (index<=1) { Buffer_D[index]=newchar; //info auslesen index++; } if (index>1) // ASCII ID in INterger umrechnen { Buffer_kanal = Buffer_kanal+(Buffer_D[0]-48)*10; Buffer_kanal = Buffer_kanal+(Buffer_D[1]-48); buchstabe='x'; } break; case ('W'): //was Buffer_was=newchar; //info auslesen buchstabe='x'; break; case ('D'): Buffer_D[index]=newchar; //info auslesen index++; if (newchar == 'E') { Buffer_Daten = (float) atof(Buffer_D); buchstabe='x'; } break; case ('Z'): Buffer_zusatz=newchar-48; //info auslesen buchstabe='x'; break; default: break; } break; } } } } } */ //################################################################################################## /* void empf_CAN(void) { if (can_check_message()) // Check if a new messag was received { can_t msg; if (can_get_message(&msg)) // Try to read the message { switch(msg.id) { //#### Reset case (0x00): if (msg.data[0] == IP_Hardware) {Hard_reset();}break; // hex 000 - Botloader - Software erzeugt RESET //#### Sensoren case ( 222): Data_S[ 0][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 0][1]=1; break; // hex 14B - S_Drehz_Mo 222 case ( 120): Data_S[ 1][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 1][1]=1; break; // hex 14B - S_Drehz_VL 120 case ( 121): Data_S[ 2][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 2][1]=1; break; // hex 14B - S_Drehz_VR 121 case ( 220): Data_S[ 3][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 3][1]=1; break; // hex 14B - S_Drehz_HL 220 case ( 221): Data_S[ 4][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 4][1]=1; break; // hex 14B - S_Drehz_HR 221 case ( 124): Data_S[ 5][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 5][1]=1; break; // hex 14B - S_Feder_VL 124 case ( 125): Data_S[ 6][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 6][1]=1; break; // hex 14B - S_Feder_VR 125 case ( 225): Data_S[ 7][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 7][1]=1; break; // hex 14B - S_Feder_HL 225 case ( 226): Data_S[ 8][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 8][1]=1; break; // hex 14B - S_Feder_HR 226 case ( 223): Data_S[ 9][0]= uniq(msg.data[0],msg.data[1]); Data_S[ 9][1]=1; break; // hex 14B - S_Leerlauf 223 case ( 126): Data_S[10][0]= uniq(msg.data[0],msg.data[1]); Data_S[10][1]=1; break; // hex 14B - S_Not_vorn 126 case ( 127): Data_S[11][0]= uniq(msg.data[0],msg.data[1]); Data_S[11][1]=1; break; // hex 14B - S_Not_Dash 127 case ( 227): Data_S[12][0]= uniq(msg.data[0],msg.data[1]); Data_S[12][1]=1; break; // hex 14B - S_Drossel 227 case ( 229): Data_S[13][0]= uniq(msg.data[0],msg.data[1]); Data_S[13][1]=1; break; // hex 14B - S_Benzi_p 229 case ( 230): Data_S[14][0]= uniq(msg.data[0],msg.data[1]); Data_S[14][1]=1; break; // hex 14B - S_OeL_p 230 case ( 228): Data_S[15][0]= uniq(msg.data[0],msg.data[1]); Data_S[15][1]=1; break; // hex 14B - S_Lambda 228 case ( 236): Data_S[16][0]= uniq(msg.data[0],msg.data[1]); Data_S[16][1]=1; break; // hex 14B - S_Tank 236 case ( 138): Data_S[17][0]= uniq(msg.data[0],msg.data[1]); Data_S[17][1]=1; break; // hex 14B - S_Batterie 138 case ( 150): Data_S[18][0]= uniq(msg.data[0],msg.data[1]); Data_S[18][1]=1; break; // hex 14B - S_Laptime 150 case ( 122): Data_S[19][0]= uniq(msg.data[0],msg.data[1]); Data_S[19][1]=1; break; // hex 14B - S_Breakped 122 case ( 123): Data_S[20][0]= uniq(msg.data[0],msg.data[1]); Data_S[20][1]=1; break; // hex 14B - S_Kupplung 123 case ( 237): Data_S[21][0]= uniq(msg.data[0],msg.data[1]); Data_S[21][1]=1; break; // hex 14B - S_Temp_Oel 237 case ( 238): Data_S[22][0]= uniq(msg.data[0],msg.data[1]); Data_S[22][1]=1; break; // hex 14B - S_Temp_Mo1 238 case ( 239): Data_S[23][0]= uniq(msg.data[0],msg.data[1]); Data_S[23][1]=1; break; // hex 14B - S_Temp_Mo2 239 case ( 139): Data_S[24][0]= uniq(msg.data[0],msg.data[1]); Data_S[24][1]=1; break; // hex 14B - S_Temp_Umg 139 case ( 180): Data_S[25][0]= uniq(msg.data[0],msg.data[1]); Data_S[25][1]=1; break; // hex 14B - S_Temp_RAD_VLL 180 case ( 181): Data_S[26][0]= uniq(msg.data[0],msg.data[1]); Data_S[26][1]=1; break; // hex 14B - S_Temp_RAD_VLM 181 case ( 182): Data_S[27][0]= uniq(msg.data[0],msg.data[1]); Data_S[27][1]=1; break; // hex 14B - S_Temp_RAD_VLR 182 case ( 183): Data_S[28][0]= uniq(msg.data[0],msg.data[1]); Data_S[28][1]=1; break; // hex 14B - S_Temp_RAD_VRL 183 case ( 184): Data_S[29][0]= uniq(msg.data[0],msg.data[1]); Data_S[29][1]=1; break; // hex 14B - S_Temp_RAD_VRM 184 case ( 185): Data_S[30][0]= uniq(msg.data[0],msg.data[1]); Data_S[30][1]=1; break; // hex 14B - S_Temp_RAD_VRR 185 //#### Lenkrad case ( 331): status_show = msg.data[0]; break; // hex 1AB - status_show //#### Steuerung case ( 420): gang = msg.data[0]; break; // Gang case ( 421): status_steuerung1= uniq(msg.data[0],msg.data[1]); break; // case ( 422): status_steuerung2= uniq(msg.data[0],msg.data[1]); break; // //#### default default: break; // andere //#### End } } } } */ //########################################################################################## Timer in Millisekunden ISR(SIG_OVERFLOW0) { TCNT0 = 5; // Zählregister auf 5 setzen --> 200 schritte bis Überlauf // routine wird aller 1msec ausgeführt und zählt variablen runter //#################### timer für Echtzeitablauf timer_Taster--; if (timer_Taster <0) {timer_Taster =0;} // timer // timer_send_CAN--; if (timer_send_CAN <0) {timer_send_CAN =0;} // timer // timer_send_Uart1--; if (timer_send_Uart1 <0) {timer_send_Uart1 =0;} // timer // timer_send_Uart--; if (timer_send_Uart <0) {timer_send_Uart =0;} // timer timer_blink--; if (timer_blink <0) {timer_blink =0;} // timer timer_loggen--; if (timer_loggen <0) {timer_loggen =0;} // timer } //########################################################################################## Hauptprogramm //########################################################################################## int main(void) { initialisierung(); while(1) { //#################### while empf_UART_GPS(); if (timer_Taster <=0) { check_taster(); } // Taster nach gedrückt für 50 msec entprellt if (timer_blink <=0) { blink(); } // LED blink if (timer_loggen <=0) { timer_loggen =10; SD_loggen(); } // LED blink //#################### end while } }