51_LanQiaoBei/模板/zuolan_v1标志位/driver/led.c

63 lines
1.2 KiB
C
Raw Normal View History

2025-04-13 01:02:19 +08:00
#include "led.h"
/// @brief Ledɨ<64><C9A8>
/// @param addr <20><>Ҫ<EFBFBD><D2AA><EFBFBD>Ƶ<EFBFBD>Led<65>ĵ<EFBFBD>ַ<EFBFBD><D6B7>0-7<><37>
/// @param enable <20><><EFBFBD>Ƹõ<C6B8>ַ<EFBFBD><D6B7>Led<65>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
void Led_Disp(unsigned char addr, unsigned char enable) {
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
if (enable)
temp |= 0x01 << addr;
else
temp &= ~(0x01 << addr);
if (temp != temp_old) {
P0 = ~temp;
P2 = P2 & 0x1f | 0x80;
P2 &= 0x1f;
temp_old = temp;
}
}
unsigned char temp_0 = 0x00;
unsigned char temp_old_0 = 0xff;
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param enable
void Beep(bit enable) {
if (enable)
temp_0 |= 0x40;
else
temp_0 &= ~(0x40);
if (temp_0 != temp_old_0) {
P0 = temp_0;
P2 = P2 & 0x1f | 0xa0;
P2 &= 0x1f;
temp_old_0 = temp_0;
}
}
/// @brief <20>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param enable
void Relay(bit enable) {
if (enable)
temp_0 |= 0x10;
else
temp_0 &= ~(0x10);
if (temp_0 != temp_old_0) {
P0 = temp_0;
P2 = P2 & 0x1f | 0xa0;
P2 &= 0x1f;
temp_old_0 = temp_0;
}
}
/// @brief MOTOR<4F><52><EFBFBD><EFBFBD>
/// @param enable
void MOTOR(bit enable) {
if (enable)
temp_0 |= 0x20;
else
temp_0 &= ~(0x20);
if (temp_0 != temp_old_0) {
P0 = temp_0;
P2 = P2 & 0x1f | 0xa0;
P2 &= 0x1f;
temp_old_0 = temp_0;
}
}