#include <REGX52.H>
#define COMM_BAUD_RATE 9600 //?????
#define OSC_FREQ 11059200 //????:11.05926MHZ
static INT8U Send_buf[10] = {0} ; // em dịch thì nó báo lỗi ở dòng này mà k hiểu là lỗi gì và sửa thế nào.ai giúp e với ạ
void Delay_Ms(INT32U z)
{
INT32U x=0 , y=0;
for(x=110 ; x>0 ;x--)
for(y=z; y>0;y-- );
}
/************************************************** ****************************
- ????: ?? 1 ???
- ?: ??? 9600 ???
************************************************** ****************************/
void Serial_init(void)
{
TMOD = 0x20; // ?? T1 ???????
SCON = 0x50; // 0101,0000 8 ????, ?????
PCON = 0x00; //PCON=0;
TH1=256-(OSC_FREQ/COMM_BAUD_RATE/32/12);//??? 9600 ???
TL1=256-(OSC_FREQ/COMM_BAUD_RATE/32/12);
TR1 = 1; //??? 1 ??
REN = 1; //?? 1 ????
ES = 1; //?? 1 ????
}
void Uart_PutByte(INT8U ch)
{
SBUF = ch;
while(!TI){;}
TI = 0;
}
/************************************************** ****************************
- ????: ????????[???????]
- ????: CMD:??????,??????,??????????
feedback:??????[0:?????,1:????]
data:?????
************************************************** ****************************/
void SendCmd(INT8U len)
???????????? YX5300-24SS ?????
33
{
INT8U i = 0 ;
Uart_PutByte(0x7E); //??
for(i=0; i<len; i++)//??
{
Uart_PutByte(Send_buf[i]) ;
}
Uart_PutByte(0xEF) ;//??
}
/************************************************** ****************************
- ????:???? --- ??????????,?? 5.3.4 ???
- ????????:
?????,???????????? 6 ???????,??????????????
?????,????????????????,??????????????? 0.????
????????????
************************************************** ****************************/
void DoSum( INT8U *Str, INT8U len)
{
INT16U xorsum = 0;
INT8U i;
for(i=0; i<len; i++)
{
xorsum = xorsum + Str[i];
}
xorsum = 0 -xorsum;
*(Str+i) = (INT8U)(xorsum >>8);
*(Str+i+1) = (INT8U)(xorsum & 0x00ff);
}
void Uart_SendCMD(INT8U CMD ,INT8U feedback , INT16U dat)
{
Send_buf[0] = 0xff; //????
Send_buf[1] = 0x06; //??
Send_buf[2] = CMD; //????
Send_buf[3] = feedback;//??????
Send_buf[4] = (INT8U)(dat >> 8);//datah
Send_buf[5] = (INT8U)(dat); //datal
DoSum(&Send_buf[0],6); //??
SendCmd(8); //??????
}
void main()
{
Serial_init() ;//???????????
Uart_SendCMD(0x03 , 0 , 0x01) ;//?????
Delay_Ms(1000) ;//???? 6S
Uart_SendCMD(0x03 , 0 , 0x02) ;//?????
Delay_Ms(1000) ;//???? 6S
Uart_SendCMD(0x03 , 0 , 0x04) ;//?????
while(1);
}
#define COMM_BAUD_RATE 9600 //?????
#define OSC_FREQ 11059200 //????:11.05926MHZ
static INT8U Send_buf[10] = {0} ; // em dịch thì nó báo lỗi ở dòng này mà k hiểu là lỗi gì và sửa thế nào.ai giúp e với ạ
void Delay_Ms(INT32U z)
{
INT32U x=0 , y=0;
for(x=110 ; x>0 ;x--)
for(y=z; y>0;y-- );
}
/************************************************** ****************************
- ????: ?? 1 ???
- ?: ??? 9600 ???
************************************************** ****************************/
void Serial_init(void)
{
TMOD = 0x20; // ?? T1 ???????
SCON = 0x50; // 0101,0000 8 ????, ?????
PCON = 0x00; //PCON=0;
TH1=256-(OSC_FREQ/COMM_BAUD_RATE/32/12);//??? 9600 ???
TL1=256-(OSC_FREQ/COMM_BAUD_RATE/32/12);
TR1 = 1; //??? 1 ??
REN = 1; //?? 1 ????
ES = 1; //?? 1 ????
}
void Uart_PutByte(INT8U ch)
{
SBUF = ch;
while(!TI){;}
TI = 0;
}
/************************************************** ****************************
- ????: ????????[???????]
- ????: CMD:??????,??????,??????????
feedback:??????[0:?????,1:????]
data:?????
************************************************** ****************************/
void SendCmd(INT8U len)
???????????? YX5300-24SS ?????
33
{
INT8U i = 0 ;
Uart_PutByte(0x7E); //??
for(i=0; i<len; i++)//??
{
Uart_PutByte(Send_buf[i]) ;
}
Uart_PutByte(0xEF) ;//??
}
/************************************************** ****************************
- ????:???? --- ??????????,?? 5.3.4 ???
- ????????:
?????,???????????? 6 ???????,??????????????
?????,????????????????,??????????????? 0.????
????????????
************************************************** ****************************/
void DoSum( INT8U *Str, INT8U len)
{
INT16U xorsum = 0;
INT8U i;
for(i=0; i<len; i++)
{
xorsum = xorsum + Str[i];
}
xorsum = 0 -xorsum;
*(Str+i) = (INT8U)(xorsum >>8);
*(Str+i+1) = (INT8U)(xorsum & 0x00ff);
}
void Uart_SendCMD(INT8U CMD ,INT8U feedback , INT16U dat)
{
Send_buf[0] = 0xff; //????
Send_buf[1] = 0x06; //??
Send_buf[2] = CMD; //????
Send_buf[3] = feedback;//??????
Send_buf[4] = (INT8U)(dat >> 8);//datah
Send_buf[5] = (INT8U)(dat); //datal
DoSum(&Send_buf[0],6); //??
SendCmd(8); //??????
}
void main()
{
Serial_init() ;//???????????
Uart_SendCMD(0x03 , 0 , 0x01) ;//?????
Delay_Ms(1000) ;//???? 6S
Uart_SendCMD(0x03 , 0 , 0x02) ;//?????
Delay_Ms(1000) ;//???? 6S
Uart_SendCMD(0x03 , 0 , 0x04) ;//?????
while(1);
}