#include <reg51.h>
#define LED_P1_1 0x01
#define LED_P1_2 0x02
#define LED_P1_3 0x04
#define LED_P1_4 0x08
#define LED_P1_5 0x10
#define LED_P1_6 0x20
#define LED_P1_7 0x40
#define LED_P1_8 0x80
unsigned int count_D1_D2 = 0;
unsigned int count_D3_D4 = 0;
unsigned int count_D5_D6 = 0;
unsigned int count_D7_D8 = 0;
void init_timer(void)
{
TMOD = 0x01;
TH0 = (65536 - 200) >> 8;
TL0 = (65536 - 200) & 0xFF;
TR0 = 1;
EA = 1;
ET0 = 1;
}
void main()
{
P1 = 0xFF;
init_timer();
while(1)
{
}
}
void timer0_isr() interrupt 1
{
TH0 = (65536 - 200) >> 8;
TL0 = (65536 - 200) & 0xFF;
count_D1_D2++;
count_D3_D4++;
count_D5_D6++;
count_D7_D8++;
if(count_D1_D2 >= 1000)
{
count_D1_D2 = 0;
P1 ^= LED_P1_1 | LED_P1_2;
}
if(count_D3_D4 >= 2500)
{
count_D3_D4 = 0;
P1 ^= LED_P1_3 | LED_P1_4;
}
if(count_D5_D6 >= 5000)
{
count_D5_D6 = 0;
P1 ^= LED_P1_5 | LED_P1_6;
}
if(count_D7_D8 >= 10000)
{
count_D7_D8 = 0;
P1 ^= LED_P1_7 | LED_P1_8;
}
}
#include <reg52.h>
sbit LED1 = P1^0;
sbit LED2 = P1^1;
sbit LED3 = P1^2;
sbit LED4 = P1^3;
sbit LED5 = P1^4;
sbit LED6 = P1^5;
sbit LED7 = P1^6;
sbit LED8 = P1^7;
unsigned int timer_count = 0;
void Timer0_ISR(void) interrupt 1 {
TH0 = 0xee;
TL0 = 0x00;
timer_count++;
if (timer_count ==200 ) {
P1=0xff;
LED1 = ~LED1;
LED2 = ~LED2;
}
if (timer_count == 500) {
P1=0xff;
LED3 = ~LED3;
LED4 = ~LED4;
}
if (timer_count == 1000) {
P1=0xff;
LED1 = ~LED1;
LED2 = ~LED2;
LED3 = ~LED3;
LED4 = ~LED4;
LED5 = ~LED5;
LED6 = ~LED6;
}
if (timer_count == 2000) {
P1=0xff;
LED1 = ~LED1;
LED2 = ~LED2;
LED3 = ~LED3;
LED4 = ~LED4;
LED5 = ~LED5;
LED6 = ~LED6;
LED7 = ~LED7;
LED8 = ~LED8;
timer_count=0;
}
}
void main(void) {
TMOD |= 0x01;
P1=0xff;
TH0 = 0x00;
TL0 = 0x00;
ET0 = 1;
EA = 1;
TR0=1;
while (1) {
}
}