Haberler:

Foruma Resim Yükleme ve Boyut Sınırlaması ( ! )  https://bit.ly/2GMFb8H

Ana Menü

atmega16 usart sorunu

Başlatan satilla, 08 Ağustos 2012, 12:36:32

satilla

geçen gün çalıştırdıgım kodu bilgisayarımdan sildigim için tekrar yazmak zorunda kaldım
ancak bu defa mcu dan herhangi bir usart çıkışı alamıyorum
isiste herşey normla bir sorun yok ama pcb üzerinde hiç çıkış yok


#include <avr/io.h>
#include <avr/delay.h>
#include <inttypes.h>
#include <avr/interrupt.h>

# define F_CPU 8000000UL

char dizi[20]=" ";
unsigned char i=0,t,receive=0;
unsigned char p,k=0;

unsigned char PWM1=0;

volatile unsigned char ReceivedByte;
volatile char usartkontrol=0;

volatile unsigned char rf_alinan[10];
unsigned char Kullanici_1[10]={0xFF,0x01,0x06,0x10,0x40,0x00,0xAD,0x0F,0x27,0x3A};

//unsigned char Kullanici_1[]={'A','B','C','D','E','F','G','H','I','J'};


void uart_init(void)
{
UBRRL = 0x33;
UBRRH = (0x33>>8);
UCSRC=(1<<URSEL)|(3<<UCSZ0); // 8N1
UCSRB = ((1<<TXEN)|(1<<RXEN) | (1<<RXCIE)); // Enable receiver and transmitter and receive complete interrupt
}

void send_byte(unsigned char data)
{
	//gönderim registerı bosalana kadar bekle
	while (!(UCSRA & (1<<UDRE)) );
	
	UDR=data; //datayı gönder
}

unsigned char receive_byte(void)
{
	//data gelene kadar bekle
	while(!(UCSRA & (1<<RXC) ) );
	
	return UDR;
}
	
void send_string(char *str)
{
   while(*str!=0)
   {
   send_byte(*str++);
   }                   
 
}


/* Receive interrupt */
ISR(USART_RXC_vect)
{
	ReceivedByte = UDR;             //read UART register into value
	rf_alinan[usartkontrol]=ReceivedByte;
	usartkontrol++;
	if(usartkontrol==9)
	usartkontrol=0;
}

int main(void)
{
PORTA  =0x00;
PORTB  =0xFF;
PORTC  =0x00;
PORTD  =0x00;

DDRB=0xFD;
DDRD=0xFE;




	      
     

UBRRL = 0x33;
UBRRH = (0x33>>8);
UCSRC=(1<<URSEL)|(3<<UCSZ0); // 8N1
UCSRB = ((1<<TXEN)|(1<<RXEN) ); // Enable receiver and transmitter and receive complete interrupt

PORTD |=(1<<7);
_delay_ms(200);
_delay_ms(200);
PORTD &=~(1<<7);	   
 

	  


    while(1)
    {

/*		
if(rf_alinan[k]!=0x3A)		
if(rf_alinan[k]==Kullanici_1[k])
k++;
if(k==6)
PORTD |=(1<<7);
*/

	sprintf(dizi,"AT\r\n");
		send_string(dizi);

_delay_ms(200);
_delay_ms(200);		

		
    }
}