اطلاعیه

Collapse
No announcement yet.

مشکل در برنامه

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل در برنامه

    سلام

    من یه پروژه دارم که با اتمگا 88 هستش از جایی که این آی سی گیرم نیومده بچه ها گفتن از اتمگا 8 هم میتونی استفاده کنی

    من توی پروتئوس تست کردم با اتمگا 88 جواب میده ولی با اتمگا 8 جواب نمیده

    الان با استفاده از آی سی اتمگا 8 باید چه تغییراتی توی برنامه داده بشه ؟؟؟

    این برنامش به زبان C هستش و من چیزی بعنوان atmega88 ندیدم اینم کل برنامه :

    کد PHP:
    #include <avr/io.h>
    #include <util/delay.h>
    #include <avr/interrupt.h>
    #include <avr/pgmspace.h>


    volatile uint8_t i=0;


    #define MAX_STEP 16


    #define START_DELAY 500

    #define INIT_DELAY 10


    #define HEAT_DELAY 110



    const uint8_t led_level[MAX_STEPPROGMEM =
        {
    250,240,200,150,100,50,40,30,
         
    25,20,15,10,5,1,1,1};
         
    /*1,3,7,15,31,63,127,255,
         255,240,230,230,230,220,220,210,
         210,200,200,190,190,180,180,170,
         160,160,150,150,140,140,130,130,
         130,120,110,100,90,80,70,60,
         70,80,90,100,120,130,140,150};*/
         
    int ni,nj,nl;
        

    ISR (TIMER0_OVF_vect)
        {
            
    PORTB 0xFF;
            
    PORTC 0xFF;
            
    PORTD 0xFF;
        };
     
    ISR (TIMER0_COMPA_vect)
        {
            
    PORTB 0x00;
            
    PORTC 0x00;
            
    PORTD 0x00;
        };


    int ledON(int val)
    {
        switch (
    val) {
        case 
    0:
            
    PORTC |= _BV(0);
        break;
        case 
    1:
            
    PORTB |= _BV(5);
        break;
        case 
    2:
            
    PORTB |= _BV(4);
        break;
        case 
    3:
            
    PORTB |= _BV(3);
        break;
        case 
    4:
            
    PORTB |= _BV(2);
        break;
        case 
    5:
            
    PORTB |= _BV(1);
        break;
        case 
    6:
            
    PORTB |= _BV(0);
        break;
        case 
    7:
            
    PORTD |= _BV(7);
        break;
        case 
    8:
            
    PORTD |= _BV(6);
        break;
        case 
    9:
            
    PORTD |= _BV(5);
        break;
        case 
    10:
            
    PORTB |= _BV(7);
        break;
        case 
    11:
            
    PORTB |= _BV(6);
        break;
        case 
    12:
            
    PORTD |= _BV(4);
        break;
        case 
    13:
            
    PORTD |= _BV(3);
        break;
        case 
    14:
            
    PORTD |= _BV(2);
        break;
        case 
    15:
            
    PORTD |= _BV(1);
        break;
        case 
    16:
            
    PORTD |= _BV(0);
        break;
        case 
    17:
            
    PORTC |= _BV(5);
        break;
        case 
    18:
            
    PORTC |= _BV(4);
        break;
        case 
    19:
            
    PORTC |= _BV(3);
        break;
        case 
    20:
            
    PORTC |= _BV(2);
        break;
        case 
    21:
            
    PORTC |= _BV(1);
        break;
        }
    }

    int ledOFF(int val)
    {
        switch (
    val) {
        case 
    0:
            
    PORTC &= ~(_BV(0));
        break;
        case 
    1:
            
    PORTB &= ~(_BV(5));
        break;
        case 
    2:
            
    PORTB &= ~(_BV(4));
        break;
        case 
    3:
            
    PORTB &= ~(_BV(3));
        break;
        case 
    4:
            
    PORTB &= ~(_BV(2));
        break;
        case 
    5:
            
    PORTB &= ~(_BV(1));
        break;
        case 
    6:
            
    PORTB &= ~(_BV(0));
        break;
        case 
    7:
            
    PORTD &= ~(_BV(7));
        break;
        case 
    8:
            
    PORTD &= ~(_BV(6));
        break;
        case 
    9:
            
    PORTD &= ~(_BV(5));
        break;
        case 
    10:
            
    PORTB &= ~(_BV(7));
        break;
        case 
    11:
            
    PORTB &= ~(_BV(6));
        break;
        case 
    12:
            
    PORTD &= ~(_BV(4));
        break;
        case 
    13:
            
    PORTD &= ~(_BV(3));
        break;
        case 
    14:
            
    PORTD &= ~(_BV(2));
        break;
        case 
    15:
            
    PORTD &= ~(_BV(1));
        break;
        case 
    16:
            
    PORTD &= ~(_BV(0));
        break;
        case 
    17:
            
    PORTC &= ~(_BV(5));
        break;
        case 
    18:
            
    PORTC &= ~(_BV(4));
        break;
        case 
    19:
            
    PORTC &= ~(_BV(3));
        break;
        case 
    20:
            
    PORTC &= ~(_BV(2));
        break;
        case 
    21:
            
    PORTC &= ~(_BV(1));
        break;
        }
    }

    int AllON () {
     
    int j;
     
    0;
     while (
    &lt22) {
        
    ledON(j);
        
    j++;
     }
    }
    int AllOFF () {
     
    int j;
     
    0;
     while (
    &lt22) {
        
    ledOFF(j);
        
    j++;
     }
    }
     

    int main(void)
    {

     
    DDRB 0xFF;
     
    DDRC 0xFF;
     
    DDRD 0xFF;
     
    PORTB 0x00;
     
    PORTC 0x00;
     
    PORTD 0x00;

     
    _delay_ms(START_DELAY);
     
    //////////////
    while (1) {
     
    PORTB |= _BV(PB0);
     
    _delay_ms(INIT_DELAY);
     
    PORTB |= _BV(PB7);
     
    _delay_ms(INIT_DELAY);
     
    PORTB |= _BV(PB4);
     
    _delay_ms(INIT_DELAY);
     
    PORTC |= _BV(PC3);
     
    _delay_ms(INIT_DELAY);
     
    PORTC |= _BV(PC5);
     
    _delay_ms(INIT_DELAY);
     
    PORTB |= _BV(PB1);
     
    _delay_ms(INIT_DELAY);
     
    PORTB |= _BV(PB6);
     
    _delay_ms(INIT_DELAY);
     
    PORTB |= _BV(PB2);
     
    //////////////////
     
    _delay_ms(INIT_DELAY); 
     
    PORTD |= _BV(PD0);
     
    _delay_ms(INIT_DELAY);
     
    PORTC |= _BV(PC4);
     
    _delay_ms(INIT_DELAY);
     
    PORTB |= _BV(PB3);
     
    _delay_ms(INIT_DELAY);
     
    PORTB |= _BV(PB5);
     
    _delay_ms(INIT_DELAY);
     
    PORTC |= _BV(PC1);
     
    _delay_ms(INIT_DELAY);
     
    PORTC |= _BV(PC2);
     
    //////////////////
     
    _delay_ms(INIT_DELAY);
     
    PORTC |= _BV(PC0);
     
    _delay_ms(INIT_DELAY);
     
    PORTD |= _BV(PD7);
     
    _delay_ms(INIT_DELAY);
     
    PORTD |= _BV(PD4);
     
    _delay_ms(INIT_DELAY);
     
    PORTD |= _BV(PD3);
     
    _delay_ms(INIT_DELAY);
     
    PORTD |= _BV(PD5);
     
    _delay_ms(INIT_DELAY);
     
    PORTD |= _BV(PD1);
     
    _delay_ms(INIT_DELAY);
     
    PORTD |= _BV(PD6);
     
    _delay_ms(INIT_DELAY);
     
    PORTD |= _BV(PD2);
     
     
    _delay_ms(HEAT_DELAY);
    ///////////////////

    PORTB 0;
    PORTC 0;
    PORTD 0;

    //_delay_ms(500); 

    ni 1;
    nj 0;
    nl 0;
    while (
    ni<2) {

        while (
    nj<=22) {
            
    ledON(nj);
            
    _delay_ms(10); 
            
    nj++;
        }

        
    nj 0;
        while (
    nj<22) {
            
    ledOFF(nj);
            
    _delay_ms(10); 
            
    nj++;
        }
        
    nj 0;
        
    ledON(0);
        while (
    nj<22) {
            
    ledON(21-nj);
            
    _delay_ms(10); 
            
    nj++;
        }
        
    nj 0;
        
    ledON(0);
        while (
    nj<22) {
            
    ledOFF(21-nj);
            
    _delay_ms(10); 
            
    nj++;
        }

        
    nj 0;
        while (
    nl &lt3) {
            while (
    nj<=22) {
                
    ledON(21-nj);
                
    _delay_ms(3);
                
    ledOFF(21-nj); 
                
    nj++;
            }
            
    nj 0;
            
    nl++;
        }
        
        
    nj 0;
        
    nl 0;
        while (
    nl &lt3) {
            while (
    nj<=22) {
                
    ledON(21-nj);
                
    ledON(20-nj);
                
    _delay_ms(3);
                
    ledOFF(21-nj);
                
    ledOFF(20-nj); 
                
    nj++;
            }
            
    nj 0;
            
    nl++;
        }
        
        
    nj 0;
        
    nl 0;
        while (
    nl &lt3) {
            while (
    nj<=22) {
                
    ledON(21-nj);
                
    ledON(20-nj);
                
    ledON(19-nj);
                
    _delay_ms(4);
                
    ledOFF(21-nj);
                
    ledOFF(20-nj); 
                
    ledOFF(19-nj); 
                
    nj++;
            }
            
    nj 0;
            
    nl++;
        }
        
        
    nj 0;
        
    nl 0;
        while (
    nl &lt4) {
            while (
    nj<=22) {
                
    ledON(21-nj);
                
    ledON(20-nj);
                
    ledON(19-nj);
                
    ledON(18-nj);            
                
    _delay_ms(5);
                
    ledOFF(21-nj);
                
    ledOFF(20-nj); 
                
    ledOFF(19-nj); 
                
    ledOFF(18-nj); 
                
    nj++;
            }
            
    nj 0;
            
    nl++;
        }
        
        while (
    nl &lt4) {
            while (
    nj<=22) {
                
    ledON(21-nj);
                
    ledON(20-nj);
                
    ledON(19-nj);
                
    ledON(18-nj);        
                
    ledON(17-nj);    
                
    _delay_ms(6);
                
    ledOFF(21-nj);
                
    ledOFF(20-nj); 
                
    ledOFF(19-nj); 
                
    ledOFF(18-nj); 
                
    ledOFF(17-nj); 
                
    nj++;
            }
            
    nj 0;
            
    nl++;
        }
        
        while (
    nl &lt4) {
            while (
    nj<=22) {
                
    ledON(21-nj);
                
    ledON(20-nj);
                
    ledON(19-nj);
                
    ledON(18-nj);        
                
    ledON(17-nj);    
                
    ledON(16-nj);
                
    _delay_ms(7);
                
    ledOFF(21-nj);
                
    ledOFF(20-nj); 
                
    ledOFF(19-nj); 
                
    ledOFF(18-nj); 
                
    ledOFF(17-nj); 
                
    ledOFF(16-nj); 
                
    nj++;
            }
            
    nj 0;
            
    nl++;
        }
        
        while (
    nl &lt4) {
            while (
    nj<=22) {
                
    ledON(21-nj);
                
    ledON(20-nj);
                
    ledON(19-nj);
                
    ledON(18-nj);        
                
    ledON(17-nj);    
                
    ledON(16-nj);
                
    ledON(15-nj);
                
    _delay_ms(8);
                
    ledOFF(21-nj);
                
    ledOFF(20-nj); 
                
    ledOFF(19-nj); 
                
    ledOFF(18-nj); 
                
    ledOFF(17-nj); 
                
    ledOFF(16-nj); 
                
    ledOFF(15-nj); 
                
    nj++;
            }
            
    nj 0;
            
    nl++;
        }

        
    nj 0;
        
    nl 0;
        while (
    nl &lt4) {
            
    AllON();
            
    _delay_ms(30);
            
    AllOFF();
            
    _delay_ms(25);
            
    AllON();
            
    _delay_ms(55);
            
    AllOFF();
            
    _delay_ms(110);
            
    nl++;
        }
        
    //PORTB = 0;
        //PORTC = 0;
        //PORTD = 0;
        // PORTB |= _BV(PB6);
        // PORTB |= _BV(PB7);
        // _delay_ms(300); 
        // PORTB &= ~(_BV(PB7));
        //_delay_ms(300);
        //PORTB = 0;
        
    ni++;
        
    nj 0;
    }


     
    TCCR0A 0<<WGM00|0<<WGM01
     
    TCCR0B 0<<WGM02|0<<WGM01|0<<CS02|1<<CS01|1<<CS00;
     
    //OCR0A = 0xFF;
     
     
    TIMSK0 _BV(TOIE0); 
     
    TIMSK0 |= _BV(OCIE0A); 
     
    sei(); 
     
     
     
    // _delay_ms(HEAT_DELAY);
     //_delay_ms(200);
     //OCR0A = 0x01;
     //_delay_ms(200); 
     //OCR0A = 64; 
     //_delay_ms(200); 
     //OCR0A = 128; 
     // _delay_ms(200); 
     //OCR0A = 0xFF; 
     
     
     
     
    1;
     
     
     
    nl 0;
     

     while (
    nl <= 511
        {
            
    cli();
            
    TCCR0B 0
            
    //TCNT0 = 0;
            
    OCR0A i;
            
    //OCR0A = led_level[i];
            
    i++;
        
            
    //if ( i > MAX_STEP ) i = 0; 
            
    TCCR0B 0<<WGM02|0<<WGM01|0<<CS02|1<<CS01|1<<CS00
            
    sei();
            
    _delay_us(1000);
            
    nl++;
        
        }

        
    cli();
        
    /*cli();
        AllOFF();
        _delay_ms(50);
        AllON();
        _delay_ms(50);
        AllOFF();*/
    };
     
    return 
    0;


    #2
    پاسخ : مشکل در برنامه

    سلام
    من خودم زیاد با avr stdio کار نکردم ولی تا اونجا که یادمه وقتی می خوای یه پروژه جدید باز کنی همون اول ازت می خواد که نوع میکروتو مشخص کنی ، به نظر من اول یه پروژه جدید باز کن نوع میکروتو مشخص کن بعد کدهاتو توش بنویس انشاالله که جواب بده

    دیدگاه


      #3
      پاسخ : مشکل در برنامه

      سلام

      ممنون از پاسخ شما

      من پیدا کردم قسمت میکرو رو در کنار فایل ها یک فایل به اسم بود Makefile بود که با نود پد باز کردم و 88 رو به 8 تغییر دادم ولی یه مکشل دیگه هست .

      من با 8 که هگز میگیرم این ارور رو میزنه :

      > "make.exe" all

      -------- begin --------
      avr-gcc (WinAVR 20100110) 4.3.3
      Copyright (C) 2008 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions. There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


      Size before:
      AVR Memory Usage
      ----------------
      Device: atmega8

      Program: 2946 bytes (36.0% Full)
      (.text + .data + .bootloader)

      Data: 7 bytes (0.7% Full)
      (.data + .bss + .noinit)




      Compiling C: main.c
      avr-gcc -c -mmcu=atmega8 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./main.lst -std=gnu99 -MMD -MP -MF .dep/main.o.d main.c -o main.o
      main.c warning: 'TIMER0_COMPA_vect' appears to be a misspelled signal handler
      main.c: In function 'ledON':
      main.c:122: warning: no return statement in function returning non-void
      main.c: In function 'ledOFF':
      main.c:194: warning: no return statement in function returning non-void
      main.c: At top level:
      main.c:196: warning: function declaration isn't a prototype
      main.c: In function 'AllON':
      main.c:203: warning: no return statement in function returning non-void
      main.c: At top level:
      main.c:204: warning: function declaration isn't a prototype
      main.c: In function 'AllOFF':
      main.c:211: warning: no return statement in function returning non-void
      main.c: In function 'main':
      main.c:468: error: 'TCCR0A' undeclared (first use in this function)
      main.c:468: error: (Each undeclared identifier is reported only once
      main.c:468: error: for each function it appears in.)
      main.c:468: error: 'WGM00' undeclared (first use in this function)
      main.c:468: error: 'WGM01' undeclared (first use in this function)
      main.c:469: error: 'TCCR0B' undeclared (first use in this function)
      main.c:469: error: 'WGM02' undeclared (first use in this function)
      main.c:473: error: 'TIMSK0' undeclared (first use in this function)
      main.c:474: error: 'OCIE0A' undeclared (first use in this function)
      main.c:501: error: 'OCR0A' undeclared (first use in this function)
      make.exe: *** [main.o] Error 1

      > Process Exit Code: 2
      > Time Taken: 00:01
      ولی به اتمگا 88 و اتمگا 48 خروجی میگیرم دیگه ارور نمیزنه اینم مشخصات برنامه موقع ساختن فایل ها :

      > "make.exe" all

      -------- begin --------
      avr-gcc (WinAVR 20100110) 4.3.3
      Copyright (C) 2008 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions. There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


      Size before:
      AVR Memory Usage
      ----------------
      Device: atmega48

      Program: 2946 bytes (71.9% Full)
      (.text + .data + .bootloader)

      Data: 7 bytes (1.4% Full)
      (.data + .bss + .noinit)




      Compiling C: main.c
      avr-gcc -c -mmcu=atmega48 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./main.lst -std=gnu99 -MMD -MP -MF .dep/main.o.d main.c -o main.o
      main.c: In function 'ledON':
      main.c:122: warning: no return statement in function returning non-void
      main.c: In function 'ledOFF':
      main.c:194: warning: no return statement in function returning non-void
      main.c: At top level:
      main.c:196: warning: function declaration isn't a prototype
      main.c: In function 'AllON':
      main.c:203: warning: no return statement in function returning non-void
      main.c: At top level:
      main.c:204: warning: function declaration isn't a prototype
      main.c: In function 'AllOFF':
      main.c:211: warning: no return statement in function returning non-void

      Linking: main.elf
      avr-gcc -mmcu=atmega48 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.o -std=gnu99 -MMD -MP -MF .dep/main.elf.d main.o --output main.elf -Wl,-Map=main.map,--cref -lm

      Creating load file for Flash: main.hex
      avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock main.elf main.hex

      Creating load file for EEPROM: main.eep
      avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
      --change-section-lma .eeprom=0 --no-change-warnings -O ihex main.elf main.eep || exit 0

      Creating Extended Listing: main.lss
      avr-objdump -h -S -z main.elf > main.lss

      Creating Symbol Table: main.sym
      avr-nm -n main.elf > main.sym

      Size after:
      AVR Memory Usage
      ----------------
      Device: atmega48

      Program: 2946 bytes (71.9% Full)
      (.text + .data + .bootloader)

      Data: 7 bytes (1.4% Full)
      (.data + .bss + .noinit)



      -------- end --------


      > Process Exit Code: 0
      > Time Taken: 00:02
      من تمام میکرو ها رو تست کردم فقط برای 48 و 88 هیچ اروری نمیزنه ولی برای بقیه ارور 2 میزنه درصورتی که دوستان گفتند حافظه میکرو 8 با میکرو 88 یکیه پس این ارور رو واسه چی میزنه

      برنامه استفاده شده winavr

      دیدگاه


        #4
        پاسخ : مشکل در برنامه

        کسی نیست راهنمایی کنه به ما ؟؟

        دیدگاه


          #5
          پاسخ : مشکل در برنامه

          واقعا کسی نیست اطلاع داشته باشه در این مورد ؟؟؟ :angry:

          دیدگاه

          لطفا صبر کنید...
          X