📄 main.i
字号:
typedef DWORD CLUST;
typedef DWORD CLUST;
typedef DWORD CLUST;
/* File system object structure */
typedef struct _FATFS {
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector */
DWORD database; /* Data start sector */
CLUST sects_fat; /* Sectors per fat */
CLUST max_clust; /* Maximum cluster# + 1 */
CLUST last_clust; /* Last allocated cluster */
CLUST free_clust; /* Number of free clusters */
DWORD fsi_sector; /* fsinfo sector */
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
BYTE pad1;
BYTE fs_type; /* FAT sub type */
BYTE csize; /* Number of sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE win[512]; /* Disk access window for Directory/FAT/File */
} FATFS;
/* Directory object structure */
typedef struct _DIR {
WORD id; /* Owner file system mount ID */
WORD index; /* Current index */
FATFS* fs; /* Pointer to the owner file system object */
CLUST sclust; /* Start cluster */
CLUST clust; /* Current cluster */
DWORD sect; /* Current sector */
} DIR;
/* File object structure */
typedef struct _FIL {
WORD id; /* Owner file system mount ID */
BYTE flag; /* File status flags */
BYTE csect; /* Sector address in the cluster */
FATFS* fs; /* Pointer to owner file system */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
CLUST org_clust; /* File start cluster */
CLUST curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
} FIL;
/* File status structure */
typedef struct _FILINFO {
DWORD fsize; /* Size */
WORD fdate; /* Date */
WORD ftime; /* Time */
BYTE fattrib; /* Attribute */
char fname[8+1+3+1]; /* Name (8.3 format) */
} FILINFO;
/* File function return code (FRESULT) */
typedef enum {
FR_OK = 0, /* 0 */
FR_NOT_READY, /* 1 */
FR_NO_FILE, /* 2 */
FR_NO_PATH, /* 3 */
FR_INVALID_NAME, /* 4 */
FR_INVALID_DRIVE, /* 5 */
FR_DENIED, /* 6 */
FR_EXIST, /* 7 */
FR_RW_ERROR, /* 8 */
FR_WRITE_PROTECTED, /* 9 */
FR_NOT_ENABLED, /* 10 */
FR_NO_FILESYSTEM, /* 11 */
FR_INVALID_OBJECT, /* 12 */
FR_MKFS_ABORTED /* 13 (not used) */
} FRESULT;
/*-----------------------------------------------------*/
/* Tiny-FatFs module application interface */
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */
FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
FRESULT f_close (FIL*); /* Close an open file object */
FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
FRESULT f_stat (const char*, FILINFO*); /* Get file status */
FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
FRESULT f_truncate (FIL*); /* Truncate file */
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
FRESULT f_unlink (const char*); /* Delete an existing file or directory */
FRESULT f_mkdir (const char*); /* Create a new directory */
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */
FRESULT f_utime (const char*, const FILINFO*); /* Change file/dir timestamp */
FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */
FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */
/* User defined function to give a current time to fatfs module */
DWORD get_fattime (void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
/* File access control and file status flags (FIL.flag) */
/* FAT sub type (FATFS.fs_type) */
/* File attribute bits for directory entry */
/* Offset of FAT structure members */
/* Multi-byte word access macros */
//******************************************************************
//* Definitions
//******************************************************************
//#define XRES PORTC.4
//#define VS_SO PINC.0
// VS1011 commands
// VS1011 registers
// Bit definition Mode Register
// Bit definition Status Register
// Mask definition Bass Enhancer Register
// Mask and bit definitions for Stream Header data Register
//#define VS1033_XTAL 12288000
//******************************************************************
//* FUNCTION PROTOTYPES
//******************************************************************
void vs_init(unsigned char HardReset);
void vs_init(unsigned char HardReset);
void vs_setvolume(unsigned char volume);
void vs_stream(unsigned char *Data,unsigned char Qte);
void vs_write(unsigned char addr, unsigned int data);
void Sine_On(unsigned char Freq);
void Sine_Off(void);
void vs_beep(void);
unsigned char WriteByte(unsigned char data);
/* Playback control code generated by G-sensor control task */
FATFS fatfs;
FIL file1;
eeprom unsigned char vol_ee=5;
void putchar(char c)
{
while (!((*(unsigned char *) 0x9b) & 0x20));
(*(unsigned char *) 0x9c)=c;
}
unsigned char getchar(void)
{
while (!((*(unsigned char *) 0x9b) & 0x80));
return (*(unsigned char *) 0x9c);
}
void init()
{
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0xFF;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=Out Func3=In Func2=Out Func1=Out Func0=Out
// State7=T State6=T State5=T State4=0 State3=P State2=1 State1=0 State0=1
PORTB=0x01011101;
DDRB=0b01000111;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0xFF;
DDRC=0xDE;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0b01111111;
DDRD=0b11101110;
// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTE=0xFF;
DDRE=0x00;
// Port F initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
(*(unsigned char *) 0x62)=0xFF;
(*(unsigned char *) 0x61)=0x00;
// Port G initialization
// Func4=In Func3=In Func2=In Func1=In Func0=In
// State4=T State3=T State2=T State1=T State0=T
(*(unsigned char *) 0x65)=0x00;
(*(unsigned char *) 0x64)=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
(*(unsigned char *) 0x79)=0x00;
(*(unsigned char *) 0x78)=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer 3 Stopped
// Mode: Normal top=FFFFh
// Noise Canceler: Off
// Input Capture on Falling Edge
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Timer 3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
(*(unsigned char *) 0x8b)=0x00;
(*(unsigned char *) 0x8a)=0x00;
(*(unsigned char *) 0x89)=0x00;
(*(unsigned char *) 0x88)=0x00;
(*(unsigned char *) 0x81)=0x00;
(*(unsigned char *) 0x80)=0x00;
(*(unsigned char *) 0x87)=0x00;
(*(unsigned char *) 0x86)=0x00;
(*(unsigned char *) 0x85)=0x00;
(*(unsigned char *) 0x84)=0x00;
(*(unsigned char *) 0x83)=0x00;
(*(unsigned char *) 0x82)=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
(*(unsigned char *) 0x6a)=0x00;
EICRB=0x00;
EIMSK=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
(*(unsigned char *) 0x7d)=0x00;
// USART1 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART1 Receiver: On
// USART1 Transmitter: On
// USART1 Mode: Asynchronous
// USART1 Baud Rate: 38400
(*(unsigned char *) 0x9b)=0x00;
(*(unsigned char *) 0x9a)=0x18;
(*(unsigned char *) 0x9d)=0x06;
(*(unsigned char *) 0x98)=0x00;
(*(unsigned char *) 0x99)=0x13;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 2*4000,000 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x50;
SPSR=0x01;
}
static
UINT out_stream ( /* Number of bytes sent or stream status */
const BYTE *p, /* Pointer to the data block to be sent */
UINT btf /* >0: Number of bytes to be sent. 0: Sense stream status */
)
{
UINT cnt = btf;
if (cnt == 0) /* Return stream status (0: not ready, 1: ready)*/
return PINC.5 ? 1 : 0; /* If once it returned 1 to sense call, it must accept a byte at least */
/* at subsequent transmission call, or f_forward will result FR_RW_ERROR. */
PORTC &= ~(1 << 6) ; /* Select decoder data port */
do {
WriteByte(*p++);
} while (--cnt && PINC.5); /* Repeat while there is a data to be sent and the decoder is demanding data */
PORTC |= (1 << 6) ; /* Deselect decoder data port */
return btf - cnt; /* Return number of bytes sent */
}
/*-----------------------------------------------------------------------*/
/* Sample code using f_forward function */
/*-----------------------------------------------------------------------*/
static
BYTE play_file (
char *fn /* Pointer to the audio file name to be played */
)
{
FRESULT rc;
FIL fil;
UINT dmy;
WORD voltime;
BYTE tempvol;
BYTE cmd;
tempvol = vol_ee;
voltime = 0;
voltime = 0;
cmd=0;
vs_init(0);
/* Open the audio file in read only mode */
rc = f_open(&fil, fn, 0x01);
printf("\r\n");
printf("Playing: %s\r\n", fn);
printf("SIZE: %9lu\r\n", fil.fsize);
/* Repeat until the file pointer reaches end of the file */
while (rc == FR_OK && fil.fptr < fil.fsize) {
/* any other processes... */
if (!(PIND.0))
{
while (!(PIND.0));
cmd=1;
break;
}
if (!(PINB.4))
{
while (!(PINB.4));
cmd=2;
break;
}
if (!(PINE.6))
{
while (!(PINE.6));
cmd=6;
break;
}
if (!(PINA.3))
{
while (!(PINA.3));
cmd=7;
break;
}
if (!(PIND & (1 << 4)))
{
while (!(PIND & (1 << 4)));
vs_beep();
PORTD &= ~(1 << 7) ;
}
if (!(PINA.6))
{
if (tempvol < 255)
{
if (voltime == 300)
{
voltime = 0;
tempvol ++;
vs_setvolume(tempvol);
vol_ee=tempvol;
} else {voltime++;}
}
}
if (!(PINA.4))
{
if (tempvol > 0)
{
if (voltime == 300)
{
voltime = 0;
tempvol --;
vs_setvolume(tempvol);
vol_ee=tempvol;
} else {voltime++;}
}
}
/* Fill output stream periodicaly or on-demand */
rc = f_forward(&fil, out_stream, 512, &dmy);
}
f_close(&fil); // 怦
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -