?? demo.c
字號:
/*********************************************
Project : FlashFileSD Example
Version : 1.41
Date : 12/23/2003
Author : Erick M Higa
Company : Progressive Resources LLC
Comments:
This is a simple example program for the FlashFileSD
Chip type : ATmega128
Program type : Application
Clock frequency : 14.745600 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 1024
*********************************************/
#include <iom128.h>
#include "putchar.c"
#include "options.h"
void port_init(void)
{
PORTA = 0xFF; DDRA = 0x00;
PORTB = 0xFF; DDRB = 0xFF;
PORTC = 0xFF; DDRC = 0x00; //m103 output only
PORTD = 0xFF; DDRD = 0x00;
PORTE = 0xFF; DDRE = 0x00;
PORTF = 0xFF; DDRF = 0x00;
PORTG = 0x1F; DDRG = 0x00;
}
//UART0 initialisation
// desired baud rate: 115200
// actual: baud rate:115200 (0.0%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
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;
}
//UART1 initialisation
// desired baud rate:115200
// actual baud rate:115200 (0.0%)
// char size: 8 bit
// parity: Disabled
void uart1_init(void)
{
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;
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
asm("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
asm("sei"); //re-enable interrupts
//all peripherals are now initialised
}
// Declare your global variables here
extern uchar rtc_hour, rtc_min, rtc_sec;
extern uchar rtc_date, rtc_month;
extern uint rtc_year;
schar flash _FF_FNAME[] = "demo.dat";
schar flash ld_str[] = "%03ld, ";
schar flash done_str[] = "\r\n\r\nDONE!!!";
schar flash column_d[] = "Column %d, ";
schar flash Fail_str[] = "\r\nFAILED!!! - %02X";
schar flash __Quote = 0x22;
schar flash WORKING_FOLDER[] = "\\TESTFOLD";
schar flash StartDemoStr[] = "\r\nStarting the Demo!!!";
schar flash CreateFailedStr[] = "\r\n%c%s%c Creation FAILED!!!";
schar flash SDSStr[] = "%s%02d%s";
schar flash CSCStr[] = "%c%s%c\r\n";
schar flash CreatedStr[] = "\r\n%c%s%c Created";
schar flash EOFStr[] = "EOF\r\n";
schar flash C2DStr[] = "%c%02d/";
schar flash p2DSlashStr[] = "%02d/";
schar flash p4DStr[] = "%04d ";
schar flash p2DColinStr[] = "%02d:";
schar flash p2DCRLFStr[] = "%02d%c\r\n";
extern schar flash __CR;
extern schar flash __LF;
main()
{
FILE *pntr1;
ulong 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)
{
printf(Fail_str, _FF_error);
n++;
if (n & 0xF0)
return;
}
pntr1 = fcreatec(_FF_FNAME, 0);
}
fputc(__Quote, pntr1);
fprintf(pntr1, _FF_FNAME);
fputc(__Quote, pntr1);
fputc(__CR, pntr1);
fputc(__LF, pntr1);
// Write to file
#ifdef _RTC_ON_
// if real time clock enabled, get and print time and date to file
rtc_get_timeNdate(&rtc_hour, &rtc_min, &rtc_sec, &rtc_date, &rtc_month, &rtc_year);
fprintf(pntr1, C2DStr, __Quote, rtc_month);
fprintf(pntr1, p2DSlashStr, rtc_date);
fprintf(pntr1, p4DStr, rtc_year);
fprintf(pntr1, p2DColinStr, rtc_hour);
fprintf(pntr1, p2DColinStr, rtc_min);
fprintf(pntr1, p2DCRLFStr, rtc_sec, __Quote);
#endif
for(c=0; c<10; c++)
fprintf(pntr1, column_d, c);
fprintf(pntr1, __CRLF);
for (c=0; c<100; c++)
{ // print numbers separated by commas
for (n=0; n<10; n++)
fprintf(pntr1, ld_str, (((ulong)c*10)+n));
if (fputc(__CR, pntr1)==EOF)
break; // line feed/carriage return
if (fputc(__LF, pntr1)==EOF)
break; // line feed/carriage return
PORTB ^= 0x40;
PORTB ^= 0x80;
}
fclose(pntr1);
printf(done_str);
PORTB &= 0xBF; // Keep LED on when done
while (1)
{ // Blink LED when done
PORTB ^= 0x80;
for (c=0; c<100000; c++)
;
};
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -