51_LanQiaoBei/题目/真题/12 第十二届省赛_左岚/第一套/第十二届省赛1/Driver/Led.c

56 lines
1.1 KiB
C
Raw Normal View History

2025-04-13 01:02:19 +08:00
#include <Led.h>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ0-7<><37><EFBFBD>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>
void Led_Disp(unsigned char addr,enable)
{
//<2F><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
//<2F><><EFBFBD>ĵ<EFBFBD>ǰ״̬
if(enable)
temp |= 0x01 << addr;
else
temp &= ~(0x01 << addr);
//<2F><>ǰ״̬<D7B4><CCAC>֮ǰ<D6AE><C7B0>״̬<D7B4><CCAC>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>led
if(temp != temp_old)
{
P0 = ~temp;
P2 = P2 & 0x1f | 0x80;
P2 &= 0x1f;
temp_old = temp;
}
}
void Beep(unsigned char flag)
{
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
if(flag)
temp |= 0x40;
else
temp &= ~0x40;
if(temp != temp_old)
{
P0 = temp;
P2 = P2 & 0x1f | 0xa0;
P2 &= 0x1f;
temp_old = temp;
}
}
void Relay(unsigned char flag)
{
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
if(flag)
temp |= 0x10;
else
temp &= ~0x10;
if(temp != temp_old)
{
P0 = temp;
P2 = P2 & 0x1f | 0xa0;
P2 &= 0x1f;
temp_old = temp;
}
}