//LED 底层重构
//led.c
void Led_Disp(unsigned char addr,enable)
{
static unsigned char temp = 0x00;
static unsigned char temp_old = 0xff;
if(enable)
{
temp |=0x01 <<addr;
}
else temp &= ~(0x01 << addr);
if(temp != old_temp)
{
P0 = ~temp;
P2 = P2 & 0x1f | 0x80;
P2 &= 0x1f;
temp_old = temp;
}
}
----------------------------------------------
//main.c
unsigned char ucLed[8]={0,0,0,0,0,0,0,0};
void Timer0Server() interrupt 1
{
Led_Disp(Seg_Pos,ucLed[Seg_Pos]);
//灯随着数码管闪烁
}
void main(void)
{
unsigned char i=0;
for(i=0;i<3;i++)
{
ucLed[i]=(i==Seg_Disp_Mode);
}
}
蓝桥杯(十) LED的另一种底层驱动模式
于 2023-03-23 22:28:59 首次发布