本帖最后由 zhihuizhou 于 2012-2-17 15:54 编辑
更多51单片机定时器知识请进入专题:http://bbs.elecfans.com/topic-dingshiqi.html
各位前辈帮我看看下面代码:
希望流水灯200ms闪烁,数码管前两位实现59s循环计时。
注led1及段选位选IO均无误。
keil出现如下两个警告。
开发板无误,下载无误。
连接中...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?INIT?数_隷躝╛_禵__蔩_?
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?_DISPLAY?数_隷躝╛_禵__蔩_?
Program Size: data=14.0 xdata=0 code=191
正在从 "数码管(中断延时)" 产生 HEX文件...
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit LED1=P1^0;
sbit WE=P2^7;
sbit DU=P2^6;
uchar counter0,counter1,num,shi,ge;
uchar code table[]={0x3f,0x06,0x5b,
0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};
void init()
{
TMOD=0X11;
TH0=(65536-46080)/265;
TL0=(65536-46080)%265;
TH1=(65536-46080)/265;
TL1=(65536-46080)%265;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
void
timer0() interrupt 1
{
TH0=(65536-46080)/265;
TL0=(65536-46080)%265;
counter0++;
}
void timer1() interrupt 3
{
TH0=(65536-46080)/265;
TL0=(65536-46080)%265;
counter1++;
}
void delay(uchar x)
{
uchar i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar shi,uchar ge)
{
DU=1;
P0=table[shi];
DU=0;
P0=0Xff;
WE=1;
P0=0Xfe;
WE=0;
delay(5);
DU=1;
P0=table[ge];
DU=0;
P0=0Xff;
WE=1;
P0=0Xfd;
WE=0;
delay(5);
}
void main()
{
void init();
while(1)
{
if(counter0==4)
{
counter0=0;
LED1=~LED1;
}
if(counter1==20)
{
counter1=0;
num++;
if(num==60)
{
num=0;
}
shi=num/10;
ge=num%10;
}
}
}
-
定时器
一周热门 更多>