Keil Logo Arm Logo

External Interrupts 89c51 using Keil Compiler

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Sanjay Kumar
Posted
17-Jun-2004 05:36 GMT
Toolset
C51
New! 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");
}
Read-Only
Author
Graham Cole
Posted
17-Jun-2004 09:08 GMT
Toolset
C51
New! RE: External Interrupts 89c51 using Keil Compiler

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.
Read-Only
Author
Sanjay Kumar
Posted
17-Jun-2004 10:11 GMT
Toolset
C51
New! RE: External Interrupts 89c51 using Keil Compiler
Thanks alot Mr. Graham Cole for ur quick reply. In my C code as a result of External interrupts I expect sharp pulse at port P0 and P2 during falling edge of the clock pulse applied on the INT0 and INT1 pins. I observed the result ,instead of sharp pulse many transitions i'm getting. What may be the problem Pls reply. One more doubt: during executing ISR is there any chance of corrupting the previous data.Do we need to do push pop like thing in ISR or its taken care in Keil Compiler

thanks again for ur reply
Sanjay
Read-Only
Author
Stefan Duncanson
Posted
17-Jun-2004 12:10 GMT
Toolset
C51
New! RE: External Interrupts 89c51 using Keil Compiler
Pls wd u considr rding sum manuls?
Read-Only
Author
Raj S
Posted
18-Jun-2004 11:37 GMT
Toolset
C51
New! RE: External Interrupts 89c51 using Keil Compiler
Cambridge university research

I cdnuolt blveiee taht I cluod uesdnatnrd waht I was rdgnieg

TEH PAOMNNEHAL PWEOR OF THE HMUAN MNID

Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in
waht oredr the ltteers in a wrod are, teh olny iprmoatnt tihng is taht
teh frist adn lsat ltteer be in the rghit pclae. The rset can be a taotl
mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the
huamn mind deosn't raed ervey lteter by istlef, but the wrod as a wlohe.


Amzanighuh ?

Truly amazing...but please avoid using sms language when you are interacting in a forum.

Rgds
Raj
Read-Only
Author
Andy Neil
Posted
18-Jun-2004 19:31 GMT
Toolset
C51
New! RE: External Interrupts 89c51 using Keil Compiler
"it deosn't mttaer in waht oredr the ltteers in a wrod are, teh olny iprmoatnt tihng is taht teh frist adn lsat ltteer be in the rghit pclae."
trbl w sms is tht ltrs rnt evn all there!
we h8 it!

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings