📄 init.c
字号:
//**********************************************************************
//File Name: Init.c
//Include: void Hardware_Init(void); -- Initialize for hardware.
// void Software_Init(void); -- Initialize for software.
//Description: Initialize for the system.
//**********************************************************************
#include "Headfiles.h"
//**********************************************************************
//Func. Name: Hardware_Init Func.
//Input variables: None
//Output variables: None
//Use sub-func.list: None
//Used by list: MainFunc.c - void main(void);
//Description: Initialize for hardware of the system, including:
// Configure System-Clock, Timer-A, Timer-B, I/O Port,
// ADC, DAC.
//**********************************************************************
void Hardware_Init(void)
{
//Configure LCD
ADPCFG |= 0x07FF; //Select digital mode for AD&I/O refrain pins
//RB0~RB10 for digital I/O
TRISB &= 0xFCC0; //Configure Output mode for DB of LCD(RB0~RB5,RB8~RB9)
TRISB |= 0x0400; //Configure Input mode for BUSY signal of LCD(RB10)
_LATD4 &= 0; //No meaning, avoid LCD error
TRISD &= 0xFFEF; //Configure Output mode for Requst signal of LCD(RD4)
//Configure Keyboard
TRISD |= 0x07E0; //Configure Input mode for 6button of Keyboard(RD5~RD10)
//Configure ADC moduel
ADPCFG &= 0x0FFF; //Select analog mode for AD&I/O refrain pins
//RB11~RB15 for analog input
TRISB |= 0xF000; //Configure input mode for ADC moduel(RB11~RB15)
ADCON1 = 0x00E4;
//ADCON1bits.SSRC = 7; //Converse after sample automatically
//ADCON1bits.ASAM = 1; //Start sample automatically
ADCON2 =0x040C;//0x0400;
//ADCON2bits.CSCNA = 1; //Scan input MUXA
//ADCON2bits.SMPI = 0;
ADCON3 = 0x0402;
//ADCON3bits.ADRC = 0;
//ADCON3bits.SAMC = 2;
//ADCON3bits.ADCS = 21; //Configure 83ksps
ADCHS = 0x000C;
//ADCHSbits.CH0SA = 12;
ADCSSL = 0xF000;
_ADCON();
//Configure SPI moduel
SPI1CON = 0x003F;//0x0022;
SPI1STAT &= 0x0000;
TRISF &= 0xFFB7; //Configure SDO & SCLK as digital for SPI
//Configure peripheral ADC moduel
TRISF &= 0xFFFB; //Configure RF2 as digital output for DAC_SYNC
_DACSYNC_DISABLE();
//Configure EEPROM
//Configure Timer1 for servo cycle of system
T1CON = 0x0000;
IFS0bits.T1IF = 0; //Clear interrupt flag of Timer1
IPC0bits.T1IP = 7; //Configure interrupt priority for highest
IEC0bits.T1IE = 1; //Enable interrupt of Timer1
TMR1 = 0xFFFF - SYSTME_SERVO_CYCLE; //Set the first value to counter
//Configure Timer2 & Output Compare moduel for PWM
T2CON = 0x0000;
T2CONbits.T32 = 0; //Select 16bits Counter mode
T2CONbits.TCS = 0; //Select internal clock source
T2CONbits.TCKPS = 0; //Prescale 1:1 for Timer2 clock
IEC0bits.T2IE = 0; //Disable interrupt of Timer2
T2CONbits.TON = 1; //Enalbe Timer2 for counter
TRISD &= 0xFFFD; //Configure digital output mode for PWM(RD1)
OC2CONbits.OCTSEL = 0; //Select Timer2 for clock source
OC2CONbits.OCM = 3; //Reverse the Output when something happened
IEC0bits.OC2IE = 0; //Disable interrupt of OC moduel
}
//**********************************************************************
//Func. Name: Software_Init Func.
//Input variables: None
//Output variables: None
//Use sub-func.list: Flash.c - void Flash_Read(void);
//Used by list: MainFunc.c - void main(void);
//Description: Initialize for software of the system, including:
// Initialize global variables; Run flash_read func.
//**********************************************************************
void Software_Init(void)
{
Interface = MAIN_VIEW; //Initialize the Interface in LCD Display prog.
Arrow_Position = 0; //Initialize the position of arrowhead in LCD Display prog.
Key_Value = NON_KEY;
Key_Buffer = 0x00;
Key_Counter = 0;
Key_Step = KEYBOARD_SCAN_START; //Initialize for Key Scan prog.
// PID_Error_Sum[0] = 0;
// PID_Error_Sum[1] = 0; //Initialize the array of erro-accumulation for PID Control prog.
Refresh_LCD_Flag = 0;
Refresh_Key_Flag = 0;
Refresh_LCD_Cycle = 0;
Refresh_Key_Cycle = 0; //Initialize System Cycle & the Flag in System Cycle
Filter_Ptr = 0;
EEPROM_Read(); //Read data from FLASH
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -