Interrupt disable comman #asm("cli"); not working

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,554
hi,

I am working on a hotline system where 8 telephone lines are connected to a microcontroller. I have o detect whether phone is on hook or off hook and ring the particular telephone. I decided of using timer 1 interrupt for generating the ring for particular frequency i.e. 50hz for now. So i am enabling the interrupt using #asm("sei"); command.When another phone is getting Off hook i want to stop the ringing so i thought of using #asm("cli"); command to disable the interrupt. Code is as follows.

Code:
#include <mega16.h>
#include <delay.h>

#define phn_1  PINA.0
#define phn_2  PINA.1
#define phn_3  PINA.2
#define phn_4  PINA.3
#define phn_5  PINA.4
#define phn_6  PINA.5
#define phn_7  PINA.6
#define master  PORTA.7

#define phn_8  PINC.0
#define phn_9  PINC.1
#define phn_10 PINC.2
#define phn_11 PINC.3
#define phn_12 PINC.4
#define phn_13 PINC.5
#define phn_14 PINC.6
#define phn_15 PINC.7

#define phn_16 PIND.6
#define ring  PORTD.5

unsigned int i=0;
bit a;
//bit b;
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
TCNT1H=0xB1;
TCNT1L=0xDF;
// Place your code here
   ring=1;

}

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=Out Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x80;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=0 State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x08;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=0 State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x20;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Toggle on compare match
TCCR0=0x10;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x02;
TCNT1H=0xB1;
TCNT1L=0xDF;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// Global enable interrupts
   
    ring = 0;
//#asm("sei")
    
while (1)
      {
      // Place your code here
      //master = ~master;

      if(phn_10  ==0 ){          
        while(phn_11==1){      //ring till another phone if On hook
             //delay_ms(5);
             #asm("sei");
             do{

             }while(phn_11==1); 
             #asm("cli");             
       }
      }

      };
}

But #asm("cli"); command is bot working. Controller is Atmega 16 and compiler is Code Vision AVR. What should i do?
 

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…