51_LanQiaoBei/模板/蓝桥杯全模块测试例程/EEPROM存储模块/Driver/Led.c

75 lines
1.5 KiB
C
Raw Normal View History

2025-04-13 01:02:19 +08:00
#include "Led.h"
/// @brief Led<65><64>ʾ
/// @param addr <20><>Ҫ<EFBFBD><D2AA>д<EFBFBD><D0B4>Led<65><64>λ<EFBFBD><CEBB>0-7
/// @param enable <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> 0<><30> 1<><31>
void Led_Disp(unsigned char addr, unsigned char enable)
{
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
// ָ<><D6B8>λ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>
if (enable)
temp |= 0x01 << addr;
else
temp &= ~(0x01 << addr);
if (temp != temp_old)
{
P0 = ~temp;
P2 = P2 & 0x1f | 0x80;
P2 &= 0x1f;
temp_old = temp;
}
}
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param enable 0 <20><> 1 <20><>
void Beep(bit enable)
{
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
if (enable)
temp |= 0x40;
else
temp &= ~(0x40);
if (temp != temp_old)
{
P0 = temp;
P2 = P2 & 0x1f | 0xa0;
P2 &= 0x1f;
temp_old = temp;
}
}
/// @brief <20>̵<EFBFBD><CCB5><EFBFBD>
/// @param enable 0 <20><> 1 <20><>
void Relay(bit enable)
{
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
if (enable)
temp |= 0x10;
else
temp &= ~(0x10);
if (temp != temp_old)
{
P0 = temp;
P2 = P2 & 0x1f | 0xa0;
P2 &= 0x1f;
temp_old = temp;
}
}
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ߻<C4B8><DFBB>ǵ͵<C7B5>ƽ
/// @param enable 0 <20><> 1 <20><>
void MOTOR(bit enable)
{
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
if (enable)
temp |= 0x20;
else
temp &= ~(0x20);
if (temp != temp_old)
{
P0 = temp;
P2 = P2 & 0x1f | 0xa0;
P2 &= 0x1f;
temp_old = temp;
}
}