chunyang 发表于 2023-12-19 14:25
显然“群里的大佬”太菜。应尽量采用负逻辑驱动,即LED按你的图中接法更好,因为你所用MCU的灌 ...
自信心崩盘,点灯失败。。。
#include <reg52.h>
unsigned char counter_1s;
#define LED_ON 0
#define LED_OFF 1
sbit led_run = P1^3;
void delay(int ms);
void initT0()
{
TMOD = 0x01;
//TH0 = 0xD8;
//TL0 = 0xF0;
TH0 = 0xDC;
TL0 = 0x00;
EA = 1; // Enable Switch
ET0 = 1; // T0 inter
TR0 = 1;
}
void main( void )
{
initT0();
counter_1s = 0;
while(1)
{
}
}
void delay(int ms)
{
int i,j;
for(i = 0; i<ms; ++i)
for(j = 0; j<110; ++j);
}
void interrupt_t0() interrupt 1
{
// 10ms
//TH0 = 0xD8;
//TL0 = 0xF0;
TH0 = 0xDC;
TL0 = 0x00;
counter_1s++;
if(counter_1s == 100)
{
counter_1s = 0;
led_run = ~led_run;
}
}