Sari la conținut
ELFORUM - Forumul electronistilor

compilare .c in .hex


Postări Recomandate

Salut, am urmatoarea problema. Nu am mai compilat pana acum un cod sursa .c in cod .hex Am instalat urmatoarele programe: WinAvr si Avrstudio si nu reusesc sa compilez acest cod. Codul l-am atasat sa vedeti. Eu am nevoie sa compilez codul scris in c in cod hex sa-l pot scrie apoi in Attiny85. Cum rezolv problema pentru ca la compilare cu avrstudio am niste erori... Multumesc!

Link spre comentariu
  • Răspunsuri 15
  • Creat
  • Ultimul Răspuns

Top autori în acest subiect

vezi ca nu e bun codul:

root@ionut:/home/ionut# avr-gcc -g -Os -Wall -mcall-prologues -mmcu=attiny85 -c -o PowerMonitor.o PowerMonitor.c PowerMonitor.c:1:2: error: expected identifier or ‘(’ before ‘/’ tokenPowerMonitor.c:14:39: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Even’PowerMonitor.c:37:4: error: invalid suffix "mhz" on integer constantPowerMonitor.c:46:21: fatal error: Stdlib.h: No such file or directorycompilation terminated.

Link spre comentariu

Ai folosit ceva program de editare pe fisierul ala? E alterat rau de tot... Pe langa faptul ca e scris codul ca din c*r.

 

Uite ceva compilabil facut rapid:

 

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Super Awesome Not So Tiny Power Meter * Using Attiny85 * By Bill Porter * Www.billporter.info*** * This Program Is Free Software : You Can Redistribute It And / Or Modify It * Under The Terms Of The Gnu General Public License As Published By The Free * Software Foundation , Either Version 3 Of The License , Or(at Your Option) * Any Later Version. * This Program Is Distributed In The Hope That It Will Be Useful, * But Without Any Warranty ; Without Even The Implied Warranty Of * Merchantability Or Fitness For A Particular Purpose. See The * Gnu General Public License For More Details. * < Http : / / Www.gnu.org / Licenses / >*** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /*Attiny Has One Port , Portb5 Usable PinsPin UsagePb0 Serial TxPb1Pb2 / Adc1 Amp 1Pb3 / Adc3 Amp 2Pb4 / Adc2 VoltsThe Plan Is To Track Time With Timer0 At 1 / 8 ScaleAnd Expanded To 16 Bit In SoftwareAt 1mhz , I Timer Tick Is .000001 Seconds18000 Ticks Is Over A Full Period *///Includes#include <stdlib.h>#include <stdio.h>#include <avr/io.h>#include <inttypes.h>#define F_CPU 8000000UL //8mhz#include <util/delay.h>#include <avr/interrupt.h>#include <avr/wdt.h>// Macros#define Bitread(value , Bit)(((value) >>(bit)) & 0x01)#define Bitset(value , Bit)((value) | =(1ul <<(bit)))#define Bitclear(value , Bit)((value) & = ~(1ul <<(bit)))#define Bitwrite(value , Bit , Bitvalue)(bitvalue Print Bitset(value , Bit) : Bitclear(value , Bit))#define Rms(val)(float)val * .707// Reads Hybrid Timer , Returns Value#define Readtimer()(Timerhighbyte << 8) | TCNT0// Sets Adc Mux To Pin#define Setanalogpin(pin) ADMUX = pin & 0b00000011#ifndef Cbi#define Cbi(sfr , bit)(sfr &= ~(1 << (bit)))#endif#ifndef Sbi#define Sbi(sfr , bit)(sfr |= (1 << (bit)))#endif// Some Settings#define Baud 4800#define Bit_delay 1000000 / Baud#define High 0x1#define Low 0x0#define Txpin 0#define Amps1 1#define Amps2 3#define Volts 2// I Like Bytetypedef uint8_t Byte;// Global Variablevolatile Byte Timerhighbyte;// Function Protosvoid Loop();int Analogread();void Digitalwrite(Byte , Byte);void Serialwrite(Byte);long Map(long , long , long , long , long);int main(){//Setup TimerSbi(TCCR0B , CS01) ;//Prescale At 1 / 8Sbi(TIMSK , TOIE0) ;//Enable Overflow Vector , Used To Extend Timer To 16 Bit//Enable Interuptssei();//Set Pin DirectionsDDRB = 0b00000001;//Clear PullupsPORTB = 0b00000001;//Enable Watchdog Timer , 500ms Delay Before Resetwdt_enable(5);for( ; ; ){ wdt_reset() ;//Reset Watchdog Loop(); _delay_ms(200); }}//The Main Loopvoid Loop(){ //Setup Some Variables unsigned int Max_volts = 0; unsigned int Max_amps1 = 0; unsigned int Max_amps2 = 0; unsigned int Timing_max = 0; unsigned int Volts1 = 0; unsigned int Volts2 = 0; unsigned int Amps1_peak = 0; unsigned int Amps2_peak = 0; unsigned int Freq = 0; unsigned int Amps1_pf = 0; unsigned int Amps2_pf = 0; unsigned int temp = 0; //int Check = 0; char String[50]; Byte String_len = 0; Byte Cs = 0; //Configure Adc //Set Adc Clock At 125khz Sbi(ADCSRA, ADPS2); Sbi(ADCSRA, ADPS1); Cbi(ADCSRA, ADPS0); //Enable A2d Conversions Sbi(ADCSRA, ADEN); //300 Samples Of Each Adc Pin Will Capture Just Over 2 Period       's worth //Of Waveform Data. I                                     'm just looking for the max value. //I Came By 300 By Testing Code Executioin Speed On 8 Mhz Attiny Setanalogpin(Volts); for(int I = 0 ; I <= 300 ; I++ )  if(temp = Analogread() , temp > Max_volts) Max_volts = temp; Setanalogpin(Amps1); for(int I = 0 ; I <= 300 ; I++ )  if(temp = Analogread() , temp > Max_amps1) Max_amps1 = temp; Setanalogpin(Amps2); for(int I = 0 ; I <= 300 ; I++ )  if(temp = Analogread() , temp > Max_amps2) Max_amps2 = temp; //Now Time To Capture Some Timming Data. //First We Are Going To Reconfigure Adc for Faster Reads , At The Cost Of Accuracy //Though We Are Only Looking for When It Peaks , So Who Cares About Accuracy. //Disable A2d Conversions Cbi(ADCSRA, ADEN); //Set Adc Clock At 250khz Sbi(ADCSRA, ADPS2); Cbi(ADCSRA, ADPS1); Sbi(ADCSRA, ADPS0); //Enable Adc Sbi(ADCSRA, ADEN); Setanalogpin(Volts); while(Analogread() != 0) {}//Wait for A Valley while(Analogread() == 0) {}//Wait for The Start for(int I = 0 ; I < 200 ; I++ ){  if(temp = Analogread() , temp > Timing_max) {    Timing_max = temp;    Volts1 = Readtimer();  } } Timing_max = 0; while(Analogread() != 0) {}//Wait for A Valley while(Analogread() == 0) {}//Wait for The Start for(int I = 0 ; I < 200 ; I++ ){  if(temp = Analogread() , temp > Timing_max) {    Timing_max = temp;    Volts2 = Readtimer();  } } //Record Period Time Freq = Volts2 - Volts1;  //Fix The Delays In Reading Adc. Found Experimentally Comparing To A Proper O -scope. Freq -=(Freq / 34); //Lets Do This Again for Pf if(Max_amps1 != 0) {  Timing_max = 0;  while(Analogread() != 0) {}//Wait for A Valley  while(Analogread() == 0) {}//Wait for The Start  for(int I = 0 ; I < 200 ; I++ ){   if(temp = Analogread() , temp > Timing_max) {     Timing_max = temp;     Volts1 = Readtimer();   }  }  Setanalogpin(Amps1);  Timing_max = 0;  while(Analogread() != 0) {}//Wait for A Valley  while(Analogread() == 0) {}//Wait for The Start  for(int I = 0 ; I < 200 ; I++ ){   if(temp = Analogread() , temp > Timing_max) {     Timing_max = temp;     Amps1_peak = Readtimer();   }  }  //Store The Difference In Time  Amps1_peak -= Volts1;  //Fix The Delays In Reading Adc. Found Experimentally Comparing To A Proper O -scope.  Amps1_peak -=(Amps1_peak / 34);  //If The Difference Is Larger Then One Cycle , Divide By # Of Cycles It       's bigger  //To Reduce The Sampel To < 1 Cycle  Amps1_peak -=((Amps1_peak / Freq) * Freq);  temp = Freq / 2;  //Get Within 1 / 2 Cycle If Larger  if(Amps1_peak > temp) Amps1_peak -= temp;  //1 / 4 Cycle Is The Time When Pf = 0  temp /= 2;  if(Amps1_peak < temp)//Handles Different Mapping for Leading / Trailing Pf   Amps1_pf = Map(Amps1_peak , temp , 0 , 0 , 100) ;//Scale Length Of Time To Pf  else   Amps1_pf = Map(Amps1_peak , Freq / 2 , temp , 100 , 0) ;//Scale Length Of Time To Pf } //Rinse And Repeat if(Max_amps2 != 0) {  Timing_max = 0;  Setanalogpin(Volts);  while(Analogread() != 0) {}//Wait for A Valley  while(Analogread() == 0) {}//Wait for The Start  for(int I = 0 ; I < 200 ; I++ ){   if(temp = Analogread() , temp > Timing_max) {     Timing_max = temp;     Volts1 = Readtimer();   }  }  Setanalogpin(Amps2);  Timing_max = 0;  while(Analogread() != 0) {}//Wait for A Valley  while(Analogread() == 0) {}//Wait for The Start  for(int I = 0 ; I < 200 ; I++ ){   if(temp = Analogread() , temp > Timing_max) {     Timing_max = temp;     Amps2_peak = Readtimer();   }  }  //Store The Difference In Time  Amps2_peak -= Volts1;  //Fix The Delays In Reading Adc. Found Experimentally Comparing To A Proper O -scope.  Amps2_peak -=(Amps2_peak / 34);  //If The Difference Is Larger Then One Cycle , Divide By # Of Cycles It       's bigger  //To Reduce The Sampel To < 1 Cycle  Amps2_peak -=((Amps2_peak / Freq) * Freq);  temp = Freq / 2;  //Get Within 1 / 2 Cycle If Larger  if(Amps2_peak > temp) Amps2_peak -= temp;  //1 / 4 Cycle Is The Time When Pf = 0  temp /= 2;  if(Amps2_peak < temp)//Handles Different Mapping for Leading / Trailing Pf   Amps2_pf = Map(Amps2_peak , temp , 0 , 0 , 100) ;//Scale Length Of Time To Pf  else   Amps2_pf = Map(Amps2_peak , Freq / 2 , temp , 100 , 0) ;//Scale Length Of Time To Pf } //Measurments Done. We Have Everything We Need. To To Start Some Conversions //Disable A2d Conversions Cbi(ADCSRA, ADEN); //Remap Adc Values To Actual Voltages , In Millivolts. 5 Volts = 5000 Millivolts. //We Do That To Avoid Floating Point , And Make It Easy To Print Later. Max_volts = Map(Max_volts , 0 , 1023 , 0 , 4960); Max_amps1 = Map(Max_amps1 , 0 , 1023 , 0 , 4960); Max_amps2 = Map(Max_amps2 , 0 , 1023 , 0 , 4960); //Upscale Voltage To Account for Divider And Xformer Max_volts =((float)Max_volts * 42) / 100; /// / Convert Peak To Rms Max_volts = Rms(Max_volts); Max_amps1 = Rms(Max_amps1); Max_amps2 = Rms(Max_amps2); //Measured Transfer Function , Each One Is Different for The Slight Differences In Opamp Gain if(Max_amps1 != 0) Max_amps1 =(float)Max_amps1 * .508 - 39; if(Max_amps2 != 0) Max_amps2 =(float)Max_amps2 * .518 - 36; //Time To Send The Data. Split Into Two Runs Or else It Explodes. //First We                                                'll send a long header to get the RX's attention. for(int I = 0 ; I < 20 ; I++ )  Serialwrite(                                                'X'); Serialwrite(                                                 '$'); String_len = sprintf(String , "POWER,%u.%u,%lu.%lu,%u.%u," , Max_volts / 10 , Max_volts%10 ,(10000000 / Freq) / 10 ,(10000000 / Freq)%10 , Max_amps1 / 10 , Max_amps1%10); for(int I = 0 ; I < String_len ; I++ ){  Serialwrite(String[I]);  Cs^= String[I];  } String_len = sprintf(String , "%u.%u,.%02u,.%02u" , Max_amps2 / 10 , Max_amps2%10 , Amps1_pf , Amps2_pf); //String_len = Sprintf(String , "Samples: %u \n" , Check); for(int I = 0 ; I < String_len ; I++ ){  Serialwrite(String[I]);  Cs^= String[I];  } Serialwrite(                                                 '*'); sprintf(String , "%X" , Cs); for(int I = 0 ; I < 2 ; I++ )  Serialwrite(String[I]); Serialwrite(                                                 '\n');}//Timer 0 OverflowISR(TIM0_OVF_vect){//Extend Timer To 16 Bit Here. Timerhighbyte ++;}int Analogread() { uint8_t low , high; //Start The Conversion Sbi(ADCSRA, ADSC); //Adsc Is Cleared When The Conversion Finishes while (bit_is_set(ADCSRA, ADSC)); //We Have To Read Adcl First ; Doing So Locks Both Adcl //And Adch Until Adch Is Read. Reading Adcl Second Would //Cause The Results Of Each Conversion To Be Discarded, //As Adcl And Adch Would Be Locked When It Completed. low = ADCL; high = ADCH; //Combine The Two Bytes return (high << 8) | low;}//Write Out A Byte As Software Emulated Uartvoid Serialwrite(Byte Bite){Digitalwrite(Txpin , Low) ;//Signal Start Bit_delay_us(Bit_delay);  for(Byte Mask = 0x01 ; Mask ; Mask <<= 1) {     if(Bite & Mask){//Choose Bit       Digitalwrite(Txpin , High) ;//Send 1     }     else{       Digitalwrite(Txpin , Low) ;//Send 0     }     _delay_us(Bit_delay);   } Digitalwrite(Txpin , High) ;//Signal End Bit _delay_us(Bit_delay);}void Digitalwrite(Byte Pin , Byte Val){ Byte Bit = (1 << Pin); if(Val == Low) PORTB &= ~Bit; else PORTB |= Bit;}long Map(long X , long In_min , long In_max , long Out_min , long Out_max){  return(X - In_min) *(Out_max - Out_min) /(In_max - In_min) + Out_min;}
Link spre comentariu

Si cu codul asta tot da eroare la compilarea din .c in .o

 

root@dabv:/avr# avr-gcc -g -Os -mmcu=attiny85 -c test.ctest.c: In function 'Loop':test.c:173: error: 'for' loop initial declaration used outside C99 modetest.c:177: error: redefinition of 'I'test.c:173: error: previous definition of 'I' was heretest.c:177: error: 'for' loop initial declaration used outside C99 modetest.c:181: error: redefinition of 'I'test.c:177: error: previous definition of 'I' was heretest.c:181: error: 'for' loop initial declaration used outside C99 modetest.c:204: error: redefinition of 'I'test.c:181: error: previous definition of 'I' was heretest.c:204: error: 'for' loop initial declaration used outside C99 modetest.c:216: error: redefinition of 'I'test.c:204: error: previous definition of 'I' was heretest.c:216: error: 'for' loop initial declaration used outside C99 modetest.c:237: error: 'for' loop initial declaration used outside C99 modetest.c:250: error: redefinition of 'I'test.c:237: error: previous definition of 'I' was heretest.c:250: error: 'for' loop initial declaration used outside C99 modetest.c:291: error: 'for' loop initial declaration used outside C99 modetest.c:304: error: redefinition of 'I'test.c:291: error: previous definition of 'I' was heretest.c:304: error: 'for' loop initial declaration used outside C99 modetest.c:366: error: redefinition of 'I'test.c:216: error: previous definition of 'I' was heretest.c:366: error: 'for' loop initial declaration used outside C99 modetest.c:373: error: redefinition of 'I'test.c:366: error: previous definition of 'I' was heretest.c:373: error: 'for' loop initial declaration used outside C99 modetest.c:381: error: redefinition of 'I'test.c:373: error: previous definition of 'I' was heretest.c:381: error: 'for' loop initial declaration used outside C99 modetest.c:390: error: redefinition of 'I'test.c:381: error: previous definition of 'I' was heretest.c:390: error: 'for' loop initial declaration used outside C99 modetest.c: In function 'Serialwrite':test.c:437: error: 'for' loop initial declaration used outside C99 mode
Link spre comentariu

