发布时间 : 星期三 文章51单片机定时器实验报告更新完毕开始阅读8b7f76fa71fe910ef12df895
51单片机定时器实验
实验内容:
实验内容:
(1)编写程序使定时器0或者定时器1工作在方式1,定时50ms触发蜂鸣器。 C语言程序 #include
TMOD=0x01;
TH0=(65535-50000)/256; TH0=(65535-50000)%6; EA=1;
//开总中断
ET0=1; //开定时器0中断 TR0=1; while(1); }
void T0_time()interrupt 1 { } 汇编程序
ORG 0000H JAMP MAIN ORG 000BH TH0=(65535-50000)/256; TH0=(65535-50000)%6; FM=~FM;
LJMP INT0_INT ORG 0100H
MIAN: SETB EA
SETB ET0 AJMP $
INT0_INT:MOV R2,#0FAH
MOV R3,#0C8H DJNZ R3,$ DJNZ R2,INT0_INT RETI
(2)编写程序使定时器0或者定时器1工作在方式1,定时500ms使两位数码管从00、01、02……98、99每间隔500ms加1显示。 #include
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83, 0xc6,0xa1,0x86,0x8e}; //共阳极数码管0-F编码表 void main() {
TMOD=0x01;
TH0=(65535-50000)/256; TH0=(65535-50000)%6; EA=1;
//开总中断
ET0=1; //开定时器0中断 TR0=1;
while(1) }
void T0_time()interrupt 1 { }
void shumaguan() { P3=0x01; P2=table[shi]; delay(5); P3=0x02; P2=table[ge]; delay(5);
TH0=(65535-50000)/256; TH0=(65535-50000)%6; num1++; if(num1==10) { }
num1=0; num++; shi=num/10; ge=num; if(num==100) { num=0; }
{ }
shumaguan();
}
void zuoyi() { }
void delay(uint x) { }
(3)编写程序使定时器0或者定时器1工作在方式2,自动重装载模式,定时500ms使两位数码管从00、01、02……98、99每间隔500ms加1显示。 #include
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83, 0xc6,0xa1,0x86,0x8e}; //共阳极数码管0-F编码表 void main()
int i,j;
for(i=0;i for(j=0;j<110;j++); a=~P3; a=a<<1; P3=~a; if(P3==0xfb) { P3=0xfe; }