This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

External Interrupts 89c51 using Keil Compiler

Hi ,
I want to use external interrupts of 89C51 to receive/transmit data using sync modem.
Following is the C code i have written but
that is not working.I'm using evaluation version of Keil Compiler . I have following
doubts about ISR in C
1. Do we need to enable and disable the interrupt in its ISR to prohibit it to interrupt
unless its ISR is over.
2. It it necessary to specify the register bank ( using 1 ..... etc )
3. To set serial port baud rate do we need to set TCON regs , default C51 setting is
sufficient or not.
4. Do I need to modify startup.a51 file for this code.

Can anybody suggest me any other way to control sync modem ( source code or any url ) ?

thaks
Sanjay

/*;Program to Transmit data to GMSK CMX469 Modem
;Int0 -> Applied RxSync clock   used for data sending P3.2
;Int1 -> Applied Txsync clock  used for data receiving P3.3
;P1.0 -> Tx data
;P1.1 -> Rx data
;P1.2 -> Carrier Detect
*/
#include <reg51.h>
#include <stdio.h>
//void ReceiveData(void);				//to be called by interrupt ISR
//void TransmitData(void);				//to be called by interrupt ISR

void InitializeInterrupts(void);
void InitSerialPort(void);
static void INT0_ISR (void);				//RX Sync clock
static void INT1_ISR (void);				//TX sync clock
void main()
{
 InitSerialPort();
 InitializeInterrupts();
  while(1)
   {   P0=0xff;   P2=0xff; }
}
static void INT1_ISR (void) interrupt 2 using 1                      //for tx
{
	EX1=0;   //disable int1
      P2=0x00;  // making it zero to know whether intr has ocured on falling edge
//	TransmitData(); 	//function to tranmit data
	EX1=1;   //enable int1
}
static void INT0_ISR (void) interrupt 0 using 1                          //for receive
{
	EX0=0;   //disable int0
      P0=0x00;  // making it zero to know whether intr has ocured on falling edge
		  //ReceiveData(); 	  //function to receive data
	EX0=1;   //enable int0
}
void InitializeInterrupts(void)
 {
		EX0=1;
		IT0=1;		//falling edge
		EX1=1;
		IT1=1;		//falling edge
		EA=1;
}
void InitSerialPort(void)
{
  SCON = 0x52;    /* SCON */                   /* setup serial port control */
  TMOD = 0x20;    /* TMOD */                   /* hardware (9600 BAUD @12MHZ) */
  TCON = 0x69;    /* TCON */
  TH1 =  0xfd;    /* TH1 */      //9600 baud rate
  TR1=1;
  printf("\nModem Program is running\n");
}

Parents

  • 1. Do we need to enable and disable the interrupt in its ISR to prohibit it to interrupt unless its ISR is over.

    No you do not need to do this. An interrupt cannot itself be interrupted except by an interrupt of a higher priority.

    You do not seem to be implementing any high priority interrupts, so no problem.

    2. It it necessary to specify the register bank ( using 1 ..... etc )

    No, it is not absolutly necessary. In general it is best to specify a register bank because it makes context switching quicker. However, if an ISR is quite trivial, not specifying a register bank can actually result in quicker code.

    3. To set serial port baud rate do we need to set TCON regs , default C51 setting is
    sufficient or not.


    4. Do I need to modify startup.a51 file for this code.

    No, that should not be necessary. Interrupt vectors (is that what you have in mind) etc are all taken care of by the compiler.

Reply

  • 1. Do we need to enable and disable the interrupt in its ISR to prohibit it to interrupt unless its ISR is over.

    No you do not need to do this. An interrupt cannot itself be interrupted except by an interrupt of a higher priority.

    You do not seem to be implementing any high priority interrupts, so no problem.

    2. It it necessary to specify the register bank ( using 1 ..... etc )

    No, it is not absolutly necessary. In general it is best to specify a register bank because it makes context switching quicker. However, if an ISR is quite trivial, not specifying a register bank can actually result in quicker code.

    3. To set serial port baud rate do we need to set TCON regs , default C51 setting is
    sufficient or not.


    4. Do I need to modify startup.a51 file for this code.

    No, that should not be necessary. Interrupt vectors (is that what you have in mind) etc are all taken care of by the compiler.

Children