‘壹’ 单片机试题
12M振荡频率,最小定时周期为12/12M=1微妙,
50ms计时初值为为
TH1=(65536-50000)/256=#03CH
TL1=(65536-50000)%256=#0B0H
1S/50ms=20
所以计时器溢出100次为一秒
要求8051以查询方式工作
程序:
ORG 0000H
START: MOV TMOD,#01H ;TIMER1=MODE1
MOV TH1,#03CH ;TH1=(65536-50000)/256
MOV TL1,#0B0H ;TL1=(65536-50000)%256
SETB TR1 ;START TIMER1
LOOP1: MOV R0,#32H ;R0=20
LOOP2: JNB TF0,LOOP2 ;WAIT FOR OVERFLOW
DJNZ R0,LOOP2 ;是否到100次OVERFLOW
CLP P1 ;CLP P1
SJMP LOOP1 ;AGAIN AND AGAIN
END
‘贰’ 单片机定时器输出波形汇编程序
#include<reg51.h>
#define uchar unsigned char
uchar times;
sbit p10=P1^0;
void t1isr() interrupt 3
{
p10=~p10;
}
main()
{
TMOD=0x60;
TH1=251;
TL1=251;
TR1=1;
ET1=1;
EA=1;
while(1);
}