|||
//P1前四个IO接L298N
#include<reg51.h>
unsigned int PWM=5000;
//定时器初始化
void InitTimer(void)
{
TMOD=0x11;
EA=1;
//开启T0和T1的中断
ET0=1;
ET1=1;
//定义10ms
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
//定义PWM
TH0=(65536-PWM)/256;
TL0=(65536-PWM)%256;
//开启定时器0和1
TR0=1;
TR1=1;
P1&=0xf0;
}
//T0的中断服务程序
void T0ISR(void) interrupt 1
{
P1&=0xf0;
TR0=0;
TH0=(65536-PWM)/256;
TL0=(65536-PWM)%256;
}
//T1的中断服务程序
void T1ISR(void) interrupt 3
{
P1=0x0a;
TR0=1;
//定义10ms
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
}
void main(void)
{
P1&=0xf0;
InitTimer();
while(1)
{
}
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-13 01:07
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社