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

📄 test-1.c~

📁 This fat 16 can be used for logging function. The user can use it for logger device.
💻 C~
📖 第 1 页 / 共 5 页
字号:
    flash int8 FOpenErrStr[] = "\r\nFOPEN Error!!!";
#endif


/*****************************************************************************
**
** 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 */
// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: On
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud rate: 115200
UCSR0A=0x00;
UCSR0B=0xD8;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x03;




/****************************************************************************
**
** Initializes UART0
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void uart1_init(void)
{

// USART1 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART1 Receiver: On
// USART1 Transmitter: On
// USART1 Mode: Asynchronous
// USART1 Baud rate: 115200
UCSR1A=0x00;
UCSR1B=0xD8;
UCSR1C=0x06;
UBRR1H=0x00;
UBRR1L=0x03;


}


/****************************************************************************
**
** 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 */
}


/****************************************************************************
**
** Displays the root commands using the _FF_putc() function
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void display_demo_commands(void)
{
    _FF_printf(TestCmd0Str);
    _FF_printf(TestCmd1Str);
    _FF_printf(TestCmd2Str);
    _FF_printf(TestCmd3Str);
    _FF_printf(TestCmd4Str);
    _FF_printf(TestCmd5Str);
    _FF_printf(TestCmd6Str);
    #ifndef _READ_ONLY_
        _FF_printf(TestCmd7Str);
        _FF_printf(TestCmd8Str);
        #ifdef _DIRECTORIES_SUPPORTED_
            _FF_printf(TestCmd9Str);
        #endif
        #ifdef _SD_BLOCK_WRITE_
            _FF_printf(TestCmd10Str);
        #endif
    #endif
    #ifdef _RTC_ON_
        _FF_printf(TimeDateStr);
    #endif
    _FF_printf(_FF_CRLFStr);
}

/****************************************************************************
**
** Displays the File commands using the _FF_putc() function
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void display_file_commands(void)
{
    _FF_printf(OpenFile0Str);
    _FF_printf(OpenFile1Str);
    _FF_printf(OpenFile2Str);
    _FF_printf(OpenFile3Str);
    _FF_printf(OpenFile4Str);
    _FF_printf(OpenFile5Str);
    _FF_printf(OpenFile6Str);
}
                                
/****************************************************************************
**
** Flushes the receive buffer for UART0
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void flush_receive(void)
{
    while(rx_counter0)
        _FF_getchar();
}                          
                          

/****************************************************************************
**
** Gets a ASCII input stream from UART0 and places it into a null terminated 
** string
**
** Parameters:  *input_str, pointer to where the data will be stored
**              max_size, the maximum number of characters to get
**
** Returns: Number of characters put into the buffer
**          0 - An error occurred
**
****************************************************************************/
int16 get_input_str(int8 *input_str, int16 max_size)
{
    int16 i;
    int8 c;           

    for(i = 0; i < max_size; )
    {
        c = _FF_getchar();
        if((c == '\n') || (c == '\r'))
        {
            /* its a Line Feed */
            *input_str = '\0';        /* null terminate the string and */ 
            return(i);                /* return the length */
        }                            
        else if(c == 8)               /* backspace */
        {
            if(i > 0) 
            {
                _FF_putchar(c);
                _FF_putchar(' ');
                _FF_putchar(c);
                input_str--;
                *input_str = '\0';
                i--;
            }
        }       
        else if(c == 0x1B)            /* ESC */
        {            
            *input_str = '\0';        /* null terminate the string */
            return(0);                /* flag escape with 0 lenght */
        }
        else
        {
            _FF_putchar(c);
            *input_str = c;
            input_str++;
            i++;                      /* only increment on valid entries! */
        }
    }        
    *input_str = '\0';    /* null terminate */
    return(i);
}


#ifdef _RTC_ON_
/****************************************************************************
**
** Sets the time/date for the RTC based on the input string from UART0,
** "mm/dd/yyyy hh:mm:ss"
**
** Parameters:  None
**
** Returns: None
**
****************************************************************************/
void set_date_time(void)
{
    int8 myinstr[25];
    int8 *next_str;
    uint16 input_vals[6];
    uint8 c;
    int8 d_str[3], semi_str[4];

    d_str[0] = '%';
    d_str[1] = 'd';
    d_str[2] = 0;
    semi_str[0] = '/';
    semi_str[1] = ':';
    semi_str[2] = ' ';
    semi_str[3] = 0;

    _FF_printf(CRLF_SENDDATE);
    if(get_input_str(myinstr,20) == 0)
        return;         
    next_str = myinstr;
    for(c = 0;((c < 6) && (strlen(next_str) != 0)); c++)                         
    {
        #ifdef _CVAVR_
            sscanf(next_str,"%d",&(input_vals[c]));
            /* find next delimiter */
            next_str = strpbrkf(next_str,"/: ");
        #else        
            sscanf(next_str, d_str,&(input_vals[c]));
            /* find next delimiter */
            next_str = strpbrk(next_str, semi_str);
        #endif
        /* if not null, move past delimiter */
        if(next_str != '\0')
            next_str++;
    }
    rtc_set_time(input_vals[3], input_vals[4], input_vals[5]);
    rtc_set_date(input_vals[1],input_vals[0],input_vals[2]);  
    rtc_get_timeNdate(&RTCHour, &RTCMin, &RTCSec, &RTCDay, &RTCMonth, &RTCYear);
    _FF_printf(CRLF_DateInsert, RTCMonth,RTCDay,RTCYear,RTCHour,RTCMin,RTCSec);
}
#endif


/****************************************************************************
**
** Displays "Error" or "Ok" the UART0 based on the input result and the 
** compare value
**
** Parameters:  result, Input value to compare
**              error_flag, flag to see if _FF_error is printed also
**              bad_compare_value, Input value to compare to
**
** Returns: None
**
****************************************************************************/
void print_result(int16 result,int8 error_flag,int16 bad_compare_value)
{                 
    if(result != bad_compare_value)
        _FF_printf(CRLF_OK);
    else
    {
        _FF_printf(CRLF_ERROR);         
        if(error_flag == 1)
             _FF_printf(DASH_X, _FF_error);
    }
}


/****************************************************************************
**
** Translates ASCII characters input from UART0 into a valid address
**
** Parameters:  addr_size, Size in bytes of address to get from the UART
**
** Returns: The address
**          0xFFFFFFFF, and error occurred 
**
****************************************************************************/
uint32 get_addr_entry(uint8 addr_size)
{                
    uint8 test_char;
    uint32 addr_sd;
    uint16 n;
    

⌨️ 快捷键说明

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