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

8051 interrupts

I am trying to generate an interrupt when a byte is received via the serial port of an Atmel AT89C51. I am not having much luck. Here is my code:

#include <reg51.h>
#include <CTYPE.H>
#include <STDIO.H>
#include <INTRINS.H>

int big_d, count, dogg, i, j;

void rcv (void) interrupt 4 
{
	big_d = _getkey();
	count++;
	dogg = 1;
	RI = 0;
}

void main(void)
{
	SCON  = 0x50;		/* SCON: mode 1, 8-bit UART, enable rcvr */
    TMOD |= 0x20;       /* TMOD: timer 1, mode 2, 8-bit reload */   
    TH1   = 253;        /* TH1:  reload value for 9600 baud @ 11.0592MHz */
    TR1   = 1;          /* TR1:  timer 1 run */          
    TI    = 1;          /* TI:   set TI to send first char of UART */
	ES = 1;				/* enable serial interrupts */

	dogg = 0;
	count = 0x30;
do{
	putchar(count);
	for(j=0; j<255; j++)
	{
		for(i=0; i<255; i++)
		{
			_nop_();
			_nop_();
			_nop_();
			_nop_();
		}
	}
	if(dogg == 1)
	{
		putchar(count);
		printf("\n");
		putchar(big_d);
		printf("\n\n\n");
		dogg = 0;
	}
}while(1);
}

Any suggestions or corrections to my code would be great. Thanks

Parents
  • A hybrid design in which characters are received via interrupts and sent using polling is common professional design.

    The 8051 has the complication that the transmit interrupt cannot be ignored. I've already shown that the polling loop needs only two instructions. Moving the character to SBUF requires one. That is three opcodes.

    The transmit interrupt can be as simple as:

    SERIAL_INTERRUPT:
       JBC TI, TINTERRUPT
    <receive interrupt processing>
    
    
    TINTERRUPT:
       SETB TRE
       RETI
    

    So the entire driver can be done with six opcodes and one memory bit.

Reply
  • A hybrid design in which characters are received via interrupts and sent using polling is common professional design.

    The 8051 has the complication that the transmit interrupt cannot be ignored. I've already shown that the polling loop needs only two instructions. Moving the character to SBUF requires one. That is three opcodes.

    The transmit interrupt can be as simple as:

    SERIAL_INTERRUPT:
       JBC TI, TINTERRUPT
    <receive interrupt processing>
    
    
    TINTERRUPT:
       SETB TRE
       RETI
    

    So the entire driver can be done with six opcodes and one memory bit.

Children
No data