某一8051单片机系统,晶振频率为12mhz,现要从单片机的p1.7引脚输出一个连续

某一8051单片机系统,晶振频率为12mhz,现要从单片机的p1.7引脚输出一个连续的5hz的方波信号,请编写程序

#include<reg51.h>
#include<INTRINS.h>
#define u16 unsigned int
#define u8 unsigned char
sbit P17=P1^7;
u8 jsflag=0;
/****************************************/
void init() //初始化函数
{ TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;

}

/***********************************/
void main()//主函数
{
init();//系统初始化
TR0=1; //定时器开始计时
while(1){}

}

/****************************/
void timer0() interrupt 1//1ms定时器
{
TH0=(65536-50000)/256;//重载初值
TL0=(65536-50000)%256;
if(++jsflag>=2){
P17=!P17;jsflag=0;

}

}追问

有没有另一种方式的?

追答

#include
sbit P17=P1^7;

void Delay100ms() //@12.000MHz
{
unsigned char i, j;

i = 195;
j = 138;
do
{
while (--j);
} while (--i);
}

/***********************************/
void main()//主函数
{
while(1){

P17=!P17;

Delay100ms();
}

}

温馨提示:答案为网友推荐,仅供参考