[SOLVED] Atmega8 usart interrupt not stopping

Status
Not open for further replies.

Madara

Newbie level 5
Joined
Jan 6, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,335
Why does the code below send continous no of 'U' in proteus simulation virtual terminal.I am using winavr for programming atmega8
By putting "cli();" instruction in ISR should have disabled interrupt. but 'U' is being continuously delivered.
what is the problem here??


Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/wdt.h>
int main(void)
{
	UCSRC=0x86;
	UBRRH=0;
	UBRRL=0x67;
	UCSRB=0xF8; 
	sei();
	_delay_ms(200);
	while(1)
	wdt_reset();
}

ISR(USART_UDRE_vect)
{	
	cli();
	UDR='U';
}
 

avr interrupt program - avr studio 4

Code:
#include <avr/io.h>                   //UART INTERRUPT    11.0592Mhz
#define F_CPU 11059200UL
#include <util/delay.h>
#include <avr/interrupt.h>
#define SRL_DISP(c){ UDR=c;while(!(UCSRA&0x20));}   // UDRE BIT TESTING 
unsigned char x;

ISR(USART_RXC_vect)
{
x=UDR;
if(x=='A'||x=='a')
{
PORTC=0XFF;
SRL_DISP(' '); SRL_DISP('O');SRL_DISP('N');SRL_DISP(10);SRL_DISP(13);   
}

else if (x=='B'||x=='b')
{
PORTC=0X0;
SRL_DISP('O');SRL_DISP('F');SRL_DISP('F');SRL_DISP(10);SRL_DISP(13); 
} 
} 


main(void)
{
unsigned char i=0,arr[30]={"AVR UART INTERRUPT TEST  \n\r"};

SREG|=0X80;
DDRD =0XFE;
DDRC=0XFF;
PORTC=0;

UCSRB=0x98;    //8BIT //1 STOP BIT //NO PARITY //RXCIE ENABLE

UCSRC=0x86;    //ASYNC  

UBRRH=0x0;  

UBRRL=0x47;    //BDRT 9600   11.0592 

while(arr[i])
SRL_DISP(arr[i++]);

PORTC=0X0;

while (1);

}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…