#include<intrins.h>
#define uchar unsigned char
uchar cnt,times
void delay()
{
uchar i
TMOD=0x01
TH0=(65536-50000)/256
TL0=(65536-50000)%256
TR0=1
for(i=0i<timesi++)
{
while(TF0==0)
TH0=(65536-50000)/256
TL0=(65536-50000)%256
TF0=0
}
TR0=0
}
void ext0() interrupt 0
{
uchar i,j
P1=0xfe
times=8
for(i=0i<5i++)
{
for(j=0j<8j++)
{
P1=_crol_(P1,1)
delay()
}
}
}
void ext1() interrupt 2
{
uchar i,j
P1=0x7f
times=12
for(i=0i<3i++)
{
for(j=0j<8j++)
{
P1=_cror_(P1,1)
delay()
}
}
}
main()
{
EX0=1
EX1=1
IT0=0
IT1=1
PX0=0
PX1=1
while(1)
}
中断#include <REGX52.H>
sbit PWM=P2^0
void InitTimer1(void)
{
TMOD = 0x10
TH1 = 0x0FC
TL1 = 0x18
EA = 1
ET1 = 1
TR1 = 0
EX1=1
IT1=1
}
void main(void)
{
InitTimer1()
while(1)
}
void Timer1Key(void) interrupt 2
{
TR1=~TR1
}
void Timer1Interrupt(void) interrupt 3
{
TH1 = 0x0FC
TL1 = 0x18
PWM=~PWM
}
查询
#include <REGX52.H>
sbit PWM=P2^0
sbit key=P3^3
void InitTimer1(void)
{
TMOD = 0x10
TH1 = 0x0FC
TL1 = 0x18
EA = 1
ET1 = 1
TR1 = 0
}
void main(void)
{
InitTimer1()
while(1)
if(key==0)TR1 = 1
}
void Timer1Interrupt(void) interrupt 3
{
TH1 = 0x0FC
TL1 = 0x18
PWM=~PWM
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)