📄 freescale
字号:
#include "IO_Map.h"
#include "LIGHT_AD.h"
#include "IRLED.h"
#include "OAPOWER.h"
#include "LED.h"
unsigned int dark_buffer[4]; // buffer for 4 ADC samples
unsigned int light_buffer[4]; // buffer for 4 ADC samples
unsigned int dark_average; // Average 4 samples with no IRLED
unsigned int light_average; // Average 4 samples with IRLED on
unsigned char smoke_detect_count = 0; // Counter for smoke detections
unsigned char alarm_flag = 0; // Alarm status. 1 means smoke
void Sample (void)
{
unsigned char i, temp;
temp = PTBD; // Preserve LED "on" if alarming
OAPOWER_SetVal(); // Turn on OA. Settling delay is below
LED_SetVal();
for(i =0;i< 4;i++)
{
LIGHT_AD_Measure(0x01); //启动A/D转换
LIGHT_AD_GetValue(dark_buffer); //读取A/D转换结果
}
IRLED_SetVal(); // Turn on IRLED
for(i =0;i< 4;i++)
{
LIGHT_AD_Measure(0x01);
LIGHT_AD_GetValue(light_buffer);
}
PTBD = temp; // Restore P1OUT, turns off IRLED and OA
}
void Average (void)
{
unsigned int i;
dark_average = 0;
light_average = 0;
for (i = 0; i < 4; i++)
{
dark_average += dark_buffer[i];
light_average += light_buffer[i];
}
dark_average = (dark_average >> 2);
light_average = (light_average >> 2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -