我用串口调试助手来接收单片机串口出来的信号,但是,没有任何反应。无论是我用51的还是atmega128单片机… 5

以下发一段atmega128的程序,串口应该会有输出的把。我用max232接PE0PE1和地的,然后另一端接电脑的串口转USB线。用串口调试助手接收信息,但是没有任何信息... 以下发一段atmega128的程序,串口应该会有输出的把。我用max232接PE0 PE1和地的,然后另一端接电脑的串口转 USB 线。用串口调试助手接收信息,但是没有任何信息。
#include <iom128v.h>
#include <macros.h>

#define uchar unsigned char
#define uint unsigned int
#define baud 9600
#define fosc 16000000
#define dron PORTC|= BIT(1)
#define droff PORTC&=~BIT(1)
#define clkon PORTC|=BIT(0)
#define clkoff PORTC&=~BIT(0)
#define stbon PORTA|=BIT(4)
#define stboff PORTA&=~BIT(4)
#define oeon PORTA|=BIT(5)
#define oeoff PORTA&=~BIT(5)
uchar line; //col为位移变量,disrow为行变量
uchar i,j,temp;
void sendbyte(uchar val);//发送一线点阵数据
void uart0_init(void);

void delay(uchar t)
{uchar a;
while(i--){
for(a=0;a<255;a++);
}
}

/***********************汉字点阵码*************************/
uchar nei[32]=
{
0x80,0x00,0x80,0x00,0x80,0x00,0xFC,0x3F,0x84,0x20,0x84,0x20,0x84,0x21,0x44,0x22,/*"内",0*/
0x44,0x24,0x24,0x28,0x14,0x28,0x0C,0x20,0x04,0x20,0x04,0x20,0x04,0x28,0x04,0x10
};
uchar niu[32]=
{
0x00,0x01,0x08,0x01,0x08,0x01,0xF8,0x3F,0x04,0x01,0x04,0x01,0x02,0x01,0x00,0x01,/*"牛",1*/
0xFE,0x7F,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x00
};
uchar man[32]=
{
0x82,0x08,0x84,0x08,0xF4,0x7F,0x80,0x08,0x01,0x00,0xEA,0x7F,0x8A,0x04,0xE8,0x3F,/*"满",2*/
0xA4,0x24,0xA4,0x24,0xA4,0x2D,0x63,0x32,0x22,0x21,0x22,0x20,0x22,0x28,0x22,0x10
};
uchar mian[32]=
{
0x00,0x00,0xFE,0x7F,0x40,0x00,0x20,0x00,0xFC,0x3F,0x24,0x22,0x24,0x22,0xE4,0x23,/*"面",3*/
0x24,0x22,0x24,0x22,0xE4,0x23,0x24,0x22,0x24,0x22,0xFC,0x3F,0x04,0x20,0x00,0x00
};

void main(void){
PORTA = 0xff;
DDRA = 0xff;
PORTE = 0xff;
DDRE = 0xff;
uart0_init;
while(1)
{
for(line=0;line<16;line++)//扫描16行
{
stboff;
sendbyte(nei[line*2]);
sendbyte(nei[line*2+1]);
sendbyte(niu[line*2]);
sendbyte(niu[line*2+1]);
sendbyte(man[line*2]);
sendbyte(man[line*2+1]);
sendbyte(mian[line*2]);
sendbyte(mian[line*2+1]);
PORTA = line;
oeoff;
stbon;
}
}
}

/***************发送一线点阵数据*******************/
void sendbyte(uchar val)
{
while(!(UCSR0A&(1<<UDRE0)));
UDR0=val;
}

void uart0_init(void)
{
UCSR0B=0x00;
UCSR0A=0x00;
UCSR0C=(1<<UCSZ01)|(1<<UCSZ00);
UBRR0L=(fosc/16/(baud+1))%256;
UBRR0H=(fosc/16/(baud+1))/256;
UCSR0B=(1<<RXEN0)|(1<<TXEN0);
}
展开
 我来答
司寇恨枫
2011-05-14 · TA获得超过392个赞
知道答主
回答量:653
采纳率:0%
帮助的人:0
展开全部
1.我看了一下你的程序.如果你用的是11.0592的晶振,那么你的初值不对.
2.Select Case MSComm1.CommEvent '接收单片机发过来的1字节数据
Case comEvReceive
MSComm1.RThreshold = 0'这一句不要用.
strBuff = MSComm1.Input
Text1.Text = Trim(Val(strBuff))
MSComm1.InBufferCount = 0 '清空接收缓冲区这一句也别要.然后再试下.
End Select

MSComm1.RThreshold = 1
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式