Google

Jul 6, 2008

AVR Interrupt in C

AVR programming in C interrupts

hey...most of you guys must have tried AVR interrupts in C.. I am trying to use UART receiver interrupt. I am using WinAVR.. I am including my code below, it looks it is branching to RESET.

the program is done by: niyaz zubair



int main(void)

{

unsigned char t1,t2;

long int i;

//configuring all ports



DDRA = 0xFF;

DDRB = 0xFF;

DDRC = 0xFF;

DDRD = 0xEF;



//for (i=0;i<10;i++)

// delay(4000);

lcdinitroutine();

cmdroutine(0x80);

dataroutine('s');

USART_Init(0x17);

USART_Transmit('A');

cmdroutine(0xC8);

dataroutine('Q');

while(1)

{

;

}

}



void USART_Init( unsigned char baud )

{

/* Set baud rate */

/* Enable receiver and transmitter, Rx complete
interrupt*/

UCSRB = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE);

/* Set frame format: 8data, 2stop bit,Even parity */

UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0)|(2<<UPM0);

/* Configuring for 1200 bps baus*/

UBRRH = 0;

UBRRL = 50;

/* Global Interrupt
Enable*/

SREG = SREG | (0x80);

}



void USART_Transmit( unsigned char data )

{



unsigned char letter;

letter ='A';

while(letter != 'Z')

{

/* Wait for empty transmit buffer */

while ( !( UCSRA & (1<<UDRE)))

;

cmdroutine(0x80);

dataroutine(letter);

/* Put data into buffer, sends the data */

UDR = letter;

letter ++;

}

}



ISR(SIG_UART_RECV)//ISR(USART_RXC_vect)//(USART0_RX_vectXS)

{

unsigned char data;



/* Read the received data */

data = UDR;

cmdroutine(0xC0);

dataroutine(data);

}



HEADER FILES INCLUDED ARE,



#include <stdio.h>

#include <math.h>

#include <avr/io.h>

#include <header.h>

#include <avr/interrupt.h>

#include <avr/signal.h>

#include <inttypes.h>



lcdinitroutine() and cmdroutine() are for LCD..


any comments plzzzzzz

guys it did work using.. the ISR as

SIGNAL (SIG_UART_RECV)

{

unsigned char data;



/* Read the received data */

data = UDR;

cmdroutine(0xC0);

dataroutine(data);

}


thanks

niyaz

You might be also interested in:

:: Interfacing Digital-To-Analog converter to 8086 using 8255
:: Temperature Control system using 8086
:: Traffic light control system using 8086

No comments: