📄 systeminitialize.c
字号:
#include "derivative.h" /* include peripheral declarations */
#include "SystemInitialize.h"
void EnablePullups(void)
{
PTAPE = 0xFF; // Enable PORT A Internal Pullups
PTCPE = 0xFF; // Enable PORT C Internal Pullups
PTDPE = 0xFF; // Enable PORT D Internal Pullups
PTEPE = 0xFF; // Enable PORT E Internal Pullups
PTHPE = 0xFF; // Enable PORT H Internal Pullups
PTFPE = 0xFF; // Enable PORT F Internal Pullups
PTGPE = 0xFF; // Enable PORT G Internal Pullups
PTJPE = 0xFF; // Enable PORT J Internal Pullups
} //end EnablePullups
void SelectDriveStrength_High(void)
{
PTDDS = 0xFF; // PORT D High output drive strength
PTEDS = 0xFF; // PORT E High output drive strength
PTHDS = 0xFF; // PORT H High output drive strength
}
void InitIO_Direction()
{
PTHDD = 0xFF;
PTEDD_PTEDD7 = 1;
PTDDD_PTDDD0 = 1;
PTDDD_PTDDD1 = 1;
PTFDD_PTFDD2 = 1;
PTEDD_PTEDD4 = 1;
PTFDD_PTFDD1 = 1;
//
PTFDD_PTFDD5 = 0;
PTFDD_PTFDD6 = 0;
PTFDD_PTFDD7 = 0;
PTCDD_PTCDD0 = 0;
PTJDD_PTJDD0 = 1;
PTDDD_PTDDD4 = 1;
PTDDD_PTDDD3 = 1;
}
void InitIO()
{
EnablePullups();
//SelectDriveStrength_High();
InitIO_Direction();
}
void InitKBI(void)
{
/*KBI1 Init*/
KBI1SC_KBIE = 0; // Mask KBI1 interrupts
KBI1ES_KBEDG3 = 0; // KBI1P3 internal pull-up, falling edge/low level
KBI1ES_KBEDG2 = 0; // KBI1P2 internal pull-up, falling edge/low level
KBI1ES_KBEDG1 = 0; // KBI1P1 internal pull-up, falling edge/low level
KBI1PE_KBIPE3 = 1; // Enable KBI1P3 interrupts
KBI1PE_KBIPE2 = 1; // Enable KBI1P2 interrupts
KBI1PE_KBIPE1 = 1; // Enable KBI1P1 interrupts
KBI1SC_KBIMOD = 0; // Detect edges only
KBI1SC_KBACK = 1; // Clear possible false interrupts
KBI1SC_KBIE = 1; // Enable KBI1 interrupts
} //end InitKBI
void InitADC(void)
{
byte done = 0x00;
ADCSC1 = 0x1F; /* Disable interrupts
Disable continuous conversions
Disable ADC by setting all ADCH bits */
ADCSC2 = 0x40; /* Select H/W trigger
Disable compare function */
ADCCFG = 0x03; /* ADIV=input clock/8
ADLSMP=long sample time
MODE=8-bit conversion
ADICLK=async clock */
APCTL1 = 0x01; // Enable ADP0 as ADC input
} //end InitADC
// Initialize Systems
void InitSystems()
{
SOPT1 = 0x23; // Disable COP,RSTO, enable STOP,BKGD,RESET
SOPT2 = 0x08; // SPI1 on PTE2/3/4/5, IIC1 on PTA2/3
SPMSC1 = 0x00; // Disable LVD
SPMSC2 = 0x00; // Disable power-down modes
SPMSC3 = 0x00; // Disable LVWIE, low trip points
SCGC1 = 0xFF; // Enable bus clock to peripherals
SCGC2 = 0xFF; // Enable bus clock to peripherals
}
// Initialize device
void InitDevice(void)
{
// Enable CoinIn
PTGD_PTGD1 = 1;
PTGDD_PTGDD1 = 1;
// ENABLE LATCH
PTJD_PTJD0 = 0;
PTDD_PTDD4 = 0;
PTDD_PTDD3 = 0;
}
void InitTimer()
{
// timer3 for buttom
TPM3MOD = 0x138; // debounce time = 20ms
TPM3SC = 0x0f; // timer interrupt disabled, clock source=Bus rate clock=4MHz, divider=128
// timer2 for delay
TPM2MOD = 0xFFFF; // debounce time = ?s
TPM2SC = 0x0f; // timer interrupt disabled, clock source=Bus rate clock=4MHz, divider=128
// timer1 for display
TPM1MOD = 0x009F; // debounce time = ms
TPM1SC = 0x0F; // timer interrupt disabled, clock source=Bus rate clock=4MHz, divider=128
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -