#include
sbit out = P3^7;
unsigned int t1 = 0;
void main()
{
TMOD = 0x01;
TH0 = (65536 - 3333) / 256; //定时3.3ms, 12MHz
TL0 = (65536 - 3333) % 256; //定时 10ms, 4MHz
TR0 = 1;
ET0 = 1;
EA = 1;
while(1);
}
void time0() interrupt 1
{
TH0 = (65536 - 3333) / 256; //定时3.3ms, 12MHz
TL0 = (65536 - 3333) % 256; //定时 10ms, 4MHz
t1++;
if(t1 == 2000) t1 = 0; //20s为一个周期
if(t1 < 500) out = ~out; //小于5s, 取反
else out = 1; //5s~20s, 输出1
}
已经调试成功。
#include
#define uchar unsigned char
#define uint unsigned int
sbit k1=P3^5;
sbit out=P0^0;
uint t1=0;
bit flag=0;
void main()
{
TMOD=0X01;
TH0=(65536-3333)/256;//定时时间=(65536-T0初值 )*(1/4)*12
TL0=(65536-3333)%256;
TR0=1;
ET0=1;
EA=1;
out=0;
while(1)
{
if(t1==500)
{
out=1;
}
if(t1==1500)
{
out=0;
t1=0;
}
}
}
void time0() interrupt 1
{
TH0=(65536-3333)/256;
TL0=(65536-3333)%256;
t1++;
flag=~flag;
if(t1<500)
{
if(flag==1)
{
out=0;
}
else
{
out=1;
}
}
}
3.14159 26535 89793 23846 26433
83279 50288 41971 69399 37510
58209 74944 59230 78164 06286
20899 86280 34825 34211 70679
82148 08651 32823 06647 09384
46095 50582 23172 53594 08128
无限不循环
要求哪个引脚输出呢?
我经常做