TA的每日心情 | 奋斗 昨天 20:14 |
---|
签到天数: 167 天 [LV.7]常住居民III
二级逆天
- 积分
- 9314
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
1.红外遥控
晶振
//-------------------------------------------------------------------- |
stm8s
#define uchar unsigned char |
#define uint unsigned int |
uchar IrRecStep = 0; //接收步骤 |
uchar IrIndex = 0; //接收位数 |
uchar IrRecFlag = 0; //接收完标志 |
uchar IrRecBuff[4]; //接收缓冲区 |
uchar IrRecAddr1; //红外地址码 |
ddr2
uchar IrRecData1; //红外数据码 |
const uchar IrCode[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; |
//--------引导码低电平范围------------------ |
#define IrHeadLow_Max 2300 //2300*4 = 9200us |
#define IrHeadLow_Min 2100 //2100*4 = 8400us |
//--------引导码高电平范围------------------ |
#define IrHeadHigh_Max 1250 //1250*4 = 5000us |
#define IrHeadHigh_Min 1050 //1050*4 = 4200us |
//--------数据0的周期范围------------------- |
#define IrData00_Max 300 //300*4 = 1200us |
#define IrData00_Min 260 //260*4 = 1040us |
//--------数据1的周期范围------------------- |
#define IrData10_Max 580 //580*4 = 2320us |
#define IrData10_Min 540 //540*4 = 2160us |
//--------数据0的占空比(高电平)范围--------- |
#define IrData0_Max 160 //160*4 = 640us |
#define IrData0_Min 120 //120*4 = 480us |
//--------数据1的占空比(高电平)范围--------- |
#define IrData1_Max 440 //440*4 = 1760us |
#define IrData1_Min 400 //400*4 = 1600us |
//---------------------------------------------------------- |
#define REMOTE_CLK_DIV 63 //63+1=64----16Mh/64=4us |
#define REMOTE_ICF_FILTER 0x30 |
for( i=0; i<1000; i++ ) |
PC_DDR_DDR1 = 0; //PC1为输入 |
TIM1_PSCRL = REMOTE_CLK_DIV; |
TIM1_CCER1 &= 0xee;//禁止输入捕获1,2 |
TIM1_CCMR1 | = (REMOTE_ICF_FILTER + 0x01);// ch1到ti1fp1 |
TIM1_CCER1 &= 0xec;//ch1 上升沿触发 |
TIM1_CCMR2 | = (REMOTE_ICF_FILTER + 0x02);// ch2选择 ti1fp2上 |
TIM1_CCER1 | = 0x20;//ch1 下降沿触发 ic2 |
TIM1_SMCR | = 0x54;//选源触发源和触发方式 复位 |
TIM1_CCER1 | = 0x11;//使能输入捕获1,2 |
if ((TIM1_SR1_CC1IF == 1)&&(TIM1_SR1_CC2IF == 1)) |
IrHigh = (uint)(TIM1_CCR2H); |
IrHigh = (IrHigh << 8) + TIM1_CCR2L; //IrHigh占空比 |
IrCycle = (uint)(TIM1_CCR1H); |
IrCycle = (IrCycle << 8) + TIM1_CCR1L; //IrCycle周期 |
if (((IrCycle - IrHigh) < IrHeadLow_Max)&&((IrCycle - IrHigh) > IrHeadLow_Min)) |
if ((TIM1_SR2_CC1OF==1) | | (TIM1_SR2_CC2OF==1) | | (TIM1_SR1_UIF==1)) |
if ((TIM1_SR1_CC1IF == 1)&&(TIM1_SR1_CC2IF == 1)) |
IrHigh = (uint)(TIM1_CCR2H); |
IrHigh = (IrHigh << 8) + TIM1_CCR2L; |
IrCycle = (uint)(TIM1_CCR1H); |
IrCycle = (IrCycle << 8) + TIM1_CCR1L; |
if ((IrHigh < IrHeadHigh_Max)&&(IrHigh > IrHeadHigh_Min)) |
if ((TIM1_SR2_CC1OF==1) | | (TIM1_SR2_CC2OF==1) | | (TIM1_SR1_UIF==1)) |
if ((TIM1_SR1_CC1IF == 1)&&(TIM1_SR1_CC2IF == 1)) |
IrHigh = (uint)(TIM1_CCR2H); |
IrHigh = (IrHigh << 8) + TIM1_CCR2L; |
IrCycle = (uint)(TIM1_CCR1H); |
IrCycle = (IrCycle << 8) + TIM1_CCR1L; |
if ((IrCycle > IrData00_Min)&&(IrCycle < IrData00_Max)) |
if ((IrHigh > IrData0_Min)&&(IrHigh < IrData0_Max)) |
else if ((IrCycle > IrData10_Min)&&(IrCycle < IrData10_Max)) |
if ((IrHigh > IrData1_Min)&&(IrHigh < IrData1_Max)) |
IrRecBuff[IrIndex >> 3] | = IrCode[IrIndex & 0x07]; |
时钟
CLK_ECKR=0x03;//外部时钟寄存器 外部时钟准备就绪,外部时钟开 |
CLK_SWCR=0x02;//切换控制寄存器 使能切换机制 |
CLK_SWR=0xB4;//主时钟切换寄存器 选择HSE为主时钟源*/ |
while (!(CLK_SWCR & 0x08)); |
CLK_CSSR=0x01;//时钟安全系统寄存器 |
IrRecAddr1 = IrRecBuff[0]; |
IrRecAddr2 = IrRecBuff[1]; |
IrRecData1 = IrRecBuff[2]; |
IrRecData2 = IrRecBuff[3]; |
|
|