软件的初始化
void MCUInit(void)
{
//LED IO初始化
PC_DDR |= (LED_G); //输出模式
//PC_CR1 |= (LED1|LED2|LED3|LED4); //推挽输出
PC_CR1 |= (LED_G);
LED_OUT&= (~LED_G); //输出高
PC_DDR |= 0x10; //PC4 out
PC_CR1 |= 0x10; //shangla
PC_ODR |= 0x10; //输出高
//KEY_IO PB5改为下降沿中断
PB_DDR &= (~KEY_IO); //输入模式
PB_CR1 |= (KEY_IO); //上拉输入
PB_CR2 |= KEY_IO; //关闭中断
EXTI_CR1 &= (~(0X03<<PORT_B)); //PORT B下降沿中断
//EXTI_CR1 |= (FallingEdgeOnly<<PORT_B);
//POWER_IN PC7shang下降沿中断
//DC_POW
PA_DDR |= DC_POW; //输出模式
PA_CR1 |= DC_POW; //推挽输出
PA_ODR &= (~DC_POW); //输出低
//PA_ODR |= DC_POW;
//OUT_POW COM_POW
PD_DDR |= (OUT_POW|COM_POW); //输出模式
PD_CR1 |= (OUT_POW|COM_POW); //推挽输出
PD_ODR = (~(OUT_POW|COM_POW)); //输出低
//PD_ODR = ((OUT_POW|COM_POW));
//LOW PWR DETECT PD4
PD_DDR &= 0xEF; //PD4 input
PD_CR1 |= 0x10; //PD4 PULL up
//ADC_LEVEL PD2 AIN3
//ADC_SHORT PD3 AIN4
CLK_PCKENR2 |=0x08; //打开ADC时钟
PD_DDR &= 0xF3;
//输入模式
PD_CR1 |= ((LEVEL_BIT|TEST_BIT));
//lghshangla输入
ADC_TDRL |= ((1<<ADC_LEVEL)|(1<<ADC_SHORT));
//禁止施密特触发
//ADC_CSR |= 0x20; //所能转换结束中断
ADC_CR1 |= 0x00; //单次转换模式
ADC_CR3 |= 0x00; //数据缓存取消
//TIM2 设置 100ms定时器中断
CLK_PCKENR1 |= 0x20; //打开TIM时钟
//默认系统主频 16Mhz 8分频 = 2Mhz
TIM2_PSCR = 4; //16分频 2Mhz / 16 = 125Khz
TIM2_CR1 = 0x09; //使能计时器 更新中断以后自动停止
TIM2_CNTRH = 0xcf; //计数12500次
TIM2_CNTRL = 0x2c; //65536-12500=53036=0xcf2c
TIM2_IER = 0x01; //使能中断 使能更新中断
}
|