feat: ppt6
This commit is contained in:
parent
c49d40b8b9
commit
216ae7930c
140
src/main.c
140
src/main.c
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "ds18b20.h"
|
#include "ds18b20.h"
|
||||||
|
|
||||||
|
// #define YELLOW_BOARD
|
||||||
|
|
||||||
typedef unsigned int u16;
|
typedef unsigned int u16;
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
|
|
||||||
@ -15,14 +17,19 @@ u16 tim0countAll = 2000;
|
|||||||
u16 tim0count = 0;
|
u16 tim0count = 0;
|
||||||
u8 tim0flag = 0;
|
u8 tim0flag = 0;
|
||||||
|
|
||||||
#define person P1_0
|
#define PERSON P1_0
|
||||||
#define gasState P1_1
|
#define GAS_STATE P1_1
|
||||||
#define beep P1_5
|
|
||||||
|
#ifdef YELLOW_BOARD
|
||||||
|
#define BEEP P1_5
|
||||||
|
#else
|
||||||
|
#define BEEP P1_6
|
||||||
|
#endif
|
||||||
|
|
||||||
char g_mode = 0x01;
|
char g_mode = 0x01;
|
||||||
char g_bodyMode = 0x00;
|
char g_bodyMode = 0x00;
|
||||||
char g_gasMode = 0x00;
|
char g_gasMode = 0x00;
|
||||||
char FAS_LIGHT_BLINK = 0x50;
|
char GAS_LIGHT_BLINK = 0x50;
|
||||||
|
|
||||||
u8 m_flag = 0;
|
u8 m_flag = 0;
|
||||||
|
|
||||||
@ -48,11 +55,13 @@ u8 LcdSegment[10] = {
|
|||||||
// #define CLASS_3
|
// #define CLASS_3
|
||||||
// #define CLASS_4
|
// #define CLASS_4
|
||||||
|
|
||||||
void delay(u16 i) {
|
void delay(u16 i)
|
||||||
|
{
|
||||||
while (i--);
|
while (i--);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uart1Send(u16 sendData) {
|
void Uart1Send(u16 sendData)
|
||||||
|
{
|
||||||
TI = 0;
|
TI = 0;
|
||||||
SBUF = (char)(sendData >> 8);
|
SBUF = (char)(sendData >> 8);
|
||||||
while (TI == 0);
|
while (TI == 0);
|
||||||
@ -64,7 +73,8 @@ void Uart1Send(u16 sendData) {
|
|||||||
delay(50);
|
delay(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsartInit(void) {
|
void UsartInit(void)
|
||||||
|
{
|
||||||
SCON = 0x50;
|
SCON = 0x50;
|
||||||
TMOD = 0x22;
|
TMOD = 0x22;
|
||||||
PCON = 0x80;
|
PCON = 0x80;
|
||||||
@ -89,20 +99,30 @@ void Usart_ISR(void) __interrupt(4) {
|
|||||||
|
|
||||||
void Timer0_ISR(void) __interrupt(1) {
|
void Timer0_ISR(void) __interrupt(1) {
|
||||||
tim0count++;
|
tim0count++;
|
||||||
if (tim0count >= tim0countAll) {
|
if (tim0count >= tim0countAll)
|
||||||
|
{
|
||||||
tim0count = 0;
|
tim0count = 0;
|
||||||
tim0flag = 1;
|
tim0flag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessCommand(void) {
|
void beep(int duration)
|
||||||
if (newCmdFlag) {
|
{
|
||||||
|
BEEP = ~BEEP;
|
||||||
|
delay(duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessCommand(void)
|
||||||
|
{
|
||||||
|
if (newCmdFlag)
|
||||||
|
{
|
||||||
#ifdef CLASS_3
|
#ifdef CLASS_3
|
||||||
u16 recv_data = (cmdCode << 8) + cmdCode;
|
u16 recv_data = (cmdCode << 8) + cmdCode;
|
||||||
Uart1Send(recv_data);
|
Uart1Send(recv_data);
|
||||||
#endif
|
#endif
|
||||||
newCmdFlag = 0;
|
newCmdFlag = 0;
|
||||||
switch (cmdCode) {
|
switch (cmdCode)
|
||||||
|
{
|
||||||
case CTRL_CODE_CYCLE_500ms:
|
case CTRL_CODE_CYCLE_500ms:
|
||||||
tim0countAll = 2000;
|
tim0countAll = 2000;
|
||||||
break;
|
break;
|
||||||
@ -140,10 +160,13 @@ void ProcessCommand(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LcdDisplay(void) {
|
void LcdDisplay(void)
|
||||||
|
{
|
||||||
u8 i;
|
u8 i;
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++)
|
||||||
switch (i) {
|
{
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
LSA = 0;
|
LSA = 0;
|
||||||
LSB = 0;
|
LSB = 0;
|
||||||
@ -181,16 +204,20 @@ void LcdDisplay(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TempProc(int temp) {
|
void TempProc(int temp)
|
||||||
|
{
|
||||||
float tp;
|
float tp;
|
||||||
u8 i = 0;
|
u8 i = 0;
|
||||||
if (temp < 0) {
|
if (temp < 0)
|
||||||
|
{
|
||||||
DisplayData[0] = 0x40;
|
DisplayData[0] = 0x40;
|
||||||
temp = temp - 1;
|
temp = temp - 1;
|
||||||
temp = ~temp;
|
temp = ~temp;
|
||||||
tp = temp;
|
tp = temp;
|
||||||
temp = tp * 0.0625 * 100 + 0.5;
|
temp = tp * 0.0625 * 100 + 0.5;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
DisplayData[0] = 0x00;
|
DisplayData[0] = 0x00;
|
||||||
tp = temp;
|
tp = temp;
|
||||||
temp = tp * 0.0625 * 100 + 0.5;
|
temp = tp * 0.0625 * 100 + 0.5;
|
||||||
@ -202,13 +229,15 @@ void TempProc(int temp) {
|
|||||||
DisplayData[5] = LcdSegment[temp % 10];
|
DisplayData[5] = LcdSegment[temp % 10];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessTempCmd(void) {
|
void ProcessTempCmd(void)
|
||||||
|
{
|
||||||
u16 t_send = 0, tc = 0, td = 0;
|
u16 t_send = 0, tc = 0, td = 0;
|
||||||
int temp;
|
int temp;
|
||||||
#ifdef CLASS_4
|
#ifdef CLASS_4
|
||||||
tempCmdCode = CTRL_CODE_TEMP_Enable;
|
tempCmdCode = CTRL_CODE_TEMP_Enable;
|
||||||
#endif
|
#endif
|
||||||
if (tempCmdCode == CTRL_CODE_TEMP_Enable) {
|
if (tempCmdCode == CTRL_CODE_TEMP_Enable)
|
||||||
|
{
|
||||||
EA = 0;
|
EA = 0;
|
||||||
DS18B20_startConvert();
|
DS18B20_startConvert();
|
||||||
temp = DS18B20_readTemperature();
|
temp = DS18B20_readTemperature();
|
||||||
@ -221,43 +250,84 @@ void ProcessTempCmd(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProcessBodyCmd(void) {
|
int ProcessBodyCmd(void)
|
||||||
|
{
|
||||||
|
int r_flag = 0;
|
||||||
|
u8 state = 0;
|
||||||
|
u16 send_buff = 0;
|
||||||
|
PERSON = 1;
|
||||||
|
delay(1);
|
||||||
|
state = PERSON;
|
||||||
|
if (state == 0)
|
||||||
|
{
|
||||||
|
if (g_bodyMode == CTRL_CODE_BODY_Light)
|
||||||
|
{
|
||||||
|
lightCmdCode = GAS_LIGHT_BLINK;
|
||||||
|
}
|
||||||
|
if (g_bodyMode == CTRL_CODE_BODY_Buzzer)
|
||||||
|
{
|
||||||
|
r_flag = 1;
|
||||||
|
}
|
||||||
|
send_buff = (MCU_CMD_BODY << 12) + MCU_CMD_BODY_NO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lightCmdCode = 0;
|
||||||
|
send_buff = (MCU_CMD_BODY << 12) + MCU_CMD_BODY_NO;
|
||||||
|
}
|
||||||
|
Uart1Send(send_buff);
|
||||||
|
return r_flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessLightCmd(void)
|
||||||
|
{
|
||||||
|
if (lightCmdCode == GAS_LIGHT_BLINK)
|
||||||
|
{
|
||||||
|
P2 = ~P2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ProcessGasCmd(void)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessLightCmd(void) {
|
void main(void)
|
||||||
}
|
{
|
||||||
|
int gasFlag, bodyFlag = 0;
|
||||||
int ProcessGasCmd(void) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(void) {
|
|
||||||
int gasFlag, bodyFlag;
|
|
||||||
DS18B20_startConvert();
|
DS18B20_startConvert();
|
||||||
delay(100);
|
delay(100);
|
||||||
UsartInit();
|
UsartInit();
|
||||||
while (1) {
|
while (1)
|
||||||
|
{
|
||||||
ProcessCommand();
|
ProcessCommand();
|
||||||
LcdDisplay();
|
|
||||||
|
|
||||||
#ifdef CLASS_4
|
#ifdef CLASS_4
|
||||||
ProcessTempCmd();
|
ProcessTempCmd();
|
||||||
LcdDisplay();
|
LcdDisplay();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (tim0flag) {
|
if (tim0flag)
|
||||||
|
{
|
||||||
tim0flag = 0;
|
tim0flag = 0;
|
||||||
if (g_mode == CTRL_CODE_SYSMODE_Security) {
|
if (g_mode == CTRL_CODE_SYSMODE_Security)
|
||||||
|
{
|
||||||
bodyFlag = ProcessBodyCmd();
|
bodyFlag = ProcessBodyCmd();
|
||||||
}
|
}
|
||||||
if ((g_mode == CTRL_CODE_SYSMODE_Security) || (g_mode == CTRL_CODE_SYSMODE_Telemetry)) {
|
if ((g_mode == CTRL_CODE_SYSMODE_Security) || (g_mode == CTRL_CODE_SYSMODE_Telemetry))
|
||||||
|
{
|
||||||
gasFlag = ProcessGasCmd();
|
gasFlag = ProcessGasCmd();
|
||||||
}
|
}
|
||||||
ProcessLightCmd();
|
ProcessLightCmd();
|
||||||
if (tempCmdCode != CTRL_CODE_TEMP_Disable) {
|
if (tempCmdCode != CTRL_CODE_TEMP_Disable)
|
||||||
|
{
|
||||||
ProcessTempCmd();
|
ProcessTempCmd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (bodyFlag)
|
||||||
|
{
|
||||||
|
beep(2);
|
||||||
|
}
|
||||||
|
LcdDisplay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user