【023】定时器和软计数器中断方式实现1个LED隔1s闪一次2007-05-02 12:35:00
【评论】
【打印】
【字体:大 中 小】
本文链接:http://blog.pfan.cn/wentao/25459.html
org 0000h
ajmp start
org 000bh
ajmp time0
org 0030h
start: clr p1.0
mov 30h,#0x00
mov tmod,#00000001b
mov th0,#0x3c
mov tl0,#0xb0
setb ea
setb et0
setb tr0
lop: ajmp lop
time0:
push acc
push psw
inc 30h
mov a,30h
cjne a,#10,next
cpl p1.0
mov 30h,#0
next: mov th0,#0x3c
mov tl0,#0xb0
pop psw
pop acc
reti
end
#include <reg51.h>
sbit P10 = P1^0;
unsigned char count = 0;
main()
{
P10 = 0;
TMOD = 0x01;
TH0 = 0x3c;
TL0 = 0xb0;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1);
}
void time0_int(void) interrupt 1
{
count++;
if (count == 10)
{
P10 = !P10;
count = 0;
}
TH0 = 0x3c;
TL0 = 0xb0;
}
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define fosc 11.0592 // 晶振频率
#define time0 50000 // 欲定时50ms(50000us)
sbit P10 = P1^0;
uchar count = 0;
uchar data time0_h;
uchar data time0_l;
uint idata time0_tmp;
main()
{
P10 = 0;
TMOD = 0x01;
time0_tmp = 65536 - time0 * fosc / 12;
time0_h = (time0_tmp / 256);
time0_l = (time0_tmp % 256);
TH0 = time0_h;
TL0 = time0_l;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1);
}
void time0_int(void) interrupt 1
{
count++;
if (count == 10)
{
P10 = !P10;
count = 0;
}
TH0 = time0_h;
TL0 = time0_l;
}
#include <reg51.h>
#define led_off P1 |= (1<<0) // 置位P1.0,LED灭
#define led_on P1 &= ~(1<<0) // 清零P1.0,LED亮
unsigned char count = 0;
unsigned char flag = 1;
main()
{
led_on;
TMOD = 0x01;
TH0 = 0x3c;
TL0 = 0xb0;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1);
}
void time0(void) interrupt 1
{
count++;
if (count == 10)
{
if(flag)
led_off, flag = 0;
else
led_on, flag = 1;
count = 0;
}
TH0 = 0x3c;
TL0 = 0xb0;
}
阅读(4459) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论