We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am looking for an example program which uses interrupts to receive data through the serial port. This is what I have tried:
#include <reg51.h> #include <CTYPE.H> #include <STDIO.H> int big_d, count, dogg; void rcv_interrupt (void) interrupt 4 using 1 { 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 = 0; do{ if(dogg == 1) { putchar(count); printf("\n"); putchar(big_d); printf("\n\n\n"); dogg = 0; } }while(1); }