📄 ap-main.c
字号:
//****************************************************************************************
//****************************************************************************************
// Project Name: MMC / SD MEMORY CARD FAT16 & FAT 32 DRIVER
// PIC18 SAMPLE PROJECT C CODE FILE
// Copyright: EMBEDDED-CODE.COM
//
// Licenced To: NONE
// Licence Number: NONE
//
// IMPORTANT: These files are copyright of embedded-code.com and are subject to a licence
// agreement. All rights reserved. Unauthorised use, reproduction or distribution of
// these files may lead to prosecution.
// Any use in violation of the licence restrictions may subject the user to criminal
// sanctions under applicable laws, as well as to civil liability for the breach of the
// terms and conditions of the license.
// This software is provided in an "as is" condition. No warranties, whether express,
// implied or statutory, including, but not limited to, implied warranties of
// merchantability and fitness for a particular purpose apply to this software.
// Embedded-code.com shall not be liable in any circumstances for special, incidental
// or consequential damages, for any reason whatsoever.
// Please see 'www.embedded-code.com\licence' or email 'licence@embedded-code.com' for
// full details.
// This file contains hidden markers to identify it uniquely to the licence number it was
// purchased under.
// DO NOT REMOVE THIS NOTICE - IT IS A REQUIREMENT OF THE LICENCE AGREEMENT.
//****************************************************************************************
//****************************************************************************************
//----- INCLUDE FILES FOR THIS SOURCE CODE FILE -----
######## "####.#" //(Include the project global defines file)
####### ###### //(Define used for following header file to flag that it is the header file for this source file)
######## "#######.#" //(Include header file for this source file)
//----- OTHER PROJECT FILES REQUIRED BY THIS SOURCE CODE FILE -----
######## "#######.#"
//----- COMPILER LIBRARY FILES REQUIRED BY THIS SOURCE CODE FILE -----
######## <#####.#> //(Needed for printf)
//#include <stdlib.h>
######## <#####.#>
######## <######.#> //Used in the example project code
//******************************************
//******************************************
//********** DEVICE CONFIGURATION **********
//******************************************
//******************************************
//These configuration defines do not need to be included, but having them means that the configuration bits will be automatically set and will be included in the .hex
//file created for the project, so that they do not need to be manually set when programming devices at manufacture.
//(The config names are given in the '.inc' file for the device being used)
###### ###################
//DEVELOPMENT MODE
####### ###### #### = ### //Osciallator Switching
####### ###### ### = ##### //Ocsillator type
####### ###### ### = ## //Brown out reset
####### ###### #### = ### //Powerup timer (Need to start ASAP to turn on power relay)
###### ###############
####### ###### #### = ## //Brown out reset voltage
#####
####### ###### #### = ## //Brown out reset voltage
######
####### ###### ### = ### //Watchdog timer
####### ###### ##### = ### //Watchdog prescaller
####### ###### ####### = ### //CCP2 pin
####### ###### ##### = ## //Debugger
####### ###### ### = ### //Low voltage program
####### ###### #### = ## //Stack overflow reset
####### ###### ### = ### //Code protect block
####### ###### ### = ### //Code protect block
####### ###### ### = ### //Code protect block
####### ###### ### = ### //Code protect block
####### ###### ### = ### //Code protect boot block
####### ###### ### = ### //Protect data eeprom
####### ###### #### = ### //Table write protect block
####### ###### #### = ### //Table write protect block
####### ###### #### = ### //Table write protect block
####### ###### #### = ### //Table write protect block
####### ###### #### = ### //Boot block write protect
####### ###### #### = ### //Config registers write protect
####### ###### #### = ### //Data eeprom write protect
####### ###### ##### = ### //Table read protect block
####### ###### ##### = ### //Table read protect block
####### ###### ##### = ### //Table read protect block
####### ###### ##### = ### //Table read protect block
####### ###### ##### = ### //Table read protect boot block
#####
//NOT IN DEVELOPMENT MODE
####### ###### #### = ### //Osciallator Switching
####### ###### ### = ##### //Ocsillator type
####### ###### ### = ## //Brown out reset
####### ###### #### = ### //Powerup timer (Need to start ASAP to turn on power relay)
###### ###############
####### ###### #### = ## //Brown out reset voltage
#####
####### ###### #### = ## //Brown out reset voltage
######
####### ###### ### = ## //Watchdog timer
####### ###### ##### = ### //Watchdog prescaller
####### ###### ####### = ### //CCP2 pin
####### ###### ##### = ### //Debugger
####### ###### ### = ### //Low voltage program
####### ###### #### = ## //Stack overflow reset
####### ###### ### = ### //Code protect block
####### ###### ### = ### //Code protect block
####### ###### ### = ### //Code protect block
####### ###### ### = ### //Code protect block
####### ###### ### = ### //Code protect boot block
####### ###### ### = ### //Protect data eeprom
####### ###### #### = ### //Table write protect block
####### ###### #### = ### //Table write protect block
####### ###### #### = ### //Table write protect block
####### ###### #### = ### //Table write protect block
####### ###### #### = ### //Boot block write protect
####### ###### #### = ### //Config registers write protect
####### ###### #### = ### //Data eeprom write protect
####### ###### ##### = ### //Table read protect block
####### ###### ##### = ### //Table read protect block
####### ###### ##### = ### //Table read protect block
####### ###### ##### = ### //Table read protect block
####### ###### ##### = ### //Table read protect boot block
######
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//********************************
//********************************
//********** INITIALISE **********
//********************************
//********************************
void initialise (void)
{
######();
//-------------------------
//----- SETUP IO PINS -----
//-------------------------
//(Device will powerup with all IO pins as inputs)
//Setup the state of any pins that are outputs (inputs are don't care)
#### = ##########;
#### = ##########;
#### = ##########; //FFS_CE, FFS_WE & FFS_OE all high
#### = ##########;
#### = ##########;
######## = #;
######## = #;
//Setup the IO pin type (0 = output, 1 = input)
########.##### = #;
##### = ##########;
##### = ##########;
##### = ##########;
##### = ##########;
##### = ##########;
//Setup internal pull ups
###########.#### = #; //Port B pull ups (0 = on)
//----- SETUP THE A TO D PINS -----
###### = ##########;
###### = ##########; //All AtoD pins are digital
//----------------------------
//----- SETUP INTERRUPTS -----
//----------------------------
//------------------------
//----- SETUP TIMERS -----
//------------------------
//(INCLUDE THE USAGE OF ALL TIMERS HERE EVEN IF NOT SETUP HERE SO THIS IS THE ONE POINT OF
//REFERENCE TO KNOW WHICH TIMERS ARE IN USE AND FOR WHAT).
//----- SETUP TIMER 0 -----
//Used for: Heartbeat
#########.###### = #; //Configured as a 16bit timer
#########.#### = #; //Use internal instruction clock
#########.#### = #;
#########.### = #; //Prescaller is in use (0 = in use)
#########.##### = #; //Prescaler 1:2
#########.##### = #;
#########.##### = #;
#########.###### = #; //Timer 0 on
##########.###### = #; //Enable the Timer 0 irq
//----- SETUP TIMER 1 -----
//Used for: Available
/*
T1CONbits.RD16 = 1; //R/W 16bits in 1 operation
T1CONbits.T1RUN = 0; //Don't use timer 1 dedicated oscillator
T1CONbits.T1OSCEN = 0; //Timer 1 dedicated oscillator disabled
T1CONbits.T1CKPS1 = 0; //1:1 prescale
T1CONbits.T1CKPS0 = 0;
T1CONbits.T1SYNC = 0;
T1CONbits.TMR1CS = 0; //Use internal instruction clock
T1CONbits.TMR1ON = 1; //Enable timer 1
*/
//----- SETUP TIMER 2 -----
//Used for: Available
/*
T2CONbits.T2OUTPS3 = 0; //1:1 postscale
T2CONbits.T2OUTPS2 = 0;
T2CONbits.T2OUTPS1 = 0;
T2CONbits.T2OUTPS0 = 0;
T2CONbits.T2CKPS1 = 1; //1:16 prescale
T2CONbits.T2CKPS0 = 0;
T2CONbits.TMR2ON = 1; //Enable timer 2
*/
//----- SETUP TIMER 3 -----
//Used for: Available
/*
T3CONbits.RD16 = 1; // R/W 16bits in 1 operation
T3CONbits.T3CCP2 = 0; // R/W 16bits in 1 operation
T3CONbits.T3CCP1 = 0;
T3CONbits.T3CKPS1 = 0; //1:1 prescale
T3CONbits.T3CKPS0 = 0;
T3CONbits.T3SYNC = 0;
T3CONbits.TMR3CS = 0; //Use internal instruction clock
T3CONbits.TMR3ON = 1; //Enable timer 3
*/
//-----------------------------------------------
//----- SETUP SYNCHRONOUS SERIAL PORT (SSP) -----
//-----------------------------------------------
//SETUP SPI BUS
###########.### = #;
###########.### = #; //Data is valid on the rising edge of the clock
###########.### = #; //Clock low in idle bus state
###########.##### = #; //Clock frequency = Fosc / 4
###########.##### = #;
###########.##### = #;
###########.##### = #;
###########.##### = #; //Enable SSP Port
//-----------------------
//----- SETUP USART -----
//-----------------------
//Setup to use for debug 'printf' output
//SETUP BAUD RATE
#########.#### = #; //Low speed mode
##### = (####)((########################### << #) / (## * (#### + #))); // OSCILLATOR_FREQUENCY / (64 * (DESIRED BAUD + 1)
//SETUP TX
#########.### = #; //8 bit tx
#########.#### = #; //Transmit enabled
#########.#### = #; //Asynchronous mode
//SETUP RX
#########.### = #; //8 bit rx
#########.##### = #; //Address detect disabled
#########.#### = #; //Enable receiver
#########.#### = #; //Serial port enabled
//------------------------
//----- USING PRINTF -----
//------------------------
//If using C18 and the compiler small memory model (devices <= 64K of program memory) you can use '(rom far char*)' to stop a build warning
//being generated, otherwise omit the (rom far char*)
//Example displaying just text:-
//printf ((rom far char*)"\n----- POWER-UP ----- \n\r");
//Example displaying a value:-
//temp_value = 199;
//itoa((int) temp_value, temp_string);
//printf ((rom far char*)"%s\n\r", temp_string);
//Example of getting terminal input:-
//printf ((rom far char*)"\nEnter 5 digit value\n\r");
//getsUSART((char*)temp_string,5);
//temp_string[5] = 0x00;
//printf ((rom far char*)"You typed: %s\n\r", temp_string);
//-----------------------------
//----- ENABLE INTERRUPTS -----
//-----------------------------
##########.#### = #; // enable lo priority interrupts
##########.#### = #; // enable hi priority interrupts
}
//**********************************************************************************************************************************************
//**********************************************************************************************************************************************
//**********************************************************************************************************************************************
//**********************************************************************************************************************************************
//**********************************************************************************************************************************************
//**********************************************************************************************************************************************
//**********************************************************************************************************************************************
//***********************************
//***********************************
//********** MAIN FUNCTION **********
//***********************************
//***********************************
void main ( void )
{
//**********************
//**********************
//***** INITIALISE *****
//**********************
//**********************
##########();
//*********************
//*********************
//***** MAIN LOOP *****
//*********************
//*********************
#####(#) //(Do forever)
{
//----- RESET THE WATCHDOG TIMEOUT TIMER -----
######();
//----- READ SWITCHES -----
#############();
//----- PROCESS MODE -----
############();
//----- PROCESS FAT FILING SYSTEM -----
###########();
}
}
//***********************************
//***********************************
//********** READ SWITCHES **********
//***********************************
//***********************************
void read_switches (void)
{
#### #############;
#### #####################;
###### #### ############# = #;
###### #### ####################### = #;
//RESET THE NEW SWITCH PRESS REGISTER
############ = #;
//ONLY DO EVERY 10MS FOR DEBOUNCE
## (################## == #)
######;
################## = #;
//GET THE SWITCH INPUTS
############# = ~(##### | ####);
//DEBOUNCE
################## = ############# & #############;
//FLAG NEW BUTTON PRESSES
############ = ################## ^ #######################;
############ &= ##################;
//STORE LAST REGISTERS FOR NEXT TIME
####################### = ##################;
############# = #############;
}
const char filename_all[] = {"*.*"};
const char filename_test_txt[] = {"test.txt"};
const char filename_test_csv[] = {"test.csv"};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -