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

📄 cfmain.c

📁 MMC interface and FAT File system
💻 C
字号:
//###################################################################################
// File: cfmain.c
//
//
//#########################################################################
// Last change: 03.05.2003
//#########################################################################
// holger.klabunde@t-online.de
// http://home.t-online.de/home/holger.klabunde/homepage.htm
//#########################################################################
// Processor: ATMega32
//#########################################################################
// Compiler: AVR-GCC 3.2
//#########################################################################

#include <io.h>
#include <interrupt.h>
#include <sig-avr.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>

#include "mydefs.h"
#include "protos.h"
#include "serial.h"
#include "lcd.h"
#include "dos.h"
#include "commands.h"

unsigned char bmode; //send sectors binary 0=off
unsigned char echo; //echo back serial input 0=off

char line[40];     //Zeichenpuffer

//"volatile" f黵 alle Variablen die in Interrupt's ge鋘dert werden
unsigned int volatile overflow;

/*
//###################################################################################
SIGNAL(SIG_OVERFLOW1)        // signal handler for timer1 overflow interrupt
//###################################################################################
{
 if(overflow>0) overflow--;
}
*/

//###################################################################################
/* Hauptprogramm */
int main(void)
//###################################################################################
{
 unsigned char c;

 DDRC=0xFF;  	// set io-pins on PortC
 PORTC=0; 	//LCD-Datenbus

 DDRD=0xF2;  	// set io-pins on PortD
 PORTD=0x02; 	//LCD-Steuersignale siehe lcd.h

 DDRA=0; 	//Alles Eing鋘ge
 PORTA=0xFF; 	//Eing鋘ge mit Pullups setzen

 DDRB=0xFF; 	//Alles Ausg鋘ge
 PORTB=0xFF; 	

 SFIOR&=!(1<<PUD); 	//Pullups Enable
// SFIOR=0; 	//Pullups Enable

 LCDInit();
 ser_init();

//Timer1
/*
 TCCR1A=0; 
 TCCR1B=0x02;        //Timer1 Start Takt = F/8 => 65ms at 8MHz
 TIMSK=(1<<TOIE1);   // enable timer1 int
*/
 sei();              //enable interrupts

 LCDCls();
 LCDWrite("CompactFlash Test1");
 puts("CompactFlash Test1\n");
 LCDPos(2,1);
 LCDWrite("by Holgi");
 Delay1ms(1000);

 if(GetDriveInformation()!=F_OK) // get drive parameters
  {
   LCDCls();
   printf("\nCF meldet sich nicht !\n");
   while(1);
  }
  
 InitDOS();             // reset DOS
 
 HelpScreen();
 puts("\n>");
 echo=1;
 bmode=0;

 for(;;)
  {
   c=WaitCommand();
   switch(c)
    {
     case HELP: HelpScreen(); break;
     case ROOT:
                if(FATtype!=FAT32)
                 { 
                  ScanRootDir(NULL);
                  CurrentDirCluster=0;
                 }
                else
                 {
                  CurrentDirCluster=FAT32RootCluster;
                  ScanSubDir(CurrentDirCluster,NULL);
                 } 
      break;
     case LIST_DIR: if(CurrentDirCluster==0) ScanRootDir(NULL);
                    else ScanSubDir(CurrentDirCluster,NULL);
      break;
     case INFO: GetDriveInformation();
                if(FATtype!=FAT32) CurrentDirCluster=0; //root directory
                else CurrentDirCluster=FAT32RootCluster;
                CurrentSector=0;
                CurrentCluster=2;
      break;
     case DUMP_SECTOR: CFReadSector(CurrentSector,inbuff);
                       DumpSector(inbuff);    
                       if(echo) printf("\nCurrent Sector %lu\n",CurrentSector);
      break; 
     case CLUSTER_TO_SECTOR:
                       if(echo) printf("\nCurrent Cluster %lu Sector %lu\n",CurrentCluster,CurrentSector);
      break; 
    }

   if(echo) puts("\n");
    
  }
}

//###################################################################################
//Nicht sonderlich genau !!
void Delay1ms(unsigned int time)
//###################################################################################
{
 unsigned int i;

 for(i=0; i<time; i++) Delay100us(10);
}

//###################################################################################
//Nicht sonderlich genau !!
//time<=255 !!
void Delay100us(unsigned char time)
//###################################################################################
{
 unsigned char k,l;

 for(k=0; k<time; k++)
  {
   for(l=0; l<40; l++)
    {
     //Ein CPU-Clock = 0.125us bei 8MHz
     NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();  
     NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();  
    }
  }
}

⌨️ 快捷键说明

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