📄 mainfile.c
字号:
/*
The SD card base on FAT12/16 file system.
Jacky.L 2008.1
Only Support ATMEGA16 and ATMEGA32
SD card connected:
/--------------- -|
/ 1 2 3 4 5 6 7 8 |
/9 |
| |
| |
| |
| (bottom side) |
| |
| |
| |
| |
| |
|___________________|
1 --------------- SS(PB4)
2 ---|47 ohm |--- MOSI(PB5)
3 --------------- GND
4 --------------- VCC (3.3V)
5 ---|47 ohm |--- SCK(PB7)
6 --------------- GND
7 ---|47 ohm |--- MISO(PB6)
8 --- NC.
9 --- NC.
*/
// Fosc= 7.3MHz
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <string.h>
#include "sdfs.h"
#include "dataType.h"
FILINFO finfo;
FATFS fatfs; /* File system object for each logical drive */
static volatile
BYTE timeDelay;
/*---------------------------------------------------------*/
/* 100Hz timer interrupt generated by OC2 */
/*---------------------------------------------------------*/
ISR(TIMER2_COMP_vect)
{
if(timeDelay) timeDelay--;
disk_timerproc(); /* Drive timer procedure of low level disk I/O module */
}
/*---------------------------------------------------------*/
/* User Provided Timer Function for FatFs module */
/*---------------------------------------------------------*/
/* This is a real time clock service to be called from */
/* FatFs module. Any valid time must be returned even if */
/* the system does not support a real time clock. */
DWORD get_fattime ()
{
return ((2006UL-1980) << 25) // Year = 2006
| (2UL << 21) // Month = Feb
| (9UL << 16) // Day = 9
| (22U << 11) // Hour = 22
| (30U << 5) // Min = 30
| (0U >> 1) // Sec = 0
;
}
static
void IoInit ()
{
OCR2 = 90-1; // Timer2: 100Hz interval (OC2)
TCCR2 = 0b00001101;
TIMSK = 0b10000000; // Enable TC2.oc, TC0.oc interrupt
sei();
}
/*-----------------------------------------------------------------------*/
/* Main */
BYTE linebuf[15];
BYTE filebuf[128];
BYTE fileNamebuf[6];
void init_fileNamebuf(void)
{
fileNamebuf[0]='0';
fileNamebuf[1]='.';
fileNamebuf[2]='B';
fileNamebuf[3]='I';
fileNamebuf[4]='N';
fileNamebuf[5]='\0';
}
void sentdata(BYTE indata)
{
//add sent out function with the reading data on file.
//.........
//.........
//.........
//.........
}
int main ()
{
BYTE i,j;
UINT s2;
FATFS *fs;
DIR dir;
FIL file1;
IoInit();
init_fileNamebuf();
disk_initialize(0);
f_mount(0, &fatfs);
for(i=0;;i++,i%=4)
{
fileNamebuf[0]='1'+i;
f_open(&file1, fileNamebuf, FA_OPEN_EXISTING | FA_READ);
do
{
f_read(&file1, filebuf, 128, &s2);
for(j=0;j<s2;j++)
{
sentdata(filebuf[j]);
}
}while(s2);
timeDelay=250;
while(timeDelay);
timeDelay=250;
while(timeDelay);
f_close(&file1);
timeDelay=250;
while(timeDelay);
}
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -