#include <reg52.h>
#include <intrins.h>
#include <stdio.h>
#include <math.h>
#include <absacc.h>
#include <string.h>
sbit OUT=P0^4; //输出口p0.4
#define uchar unsigned char
#define uint unsigned int
unsigned int bili;
//void Delay1Ms(uint n); //延时t*1毫秒
void Hdelay1ms(void)
{
TMOD &= 0xF0;
TMOD |=0x01;
TH0 = 0xFC;
TL0 = 0x18;
TF0=0;//清除定时器溢出标志
TR0 = 1;//启动定时器
while(TF0==0);//等待计数完成
TR0=0;//停止定时器
}
void Delay1Ms(uint n)
{
unsigned int j;
for(j=n;j>0;j--)
Hdelay1ms();
}
void morse(unsigned char str,unsigned int speed)
{
bili=3;
if(str==0x00)
{
OUT=1;
Delay1Ms(speed);
OUT=0;
Delay1Ms(speed*bili);
}
if(str==0x01)
{
OUT=1;
Delay1Ms(speed);
OUT=0;
Delay1Ms(speed);
OUT=1;
Delay1Ms(speed);
OUT=0;
Delay1Ms(speed);
}
if(str==0x02)
{
OUT=1;
Delay1Ms(speed);
OUT=0;
Delay1Ms(speed);
OUT=1;
Delay1Ms(speed);
OUT=0;
Delay1Ms(speed);
OUT=1;
Delay1Ms(speed*bili);
OUT=0;
Delay1Ms(speed*bili);
}
}
void main(void)
{
bili=3;
morse(0x01,200);
OUT=1;
Delay1Ms(100);
OUT=0;
Delay1Ms(100);
} |