// File : m11_uart.c #include #include unsigned char received_data; unsigned char transmit_ready; unsigned char response; void initialize(); void putchar(char ch) { while(transmit_ready == 0); transmit_ready = 0; SBUF = ch; } void delay() { char temp; for(temp=0;temp<20;temp++); } void uart_int(void) interrupt SIO_VECTOR { if (TI) { // Transmit Mode TI = 0; transmit_ready = 1; } else if (RI) { // Receive Mode received_data = SBUF; RI = 0; if(received_data=='T') { response = 1; } else { SBUF = received_data; // Resend to Serial Port while(!TI); delay(); TI=0; } } } void use_external_clock() { // // Wait Crystal Amplifier stable // while (!(STATUS & 0x10)); // // Declare External Clock // EXIF |= XTRG_; } void init() { response = 0; transmit_ready = 1; use_external_clock(); // // Use TX Port // ALTSEL |= 0x04; // // Timer1 Mode2 // TMOD = 0x20; // // *Fosc = 22.1284MHz 57600 bps // PCON |= 0x80; // Timer1 baudrate double TH1 = 0xFE; // // Serial Reception enable // REN = 1; // Reception Enable // // UART Interrupt (Commnucation) Enable // ES = 1; // // All Interrupts Enable // EA = 1; // // Timer1 Start // TR1 = 1; } void main() { init(); printf("hello\n"); while(1) { if(response == 1) { response = 0; } }; }