hardik.patel
Member level 5
- Joined
- Aug 15, 2012
- Messages
- 94
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 2,008
Xtal-11.0592
compiler - avr gcc
here i had write code in which i used INT2 n serial interrupt for different task.
INT2 is working fine, but as serial interrupt comes...it goes in its routine (it goes to compare())...but it not back from its routine to main().
main.c
my_uart.c
- - - Updated - - -
complete code is in .rar file
compiler - avr gcc
here i had write code in which i used INT2 n serial interrupt for different task.
INT2 is working fine, but as serial interrupt comes...it goes in its routine (it goes to compare())...but it not back from its routine to main().
main.c
Code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include<compat/deprecated.h>
#include <inttypes.h>
#include<my_uart.c>
#include<fan.c>
#include<my_eeprom.c>
#include<device_define.c>
//#include<compare.c>
#include <rtc.c>
#include <disp.c>
#include <disp1.c>
char data;
char a,b,c,d,e,f=0;
void init_interrupt2()
{
GICR |= (1<<INT2); // Enable external interrupt INT2
MCUCSR |= (1<<ISC2); // INT2 is executed on rising edge
// sei(); //
}
ISR(INT2_vect)
{
set_pattern();
//alarm_set_ok=0;
alarm_set();
}
ISR (USART_RXC_vect)
{
compare();
}
void compare()
{
int flag=0;
int d0,d1,d2,d3,d4,d5,d6,d7,d8=0;
//int d8,d9,d10,d11,d12=0;
//b4_power();
//speed_eeprom();
//while(1)
//{
data=USARTReadChar(); a=data; USARTWriteChar(a);//_delay_ms(5);
data=USARTReadChar(); b=data; USARTWriteChar(b);//_delay_ms(5);
data=USARTReadChar(); c=data; USARTWriteChar(c);//_delay_ms(5);
data=USARTReadChar(); d=data; USARTWriteChar(d);//_delay_ms(5);
data=USARTReadChar(); e=data; USARTWriteChar(e);//_delay_ms(5);
if((a=='8') && (flag==0))
{
flag=1;
}
if((b=='0') && (flag==1))
{
flag=2;
}
if((c=='2') && (flag==2))
{
flag=3;
}
if((d=='1') && (flag==3))
{
flag=4;//PORTC=0x01;
}
if((flag==4) && (e=='A'))
{
tbi(PORTC,PC2); //here the toggling takes place
d0 = bit_is_set(PINC,2); //status of PC0 wheather CLEARED/SET is stored in d0
if(d0>0){ EEPROMWrite(1,0); }
else{ EEPROMWrite(1,1); } // That status of d0 will be store at 0th EEPROM Location
}
if((flag==4) && (e=='B'))
{
tbi(PORTC,PC3);
d1 = bit_is_set(PINC,3);
if(d1>0)
{ EEPROMWrite(2,0); }
else{ EEPROMWrite(2,1); }
}
if((flag==4) && (e=='C'))
{
tbi(PORTC,PC4);
d2 = bit_is_set(PINC,4);
if(d2>0)
{ EEPROMWrite(3,0); }
else{ EEPROMWrite(3,1); }
}
if((flag==4) && (e=='D'))
{
tbi(PORTC,PC5);
d3 = bit_is_set(PINC,5);
if(d3>0)
{ EEPROMWrite(4,0); }
else{ EEPROMWrite(4,1); }
}
if((flag==4) && (e=='E'))
{
tbi(PORTC,PC6);
d4 = bit_is_set(PINC,6);
if(d4>0)
{ EEPROMWrite(5,0); }
else{ EEPROMWrite(5,1); }
}
if((flag==4) && (e=='F'))
{
tbi(PORTC,PC7);
d5 = bit_is_set(PINC,7);
if(d5>0)
{ EEPROMWrite(6,0); }
else{ EEPROMWrite(6,1); }
}
/////////////////////////////////////////////////////////////////////////////
if((flag==4) && (e=='G'))
{
tbi(PORTD,PD5); //here the toggling takes place
d6 = bit_is_set(PIND,5); //status of PC0 wheather CLEARED/SET is stored in d0
if(d6>0){ EEPROMWrite(7,0); }
else{ EEPROMWrite(7,1); } // That status of d0 will be store at 0th EEPROM Location
}
if((flag==4) && (e=='H'))
{
tbi(PORTD,PD6);
d7 = bit_is_set(PIND,6);
if(d7>0)
{ EEPROMWrite(8,0); }
else{ EEPROMWrite(8,1); }
}
//if((flag==4) && (e=='I'))
//{
// tbi(PORTD,PD6);
// d8 = bit_is_set(PIND,6);
// if(d8>0)
// { EEPROMWrite(9,0); }
// else{ EEPROMWrite(9,1); }
//}
//if((flag==4) && (e=='J'))
//{
// tbi(PORTA,PA1);
// d9 = bit_is_set(PINA,1);
// if(d9>0)
// { EEPROMWrite(10,0); }
// else{ EEPROMWrite(10,1); }
//}
//if((flag==4) && (e=='K'))
//{
// tbi(PORTA,PA2);
// d10 = bit_is_set(PINA,2);
// if(d10>0)
// { EEPROMWrite(11,0); }
// else{ EEPROMWrite(11,1); }
//}
//if((flag==4) && (e=='L'))
//{
// tbi(PORTA,PA3);
// d11 = bit_is_set(PINA,3);
// if(d11>0)
// { EEPROMWrite(12,0); }
// else{ EEPROMWrite(12,1); }
//}
//if((flag==4) && (e=='M'))
//{
// tbi(PORTA,PA4);
// d12 = bit_is_set(PINA,4);
// if(d12>0)
// { EEPROMWrite(13,0); }
// else{ EEPROMWrite(13,1); }
//}
//////////////////////////////////////////////////////////////////////////////////////
if((flag==4) && (e=='N')) //STATUS
{
fan_status();
}
if((flag==4) && (e=='O')) // MINUS
{
fan_speed_minus();
}
if((flag==4) && (e=='P')) //MAXIMUM
{
fan_speed_plus();
}
//goto out_while;
//}
}
int main(void)
{
DDRA=0XFF; //7seg data port
DDRB=0xF0; //bit 4-7 as i/p for switch for Alarm setting + bit 0-3 as o/p for 7seg control
DDRC=0xFC; // PC0-PC1 i/p for SCL & SDA rest all o/p
DDRD=0xFE; //PD0 as RX i/p rest all o/p
USARTInit(71); //UBRR = 71, 9600 at 11.0592Mhz
init_interrupt2();
// sei();
//RTC_write_data();
//PORTD=0x03;
b4_power();
speed_eeprom();
while(1)
{
RTC_read_data(); //_delay_ms(1000);
match(); //_delay_ms(1000);
//compare();
//buzzer_off; _delay_ms(500);
//buzzer_on; _delay_ms(500);
}
}
my_uart.c
Code:
#include <avr/io.h>
void USARTInit(uint16_t ubrr_value)
{
UBRRL = ubrr_value;
UBRRH = (ubrr_value>>8);
//UCSRC=(1<<URSEL)|(3<<UCSZ0);
//UCSRB=(1<<RXEN)|(1<<TXEN);
UCSRB |= (1 << RXEN ) | (1 << TXEN ); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL ) | (1 << UCSZ0 ) | (1 << UCSZ1 ); // Use 8- bit character sizes
//UCSRB = (1<<TXEN) | (1<<RXEN) | (1<<RXCIE);
UCSRB |= (1 << RXCIE );
//UCSRB = (1 << RXCIE );
//UCSRC = 1<<URSEL | 1<<UCSZ1 | 1<<UCSZ0 ;
sei ();
}
char USARTReadChar()
{
while(!(UCSRA & (1<<RXC)))
{
//Do nothing
}
return UDR;
}
void USARTWriteChar(char data)
{
while(!(UCSRA & (1<<UDRE)))
{
//Do nothing
}
UDR=data;
}
- - - Updated - - -
complete code is in .rar file
Attachments
Last edited: