求助 mega8a 接收不到数据
mage8a怎么接收不到数据呢 ?可以发送 哪位老大 懂的 帮帮兄弟吧 422 通信的/*
* CY121010.c
*
* Created: 2012/10/10 8:29:24
*Author: QC
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
unsigned char SendFlag;
unsigned char RecvData;
unsigned int count;
void init(void);
unsigned char USART_Receive( void );
void USART_Transmit( unsigned char data );
void SIG(TIMER0_OVF_vect);
void PSendData(void);
void GetKey(void);
void PKey(void);
/***********************************************************************************************
*
*
*
*
************************************************************************************************/
void USART_Init( unsigned int baud )
{
/* 设置波特率*/
UBRRH = (unsigned char)(baud>>8);
UBRRL = (unsigned char)baud;
/* 接收器与发送器使能*/
UCSRB = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE);
/* 设置帧格式: 8 个数据位, 2 个停止位*/
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0)|(3<<UPM0);
}
unsigned char USART_Receive( void )
{ PORTD &=0xfb;
/* 等待接收数据 */
while ( !(UCSRA & (1<<RXC)) )
;
return UDR;
}
void USART_Transmit( unsigned char data )
{
/* 等待发送缓冲器为空 */
while ( !( UCSRA & (1<<UDRE)) )
;
/* 将数据放入缓冲器,发送数据 */
UDR = data;
_delay_ms(1);
}
int main(void)
{PORTB=0xff;
//PORTB &=0x04;
DDRB=0xff;
USART_Init(12);
while(1)
{ // USART_Transmit(0xaa);
RecvData=USART_Receive();//写入RecvData;
_delay_ms(1);
USART_Transmit(0x00);
// PORTB ^= (1<<7);
//_delay_ms(1000);
}
}
{:cry:}找了好久 找不出问题快谁遇到过这样的问题帮帮我吧 不知道是不是这个原因 yklstudent 发表于 2012-10-29 19:46 static/image/common/back.gif
不知道是不是这个原因
什么意思? 系统时钟频率多少。
UBRR = 12
1M对应4800
8M对应38400 问题已经解决 谢谢!硬件422 与232出现问题了
页:
[1]