中断方式:
ORG 0000H
JMP MAIN
ORG 000BH
JMP T0_INT
MAIN:
MOV TMOD, #01H
MOV TH0, #HIGH(65536-62500)
MOV TL0, #LOW (65536-62500)
SETB TR0
MOV A, #7FH
MOV P0, A
M_LOOP:
SJMP M_LOOP
;--------------------------------
T0_INT:
MOV TH0, #HIGH(65536-62500)
MOV TL0, #LOW (65536-62500)
DJNZ R7, T0_END
MOV R7, #32
RR A
MOV P0, A
T0_END:
RETI
;--------------------------------
END
;==========================
查询方式,最简单:
ORG 0000H
MOV TMOD, #01H
SETB TR0
MOV A, #7FH
M_LOOP:
MOV P0, A
MOV R7, #32
WAIT:
MOV TH0, #HIGH(65536-62500)
MOV TL0, #LOW (65536-62500)
JNB TF0, $
CLR TF0
DJNZ R7, WAIT
RR A
SJMP M_LOOP
END
unsigned char a,count;
void main()
{
P1=0xff;
a=0x01;
count=0
//**********************************//
TMOD=0x21; /*每2.5mS产生定时0中断,时钟11.0592MHZ*/
TH0=55536/256; //定时器0置为10ms定时器,
TL0=55536%256;
while(1)
{
;
}
}
void timer0() interrupt 1
{
TH0=55536/256; //重置定时器
TL0=55536%256;
count++;
if (count>199)
{
count=0;
P1=~a;
a<<=1;
if (a==0)
a=0x01;
}
}
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar temp, t0, t1;
bit t2;
sbit P10 = P1^0;
void main()
{
P10 = 1;
temp = 0xfe;
P0 = temp;
P2 = 0xff;
TMOD = 0x01;
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
ET0 = 1;
EA = 1;
TR0 = 1;
while(1);
}
void timer0() interrupt 1
{
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
t0++;
if(t0 == 10) {
t0 = 0;
t1++;
if(t1 == 8) {t1 = 0; t2 = ~t2; P10 = t2;}
temp = _crol_(temp, 1);
if(t2) {P0 = temp; P2 = 255;}
else {P2 = temp; P0 = 255;}
}
}
看着改改就能用了,不动的看我信息加我qq