注册会员
- 积分
- 189
- 威望
- 111
- 贡献
- 40
- 兑换币
- 60
- 注册时间
- 2013-7-19
- 在线时间
- 19 小时
- 毕业学校
- 福州大学
|
我用51模拟一段波形 ,可是在虚拟示波器上怎么也显示不了波形,接线我是51的TXD端口接下载器的RXD,程序如下:
#include <reg52.H>
#include <intrins.H>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
float OutData[4] = { 0 };
unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT)
{
unsigned short CRC_Temp;
unsigned char i,j;
CRC_Temp = 0xffff;
for (i=0;i<CRC_CNT; i++){
CRC_Temp ^= Buf[i];
for (j=0;j<8;j++) {
if (CRC_Temp & 0x01)
CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
else
CRC_Temp = CRC_Temp >> 1;
}
}
return(CRC_Temp);
}
void send(uchar c)
{
SBUF=c;
while(TI==0);
TI=0;
ES=1;
}
void OutPut_Data(void)
{
int temp[4] = {0};
unsigned int temp1[4] = {0};
unsigned char databuf[10] = {0};
unsigned char i;
unsigned short CRC16 = 0;
for(i=0;i<4;i++)
{
temp[i] = (int)OutData[i];
temp1[i] = (unsigned int)temp[i];
}
for(i=0;i<4;i++)
{
databuf[i*2] = (unsigned char)(temp1[i]%256);
databuf[i*2+1] = (unsigned char)(temp1[i]/256);
}
huo
CRC16 = CRC_CHECK(databuf,8);
databuf[8] = CRC16%256;
databuf[9] = CRC16/256;
for(i=0;i<10;i++)
send(databuf[i]);
//uart_putchar(databuf[i]);
}
void main(void)
{
float temp = 0.0;
SCON=0x50; //串口方式1
TMOD=0x20; //定时器1,定时方式为2
PCON=0x00; //设定串口工作方式1/64
TCON=0x40; //设定时器1开始计数
TH1=0xfd; //设定波特率为9600
TL1=0xfd;
TR1=1;
EA=1;
ES=1;
while(1)
{
for(temp = 0; temp <= 3.14*2; temp += 0.1)
{
OutData[0] = sin(temp)*(float)1000;
OutData[1] = sin(temp-3.14/4)*(float)1000;
OutData[2] = sin(temp+3.14/4)*(float)1000;
OutData[3] = sin(temp+3.14/2)*(float)1000;
OutPut_Data();
}
}
}
或者哪位大神能把能用的程序拿出来,,,感激不尽!!!!
|
|