📄 ap-main.c
字号:
const char read_access_mode[] = {"r"};
const char write_access_mode[] = {"w"};
const char append_access_mode[] = {"a"};
const char read_write_access_mode[] = {"r+"};
const char write_read_access_mode[] = {"w+"};
const char append_read_access_mode[] = {"a+"};
const char text_file_line1_string[] = {"THIS IS A SAMPLE FILE\r\n"}; //('\r' = carriage return, '\n' = line feed)
const char text_file_line2_string[] = {"Created by the embedded-code.com MMC / SD FAT driver\r\n"};
const char spreadsheet_file_no_text_file_string[] = {"The text.txt file could not be read!"};
//**********************************
//**********************************
//********** PROCESS MODE **********
//**********************************
//**********************************
//This is a simple example user mode state machine function.
//The current mode is selected using the switch inputs.
//Each of the 6 modes does a specific function with the LCD screen
void process_mode (void)
{
######## *##########;
######## *##########;
#### ######;
#### ###############[##];
### ######;
//------------------------------
//----- DO THE LED OUTPUTS -----
//------------------------------
//----- RED LED INDICATES THAT PCB IS POWERED -----
## (#########################)
{
//LED IS BEING FORCED OFF
######## = #;
}
####
{
//LED OPERATES AS NORMAL
######## = #;
}
//----- GREEN LED INDICATES THAT A MMC / SD CARD IS INSERTED AND IS READY FOR USE -----
## (#########################)
{
//LED IS BEING FORCED OFF
######## = #;
}
####
{
//LED OPERATES AS NORMAL
## (###########)
{
//Card is inserted and ready to use
######## = #;
}
####
{
//Card is not inserted
######## = #;
}
}
//--------------------------------------
//----- PROCESS ANY BUTTON PRESSES -----
//--------------------------------------
## (################## && ###########)
{
//------------------------------------
//----- LEFT EDGE BUTTON PRESSED -----
//------------------------------------
//ALL FILES IN THE ROOT DIRECTORY ARE DELETED, AND A NEW FILE CALLED TEST.TXT IS CREATED
//CONTAINING EXAMPLE TEST DATA. THE RED LED BLINKS TO CONFIRM THE OPERATION.
//----- DELETE ALL FILES IN THE ROOT DIRECTORY -----
##### (##########(############) == #)
;
//----- CREATE NEW FILE FOR WRITING -----
########## = #########(#################, #################);
## (########## != #)
{
//----- FILE WAS SUCESSFULLY CREATED -----
//----- WRITE STRING DATA -----
## (#########(######################, ##########) == #######)
#### #################; //Write error
//----- WRITE A DATA BLOCK -----
##########(######################, ######(####), (###)######(######################), ##########);
//----- WRITE INDIVIDUAL BYTES OF DATA -----
### (###### = '#'; ###### <= '#'; ######++)
{
## (#########((###)######, ##########) == #######)
#### #################; //Write error
}
//----- CLOSE THE FILE -----
## (##########(##########))
#### #################; //Error - could not close
//----- BLINK THE RED LED TO CONFIRM OPERATION -----
######################### = ##;
}
####
{
//----- ERROR - THE FILE COULD NOT BE CREATED -----
#### #################;
}
}
## (################## && ###########)
{
//---------------------------------
//----- MIDDLE BUTTON PRESSED -----
//---------------------------------
//A NEW SPREADSHEET FILE CALLED TEST.CSV IS CREATED CONTAINING TEST DATA FROM THE TEST.TXT FILE
//IF IT IS PRESENT ON THE MMC / SD CARD. THE GREEN LED BLINKS TO CONFIRM THE OPERATION.
//----- CREATE NEW FILE FOR WRITING -----
########## = #########(#################, #################);
## (########## != #)
{
//----- FILE WAS SUCESSFULLY CREATED -----
//----- OPEN THE TEST.TXT FILE FOR READING IF IT EXISTS -----
########## = #########(#################, ################);
## (########## != #)
{
//----- THE TEST.TXT FILE DOES EXIST -----
//WRITE TO THE NEW SPREADSHEET FILE USING DATA FROM THE TEXT FILE
//READ THE FIRST LINE FROM THE TEXT FILE
## (#########(###############, ##, ##########) == #)
#### #################; //Error - end of line not detected
//WRITE TO SPREADSHEET FILE
## (##############(###############, ##########) == #######)
#### #################; //Write error
//READ NEXT LINE AS A DATA BLOCK FROM THE TEXT FILE
#########(###############, ######(####), (###)######(######################), ##########);
//WRITE TO SPREADSHEET FILE
##########(######################, ######(####), (###)######(######################), ##########);
//WRITE SEVERAL COLUMNS THE SPREADSHEET FILE
#########((###)'\#', ##########);
#########((###)'\#', ##########);
### (###### = '#'; ###### <= '#'; ######++)
{
#########((###)######, ##########);
#########((###)',', ##########);
}
//CHECK TO SEE IF ANY ERROR HAS OCCURED
## (##########(##########))
#### #################;
//WRITE THE LAST CHARACTER OF THE TEXT FILE TO THE START OF THE NEXT ROW
#########((###)'\#', ##########);
#########((###)'\#', ##########);
#########(##########, #, ############);
###### = #########(##########);
## (###### == #######)
#### #################; //Read error
#########(######, ##########);
#########((###)'\#', ##########);
#########((###)'\#', ##########);
//CLOSE THE TEST.TXT FILE
## (##########(##########))
#### #################; //Error - could not close
}
####
{
//----- THE TEST.TXT FILE DOES NOT EXIST -----
//WRITE TO THE NEW SPREADSHEET FILE WITHOUT DATA FROM THE TEXT FILE
## (#########(####################################, ##########) == #######)
#### #################; //Write error
}
//----- CLOSE THE SPREADSHEET FILE -----
## (##########(##########))
#### #################; //Error - could not close
//----- BLINK THE GREEN LED TO CONFIRM OPERATION -----
######################### = ##;
}
####
{
//----- ERROR - THE FILE COULD NOT BE CREATED -----
#### #################;
}
}
######;
file_access_error:
//-----------------------------
//----- FILE ACCESS ERROR -----
//-----------------------------
//Try and close the files if they are open
##########(##########);
##########(##########);
#####(#) //<<<< HALT HERE FOR DEBUG - HANDLE PROPERLY FOR A RELEASE APPLICATION <<<<
;
}
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//*************************************************************************************************************************************
//************************************************
//************************************************
//********** INTERRUPT VECTOR LOCATIONS **********
//************************************************
//************************************************
//***********************************
//***** HIGH PRIORITY INTERRUPT *****
//***********************************
####### #### ##########=#### //This is the vector address for a PIC18 high priority interrupt
void athighvector (void)
{
#### #### ############# #######
}
####### #### //(Return to normal)
//**********************************
//***** LOW PRIORITY INTERRUPT *****
//**********************************
####### #### #########=#### //This is the vector address for a PIC18 low priority interrupt
void atlowvector (void)
{
#### #### ############# #######
}
####### #### //(Return to normal)
//*************************************************************
//*************************************************************
//********** HIGH PRIORITY INTERRUPT SERVICE ROUTINE **********
//*************************************************************
//*************************************************************
//#pragma interrupt interruptisrh //<<< This is the normal C18 compiler definition to indicate the interrupt high priority function.
####### ############ ############# //<<<For PIC18 devices with the silicon bug that means the RETFIE FAST instruction cannot be used use this C18
//compiler definition so that the low priority context saving aproach is used (if not sure just use this)
void interruptisrh (void)
{
###### #### ############## = #;
###### #### ############# = #;
//************************
//***** USART TX IRQ *****
//************************
//if(PIE1bits.TXIE && PIR1bits.TXIF)
// usart_transmit_irq();
//************************
//***** USART RX IRQ *****
//************************
//if(PIE1bits.RCIE && PIR1bits.RCIF)
// usart_receive_irq();
//***************************************
//********** TIMER 0 HEARTBEAT **********
//***************************************
##(##########.###### && ##########.######)
{
##########.###### = #; //Reset the timer 0 irq flag
####
//Reset timer for the next rollover (in assembler for accuracy)
##### #####,############ //read the current timer value (read low byte loads the high byte)
##### #####,#############
##### ((####### # (((########################### / ###) / #) # ##)) & ######) //<<< /100 for 10mS irq, /1000 for 1mS irq
##### ############,#,# //(1 = file register, 0 = access ram)
##### ((####### # (((########################### / ###) / #) # ##)) >> #) //<<< /100 for 10mS irq, /1000 for 1mS irq
###### #############,#,# //(1 = file register, 0 = access ram)
##### #############,##### //Store new value (high byte first)
##### ############,#####
#######
//The above code takes 12 instruction cycles
//The timer is inhibited for 2 instruction cycles after the low byte is written
//Therefore subtract 14 from the value to be written
//------------------------------
//------------------------------
//----- HERE EVERY 10 mSec -----
//------------------------------
//------------------------------
//----- GENERAL USE 10mS TIMER -----
## (######################)
########################;
//----- READ SWITCHES FLAG -----
################## = #;
//----- USER MODE 10mS TIMER -----
## (####################)
######################;
//----- FAT FILING SYSTEM DRIVER TIMER -----
## (##############)
################;
//----- LED TIMERS -----
## (#########################)
###########################;
## (#########################)
###########################;
##############++;
## (############## == ##)
{
//-------------------------------
//-------------------------------
//----- HERE EVERY 100 mSec -----
//-------------------------------
//-------------------------------
############## = #;
//----- GENERAL USE 100mS TIMER -----
## (#######################)
#########################;
#############++;
## (############# == ##)
{
//----------------------------
//----------------------------
//----- HERE EVERY 1 Sec -----
//----------------------------
//----------------------------
############# = #;
}
}
}
//<<<<< ADD OTHER HIGH PRIORITY INTERRUPTS HERE <<<<<
}
//************************************************************
//************************************************************
//********** LOW PRIORITY INTERRUPT SERVICE ROUTINE **********
//************************************************************
//************************************************************
####### ############ ############# //<<< C18 compiler definition to indicate the interrupt low priority function.
void interruptisrl (void)
{
//<<<<< ADD OTHER LOW PRIORITY INTERRUPTS HERE <<<<<
}
####### #### //(Return to normal)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -