/***********定时器**************************/
void Timer1Init(void)
{
TIM1_CR1 |=0X04; //自动重载,只有溢出才产生更新中断
TIM1_IER |=0X01; //允许更新中断
// TIM2_SR1=0X00; //状态寄存器
TIM1_PSCR =0X01; //PSC[3:0]:预分频器的值 ,开预分频功能不许使能EGR中的UG位
// TIM1_PSCR =0X00; //PSC[3:0]:4预分频器的值
TIM2_EGR |=0X01; //时间产生状态寄存器,重新初始化计数器,并产生一个更新事件。
//如果不开预分频功能,此位可以删去 //TIM2_CCMR1=0X00; //捕获/比较模式寄存器,可用于选择PWM输出端口
//TIM2_CCMR1=0X68; //PWM模式,通道1,预装载使能
// TIM2_CCMR2=0X68; //PWM模式,通道2,预装载使能
// TIM2_CCER2=0X03; //使能PWM输出通道
// TIM2_CCER1=0X03; //使能PWM输出通道
TIM1_CNTRH=0X9C; //计数值
TIM1_CNTRL=0X40;
TIM1_ARRH=0X9C; //自动重载值(10ms进一次中断),8M2分频,40000/4000000=10ms
TIM1_ARRL=0X40;
TIM1_CR1 |=0X01; //开计数器
} /************AWU唤醒********************/
void AWU_Open(void)
{
AWU_APR = 0X3E; //APPRdiV=64
AWU_TBR = 0X0D; //time interval = 2^11 *APPRdiV/Fls=2048*64/128KHZ=1S 0D=2S
// AWU_TBR = 0X0E; //time interval = 2^11 *APPRdiV/Fls=2048*64/128KHZ=1S 0E==大约5S
AWU_CSR = 0x30; //enable AWU,AWU_INT
CLK_ICKR |= 0X20; //1:活跃停机(Active Halt) 模式下主dian ya tiao jie qi guan bi
} void AWU_Close(void)
{
AWU_APR = 0X3F; //APPRdiV
AWU_TBR = 0X00; //disable time interval
AWU_CSR = 0x00; //disable AWU
CLK_ICKR &= ~(0X20);
} void EEPROM_Init(void)
{
FLASH_CR1 = 0x00;
FLASH_CR2 = 0x00;
FLASH_DUKR = MASS_KEY1;
FLASH_DUKR = MASS_KEY2; //密钥使能
while(!(FLASH_IAPSR&0x08)); /*等待写保护解锁*/
} /***********EEPROM***************************/
u8 EEPROM_Write(u8 addr,u8 dat)
{
u16 TimeOut;
*((u8*)(addr + EEP_BASE)) = dat; for( TimeOut = 0; TimeOut < 0xFFFF; TimeOut++ )
{
if( FLASH_IAPSR & ( WR_PG_DIS | EOP_BIT ))return 1; //编程完成或者写到了写保护区
}
return 0;
//超时退出
// while(!(FLASH_IAPSR&0x02)); /*等待写完成*/
} u8 EEPROM_Read(u8 addr)
{
return *((u8*)(EEP_BASE + addr));
} void EEPROM_THREE_BYTE_WRITE(void)
{ EEPROM_Write(0x00,i2c_buff[0]);
EEPROM_Write(0x01,i2c_buff[1]);
EEPROM_Write(0x02,i2c_buff[2]);
} void EEPROM_THREE_BYTE_READ(void)
{
if(ADC_OnOff==1)
ADC_ON_OR_OFF=2;
else
ADC_ON_OR_OFF=EEPROM_Read(0x00);
ADC_OPEN_MIN=EEPROM_Read(0x01);
ADC_OPEN_TIME=EEPROM_Read(0x02);
}
|