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

📄 drivers.c

📁 嵌入式系统中的完整FAT16和FAT32源码
💻 C
字号:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//					    FAT32 File IO Library for AVR 
//								  V0.1c
// 	  							Rob Riglar
//							Copyright 2003,2004 
//
//   					  Email: rob@robriglar.com
//
//			    Compiled with Imagecraft C Compiler for the AVR series
//-----------------------------------------------------------------------------
//
// This file is part of FAT32 File IO Library.
//
// FAT32 File IO Library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// FAT32 File IO Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FAT32 File IO Library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
typedef unsigned char   UI8;
typedef unsigned char   byte;
typedef signed char     SI8;
typedef unsigned int    UI16;
typedef unsigned int    word;
typedef signed int      SI16;
typedef unsigned long   UI32;


//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
void InitUART( unsigned char baudrate );
unsigned char ReceiveByte( void );
void putchar( unsigned char data );
int getchar(void); 
void DisplayTag(void);
 
//-----------------------------------------------------------------------------
// Definitions
//-----------------------------------------------------------------------------

#define  UBR   (*(volatile unsigned char *)0x99)
#define  UCR   (*(volatile unsigned char *)0x9A)
#define  USR   (*(volatile unsigned char *)0x9B)
#define  UDR     (*(volatile unsigned char *)0x9C)

//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
void InitUART( unsigned char baudrate )
	{
	UBR = baudrate; /* set the baud rate */
	UCR = BIT(RXCIE1) | BIT(RXEN1) | BIT(TXEN1); /* enable UART receiver and transmitter */
	}

//-----------------------------------------------------------------------------
// ReceiveByte: Polled Recieved byte UART function
//-----------------------------------------------------------------------------
unsigned char ReceiveByte( void )
	{
	while ( !(USR & (1<<RXC1)) ) /* wait for incomming data */
		; /* return the data */
	return UDR;
	}

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
void putchar( unsigned char data )
	{
	while ( !(USR & (1<<UDRE1)) )
		; /* wait for empty transmit buffer */
	UDR = data; /* start transmittion */
	}
	
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
int getchar(void)
	{
	while ( !(USR & (1<<RXC1)) ) /* wait for incomming data */
		; /* return the data */
	return UDR;
	}
	 		 
//-----------------------------------------------------------------------------
// Delay millisecond Function
//  This function uses Timer 3 and the A compare registers
//  to produce millisecond delays.
//  Clock = 14.746MHz
//----------------------------------------------------------------------------
void delay_ms(unsigned int delay)
{
 unsigned int i;
 OCR3AH = 0x39;
 OCR3AL = 0x9A;          
 TCCR3B = 0x00;          // Stop Timer3
 for(i=0;i<delay;++i)
 {
 TCCR3B = 0x00;          // Stop Timer3
 TCNT3H = 0x00;          // Clear Timer3
 TCNT3L = 0x00;          
 TCCR3B = 0x09;          // Start Timer3 with clk/1
 while(!(ETIFR & 0x10));
 ETIFR |= 0x10;
 }
}
//-----------------------------------------------------------------------------
// Delay microsecond Function
//  This function uses Timer 3 and the A compare registers
//  to produce microsecond delays.
//   
//-----------------------------------------------------------------------------
void delay_us(unsigned int delay)
{
 unsigned int i;
 OCR3AH = 0x00;
 OCR3AL = 0x0E;     
 TCCR3B = 0x00;          // Stop Timer3
 for(i=0;i<delay;++i)
 {
 TCCR3B = 0x00;          // Stop Timer3
 TCNT3H = 0x00;          // Clear Timer3
 TCNT3L = 0x00;          
 TCCR3B = 0x09;          // Start Timer3 with clk/1
 while(!(ETIFR & 0x10));
 ETIFR |= 0x10;
 }
}


void DisplayTag(void)
{
printf(" ------------------------------------------------\r\n");
printf("|                                                |\r\n");
printf("|         Embedded Disc Reader System            |\r\n");
printf("|                     V0.1                       |\r\n");
printf("|                                                |\r\n");
printf("|                                                |\r\n");
printf("|                (c) R. Riglar                   |\r\n");
printf("|                                                |\r\n");
printf("|          http:\\\\www.robs-projects.com          |\r\n");
printf("|                                                |\r\n");
printf("|                                                |\r\n");
printf(" ------------------------------------------------\r\n");
printf("\r\n Starting System...\r\n");
}

⌨️ 快捷键说明

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