multumesc mult, dar oricum raman dator, mai am inca o chestie simpla(simpla pentru tine :da ) de facut daca ai putea sa m-a ajuti. Am realizat si eu proiectul de la viewtopic.php?f=35&t=29786&start=810 si as dori sa mai adaug doua relee pe oricare pini liberi de la atmega8 sa-i comand cu aceasi telecomanda IR, primul releu sa aibe retinere deci odata apasat pe buton de ex. butonul 1 sa faca "clant" apoi iar apasat sa declanseze, iar al doilea releu fara retinere(doar pe perioada apasarii butonului 2 sa imi mentina releul. Butoanele up down vol left si right si pwr on/off sunt deja definite in cod. Acolo dupa cum se vede mai este un releu dar acela porneste doar la comutarea montajului din modul stand-by pentru comanda un amplificator, o sursa o priza, orice... Montajul pot spune ca este foarte bun si ii multumesc lui danzup pentru efort. Postez aici intr-o arhiva tot ce trebuie ,daca ai timp sa modifici codul :da iar cand vi la mare la Cta (nu mai e mult pana la vara) fac cinste asa cum meriti ! Daca poti posta hex-ul dar si codul cu modificarea ta ar fi super...

Link spre comentariu

Creează un cont sau autentifică-te pentru a adăuga comentariu

Trebuie să fi un membru pentru a putea lăsa un comentariu.

Creează un cont

Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!

Înregistrează un nou cont

Autentificare

Ai deja un cont? Autentifică-te aici.

Autentifică-te acum



×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări