|
近期搞了一個(gè)傳感器模塊A和一個(gè)音樂(lè)模塊B,A傳感器串口輸出AA 55 01 02 03的數(shù)據(jù)一共有10組,模塊B一共有30個(gè)觸發(fā)串口地址為 55 03 11 01 02 ,55 03 11 02 02,55 04 01 03 02類似格式的數(shù)據(jù),比如單片機(jī)收到傳感器AA 55 01 02 03數(shù)據(jù)后,讓它TXd口輸出 55 03 11 01 02,然后再過(guò)1秒輸出 55 03 11 02 02到B模塊。意思就是收到X,發(fā)送Y延時(shí)1秒發(fā)送Z,怎么寫(xiě)這部分代碼,我絞盡腦汁也沒(méi)弄好請(qǐng)求大神幫忙
單片機(jī)源程序如下:
//晶振為11.0592Mhz 波特率9600
#include "reg52.h"
#define uint unsigned int
sbit d=P1^5;
sbit a=P1^1;
uint x,y,z;
void delay(z); //聲明子函數(shù)
void UART_Init()
{
SCON=0x50;
PCON |=0X80;
TMOD &=0x0f;
TMOD |=0x20;
TL1=0XFD;
TH1=0XFD;
TF1=0;
TR1=1;
ET1=0;
EA=1;
ES=1;
}
void main()
{
UART_Init();
while(1)
{
}
}
void UART_SendByte(unsigned char Byte)
{
SBUF=Byte;
while(TI==0);
TI=0;
}
void UART_Routine() interrupt 4
{
if(RI==1)
{
RI=0;
UART_SendByte(SBUF);
}
}
void delay(z)
{
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
|
|