Example now enables the serial RX interrupt for echo
This commit is contained in:
13
example.c
13
example.c
@@ -187,7 +187,8 @@ void timer_init(void) {
|
|||||||
|
|
||||||
// Enable interrupts only for timer 0
|
// Enable interrupts only for timer 0
|
||||||
|
|
||||||
IE = 0x82;
|
EA = 1;
|
||||||
|
ET0 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes the serial port (along with timer 2).
|
// Initializes the serial port (along with timer 2).
|
||||||
@@ -202,12 +203,14 @@ void serial_init(void) {
|
|||||||
|
|
||||||
SCON = 0x50;
|
SCON = 0x50;
|
||||||
TI = 1;
|
TI = 1;
|
||||||
|
ES = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes a character to the serial port.
|
// Writes a character to the serial port.
|
||||||
void serial_putchar(char c) {
|
void serial_putchar(char c) {
|
||||||
while(TI == 0);
|
while(TI == 0);
|
||||||
SBUF = c;
|
SBUF = c;
|
||||||
|
TI = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__bit stdout_to_lcd = 0;
|
__bit stdout_to_lcd = 0;
|
||||||
@@ -317,3 +320,11 @@ void timer0_handler(void) __interrupt(1) {
|
|||||||
if(TIMER != 0) TIMER--;
|
if(TIMER != 0) TIMER--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serial_hanlder(void) __interrupt(4) {
|
||||||
|
if(RI) {
|
||||||
|
uint8_t data = SBUF;
|
||||||
|
serial_putchar(data);
|
||||||
|
RI = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user