feat: prod mode, lcd display and temperature data upload

This commit is contained in:
Timothy Yin 2024-11-28 04:05:43 +08:00
parent 8edaf36a1a
commit 8894d23d78

View File

@ -1,7 +1,6 @@
#include <8052.h> #include <8052.h>
#include "serial_command.h" #include "serial_command.h"
#include "onewire.h"
#include "ds18b20.h" #include "ds18b20.h"
typedef unsigned int u16; typedef unsigned int u16;
@ -16,13 +15,14 @@ u16 tim0countAll = 2000;
u16 tim0count = 0; u16 tim0count = 0;
u8 tim0flag = 0; u8 tim0flag = 0;
#define person P1_0
#define gasState P1_1
#define beep P1_5
char g_mode = 0x01; char g_mode = 0x01;
char g_bodyMode = 0x00; char g_bodyMode = 0x00;
#define person = P1_0;
char g_gasMode = 0x00; char g_gasMode = 0x00;
#define gasState = P1_1;
char FAS_LIGHT_BLINK = 0x50; char FAS_LIGHT_BLINK = 0x50;
#define beep = P1_5;
u8 m_flag = 0; u8 m_flag = 0;
@ -45,8 +45,8 @@ u8 LcdSegment[10] = {
0x6F 0x6F
}; };
#define CLASS_3 // #define CLASS_3
#define CLASS_4 // #define CLASS_4
void delay(u16 i) { void delay(u16 i) {
while (i--); while (i--);
@ -55,13 +55,11 @@ void delay(u16 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);
}
TI = 0; TI = 0;
SBUF = (char) (sendData & 0xFF); SBUF = (char) (sendData & 0xFF);
while (TI == 0) { while (TI == 0);
}
TI = 0; TI = 0;
delay(50); delay(50);
} }
@ -72,24 +70,36 @@ void UsartInit(void) {
PCON = 0x80; PCON = 0x80;
TH1 = 0xF4; TH1 = 0xF4;
TL1 = 0xF4; TL1 = 0xF4;
TR1 = 1;
ES = 1; ES = 1;
EA = 1; EA = 1;
TR1 = 1;
PS = 1; PS = 1;
TH0 = 0x05;
TL0 = 0x05;
ET0 = 1;
TR0 = 1;
} }
void Usart(void) __interrupt(4) { void Usart_ISR(void) __interrupt(4) {
cmdCode = SBUF; cmdCode = SBUF;
newCmdFlag = 1; newCmdFlag = 1;
RI = 0; RI = 0;
} }
void Timer0_ISR(void) __interrupt(1) {
tim0count++;
if (tim0count >= tim0countAll) {
tim0count = 0;
tim0flag = 1;
}
}
void ProcessCommand(void) { void ProcessCommand(void) {
if (newCmdFlag) { if (newCmdFlag) {
#ifdef CLASS_3 #ifdef CLASS_3
u16 recvData; u16 recv_data = (cmdCode << 8) + cmdCode;
recvData = (cmdCode << 8) + cmdCode; Uart1Send(recv_data);
Uart1Send(recvData);
#endif #endif
newCmdFlag = 0; newCmdFlag = 0;
switch (cmdCode) { switch (cmdCode) {
@ -166,7 +176,7 @@ void LcdDisplay(void) {
break; break;
} }
P0 = DisplayData[5 - i]; P0 = DisplayData[5 - i];
delay(100); delay(200);
P0 = 0x00; P0 = 0x00;
} }
} }
@ -229,11 +239,11 @@ void main(void) {
UsartInit(); UsartInit();
while (1) { while (1) {
ProcessCommand(); ProcessCommand();
LcdDisplay();
#ifdef CLASS_4 #ifdef CLASS_4
ProcessTempCmd(); ProcessTempCmd();
LcdDisplay(); LcdDisplay();
// Uart1Send(0x1234);
#endif #endif
if (tim0flag) { if (tim0flag) {