⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo.c

📁 This fat 16 can be used for logging function. The user can use it for logger device.
💻 C
📖 第 1 页 / 共 2 页
字号:
** EXPORTED FUNCTIONS 
**
*****************************************************************************/
/*****************************************************************************
**
** LOCAL FUNCTIONS 
**
*****************************************************************************/

#if defined(_ICCAVR_)
/****************************************************************************
**
** Putchar function needed for ICC
**
** Parameters: send_char, character to send
**
** Returns: Sent character
**
****************************************************************************/
int16 putchar(int8 send_char)
{
    while (!(UCSR0A & 0x20))
        ;               /* wait xmit ready */
    UDR0 = (uint8) send_char;
    return(send_char);
}
#endif


/****************************************************************************
**
** Initializes the port and ddr settings 
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void port_init(void)
{
    PORTA = 0xFF;        DDRA  = 0x00;
    PORTB = 0xFF;        DDRB  = 0x00;
    PORTC = 0xFF;        DDRC  = 0x00;      /* m103 output only */
    PORTD = 0xFF;        DDRD  = 0x00;
    #ifndef _MEGAAVRDEV_
        PORTE = 0xFF;        DDRE  = 0x00;
        PORTF = 0xFF;        DDRF  = 0x00;
        PORTG = 0x1F;        DDRG  = 0x00;
    #endif
}


/****************************************************************************
**
** Initializes UART0
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void uart0_init(void)
{
    /* UART0 initialisation */
    /* desired baud rate: 115200 */
    /* actual baud rate: 115200 (0.0%) */
    /* char size: 8 bit */
    /* parity: Disabled */
    UCSR0B = 0x00;      /* disable while setting baud rate */
    UCSR0A = 0x00;
    UCSR0C = 0x06;
    UBRR0L = 0x07;      /* set baud rate lo */
    UBRR0H = 0x00;      /* set baud rate hi */
    UCSR0B = 0x18;
}


/****************************************************************************
**
** Initializes UART0
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void uart1_init(void)
{
    /* UART1 initialisation */
    /* desired baud rate: 115200 */
    /* actual baud rate: 115200 (0.0%) */
    /* char size: 8 bit */
    /* parity: Disabled */
    UCSR1B = 0x00; /* disable while setting baud rate */
    UCSR1A = 0x00;
    UCSR1C = 0x06;
    UBRR1L = 0x07; /* set baud rate lo */
    UBRR1H = 0x00; /* set baud rate hi */
    UCSR1B = 0x18;
}


/****************************************************************************
**
** Initialise all peripherals
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void init_devices(void)
{
    /* stop errant interrupts until set up */
    _FF_CLI();      /* disable all interrupts */
    XDIV  = 0x00;   /* xtal divider */
    XMCRA = 0x00;   /* external memory */
    port_init();
    uart0_init();
    uart1_init();

    MCUCR = 0x00;
    EICRA = 0x00;   /* extended ext ints */
    EICRB = 0x00;   /* extended ext ints */
    EIMSK = 0x00;
    TIMSK = 0x00;   /* timer interrupt sources */
    ETIMSK = 0x00;  /* extended timer interrupt sources */
    _FF_SEI();      /* re-enable interrupts */

    /* all peripherals are now initialised */
}


/****************************************************************************
**
** Main Function
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void main(void)
{
    FILE *pntr1;
    uint32 c, n;
        
    init_devices();

    #ifdef _RTC_ON_
        twi_setup();
    #endif

    while(initialize_media() == 0)
        ;
    
    /* Create File */
    pntr1 = fcreatec(_FF_FNAME, 0);
    n = 0;
    while(pntr1 == 0)
    {
        if(pntr1 == 0)
        {
            _FF_printf(Fail_str, _FF_error);
            n++;
            if(n & 0xF0)
                return;
        }
        pntr1 = fcreatec(_FF_FNAME, 0);
    }
    
    fputc('\"', pntr1);
    fprintf(pntr1, _FF_FNAME);
    fputc('\"', pntr1);
    fputc('\r', pntr1);
    fputc('\n', pntr1);
    /* Write to file */
    #ifdef _RTC_ON_
        /* if real time clock enabled, get and print time and date to file */
        rtc_get_timeNdate(&RTCHour, &RTCMin, &RTCSec, &RTCDay, &RTCMonth, &RTCYear);
        fprintf(pntr1, C2DStr, '\"', RTCMonth);
        fprintf(pntr1, p2DSlashStr, RTCDay);
        fprintf(pntr1, p4DStr, RTCYear);
        fprintf(pntr1, p2DColinStr, RTCHour);
        fprintf(pntr1, p2DColinStr, RTCMin);
        fprintf(pntr1, p2DCRLFStr, RTCSec, '\"');
    #endif
    
    for(c = 0; c < 10; c++)
        fprintf(pntr1, column_d, c);
    fprintf(pntr1, _FF_CRLFStr);
    
    for(c = 0; c < 100; c++)
    {
        /* print numbers separated by commas */
        for(n = 0; n < 10; n++)
            fprintf(pntr1, ld_str, (((uint32) c * 10) + n));
        if(fputc('\r', pntr1) == EOF)
            break;            /* line feed/carriage return */
        if(fputc('\n', pntr1) == EOF)
            break;            /* line feed/carriage return */
        PORTB ^= 0x40;
        PORTB ^= 0x80;
    }

    fclose(pntr1);
    _FF_printf(done_str);

    PORTB &= 0xBF;    /* Keep LED on when done */
    while(1)
    {
        /* Blink LED when done */
        PORTB ^= 0x80;
        for(c = 0; c < 100000; c++)
            ;
    };

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -