logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

void C_task main(void) -> czy ktos z tym mial probemy??

Radek_go 17 Sty 2006 00:18 1733 2
REKLAMA
  • #1 2189157
    Radek_go
    Poziom 11  
    Posty: 13
    Witam serdecznie,
    mam juz troche dosc walki z przerabianiem starych programow z not aplikacyjnych na dzialajace, ale czasem nie chce mi sie pisac calego kodu aby sprawdzc jakas funkcje. Stad moje pytanko:
    void C_task main(void) ->co to jest i jak to obejsc w obecnym kompilatorze WinAVR??

    mam rowniez problem z:

    interrupt [TIMER0_OVF_vect] void counter(void)
    w obu przypadkach pisze o nieprawidlowej skladni.
    Dla mnie tez to wyglada dziwnie ;)
    programik jest z noty AVR134
    do wgladu min pod linkiem:
    http://katalog.elektroda.net/download.php?id=275

    dziekuje i pozdrawiam

    Radek_Go.
  • REKLAMA
  • Pomocny post
    #2 2189381
    al555
    Poziom 20  
    Posty: 485
    Pomógł: 32
    Ocena: 8
    Ten kod jest napisany dla ATmega103 ( niedostępny już w handlu) a jego następca to ATmega128.

    Poniżej poprawki dla WinAVR ( ten kod był dla kompilatora IAR):

    1.
    #include <iom103.h>
    #include <ina90.h>

    ma być

    #include <avr/io.h>
    #include <avr/signal.h>

    2.
    type def struct{
    ma być
    typedef struct{

    3.
    interrupt [TIMER0_OVF_vect] void counter(void) //overflow interrupt vector
    ma być
    SIGNAL(SIG_OVERFLOW0)

    4.
    void C_task main(void) //C_task means "main" is never called from another function
    ma być
    int main(void)

    5.
    _SEI(); //set the Global Interrupt Enable Bit
    ma być
    asm("sei");

    6.
    _SLEEP(); //will wake up from time overflow interrupt
    ma być
    asm("sleep");

    7.
    _NOP();
    ma być
    asm("nop");


    A zresztą zamieszczę cały poprawiony kod ( możesz skopiować):
    
    /**** A V R A P P L I C A T I O N NOTE 1 3 4 **************************
    *
    * Title: Real-Time Clock
    * Version: 1.01
    * Last Updated: 12.10.98
    * Target: ATmega103 (All AVR Devices with secondary external oscillator)
    * Support E-mail: avr@atmel.com
    *
    * Description
    * This application note shows how to implement a Real-Time Clock utilizing a secondary
    * external oscilator. Included a test program that performs this function, which keeps
    * track of time, date, month, and year with auto leap-year configuration. 8 LEDs are used
    * to display the RTC. The 1st LED flashes every second, the next six represents the
    * minute, and the 8th LED represents the hour.
    *
    ******************************************************************************************/
    
    #include <avr/io.h>
    #include <avr/signal.h>
    
    //#include <iom103.h>
    //#include <ina90.h>
    char not_leap(void);
    typedef struct{
    unsigned char second; //enter the current time, date, month, and year
    unsigned char minute;
    unsigned char hour;
    unsigned char date;
    unsigned char month;
    unsigned int year;
    }time;
    time t;
    //void C_task main(void) //C_task means "main" is never called from another function
    int main(void)
    {
    int temp0,temp1;
    for(temp0=0;temp0<0x0040;temp0++) // Wait for external clock crystal to stabilize
    {
    for(temp1=0;temp1<0xFFFF;temp1++);
    }
    DDRB=0xFF;
    TIMSK &=~((1<<TOIE0)|(1<<OCIE0)); //Disable TC0 interrupt
    ASSR |= (1<<AS0); //set Timer/Counter0 to be asynchronous from the CPU clock
    //with a second external clock(32,768kHz)driving it.
    TCNT0 = 0x00;
    TCCR0 = 0x05; //prescale the timer to be clock source / 128 to make it
    //exactly 1 second for every overflow to occur
    while(ASSR&0x07); //Wait until TC0 is updated
    TIMSK |= (1<<TOIE0); //set 8-bit Timer/Counter0 Overflow Interrupt Enable
    //_SEI(); //set the Global Interrupt Enable Bit
    asm("sei");
    while(1)
    {
    MCUCR = 0x38; //entering sleeping mode: power save mode
    //_SLEEP(); //will wake up from time overflow interrupt
    asm("sleep");
    //_NOP();
    asm("nop");
    TCCR0=0x05; // Write dummy value to Control register
    while(ASSR&0x07); //Wait until TC0 is updated
    }
    }
    
    SIGNAL(SIG_OVERFLOW0)
    //interrupt [TIMER0_OVF_vect] void counter(void) //overflow interrupt vector
    {
    if (++t.second==60) //keep track of time, date, month, and year
    {
    t.second=0;
    if (++t.minute==60)
    {
    t.minute=0;
    if (++t.hour==24)
    {
    t.hour=0;
    if (++t.date==32)
    {
    t.month++;
    t.date=1;
    }
    else if (t.date==31)
    {
    if ((t.month==4) || (t.month==6) || (t.month==9) || (t.month==11))
    {
    t.month++;
    t.date=1;
    }
    }
    else if (t.date==30)
    {
    if(t.month==2)
    {
    t.month++;
    t.date=1;
    }
    }
    else if (t.date==29)
    {
    if((t.month==2) && (not_leap()))
    {
    
    t.month++;
    t.date=1;
    }
    }
    if (t.month==13)
    {
    t.month=1;
    t.year++;
    }
    }
    }
    }
    PORTB=~(((t.second&0x01)|t.minute<<1)|t.hour<<7);
    }
    char not_leap(void) //check for leap year
    {
    if (!(t.year%100))
    return (char)(t.year%400);
    else
    return (char)(t.year%4);
    }
    
    


    Juz mi się nie chciało robić "wcięć" w kodzie ...

    Jakbyś miał trudności z plikiem Makefile to daj znać .
  • #3 2192294
    Radek_go
    Poziom 11  
    Posty: 13
    Dziekuje bardzo,
    Zaraz sie biore do testowania
    Pozdrawiam

    Dodano po 42 [minuty]:

    Skompilowal bez problemow, teraz musze troche sie pobawic w przerobki do mojego kitu.
    Jeszcze raz dzieki.
REKLAMA