代码:
// GY-25
// ?????????STC89C52
// ???? 11.0592 M
// ???????LCD1602
// ???????9600
#include<REG52.H>
#include<math.h> //Keil library
#include<stdio.h> //Keil library
#include<INTRINS.H>
#define uchar unsigned char
#define uint unsigned int
//********???????*****************************
uchar BUF[10]; //?????????
uchar cnt=0; //?????????????
uchar sign=0;
int YPR[3];
//sbit FM=P2^3;
//sbit LED1=P0^1;
//********???庯??*****************************
void delay(unsigned int k);
void SeriPushSend(uchar send_data);
void display(void);
//*********************************************
//?????ж?
void serial_serve(void) interrupt 4
{
if(RI==1){ //?ж???
RI=0;
BUF[cnt]=SBUF;
cnt++; //???????
if(cnt==8) //
{
cnt=0; //
sign=1;
}
}
}
//*********************************************
//????????
//9600 bps @ 11.059 MHz
void init_uart()
{
TMOD=0x21;
TH1=0xfd;
TL1=0xfd;
SCON=0x50;
PS=1; //?????ж?????????????
TR0=1; //????????
TR1=1;
ET0=1; //???????0?ж?
ES=1;
}
//**********???????***************
void delay(unsigned int k)
{
unsigned int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<121;j++)
{;}
}
}
//*********???????????******************
void SeriPushSend(uchar send_data)
{
SBUF=send_data;
while(!TI);TI=0;
}
//*************************************
void dis_play(int num)
{ // LED1=0;
if(num<0)
{
num=-num;
SeriPushSend('-');
}
else
SeriPushSend('+');
SeriPushSend(0x30|(num/10000));
SeriPushSend(0x30|(num%10000/1000));
SeriPushSend(0x30|(num%1000/100));
SeriPushSend(0x2e);
SeriPushSend(0x30|(num%100/10));
SeriPushSend(0x30|(num%10));
SeriPushSend(',');
}
//*******************???????????**********************
void display(void)
{
if(sign){
sign=0;
if(BUF[0]==0XAA&&BUF[7]==0X55){ //???ж?
YPR[0]=(BUF[1]<<8|BUF[2]);
YPR[1]=(BUF[3]<<8|BUF[4]);
YPR[2]=(BUF[5]<<8|BUF[6]);
SeriPushSend('#');
SeriPushSend('Y');
SeriPushSend('P');
SeriPushSend('R');
SeriPushSend('=');
dis_play(YPR[0]);
dis_play(YPR[1]);
dis_play(YPR[2]);
SeriPushSend(0X0d);
SeriPushSend(0X0a);
//if(YPR[0]*100+YPR[1]*10+YPR[2]>30)
//{
// FM=0;
// }
}
}
}
//***************************************
//??????
void main()
{
delay(2000); //???
init_uart(); //?????????
EA=1; //?????ж?
cnt=0;
SeriPushSend(0XA5);
SeriPushSend(0X52); //????1???????????????
while(1){
display();
} //end while
}
|