#include __CONFIG(0x3F32); #define seg PORTD // define 7 segment as PORTD unsigned char a; void init(void) // subroutine to initialize { SPBRG=0x0A; // set baud rate as 115200 baud BRGH=1; TXEN=1; CREN=1; SPEN=1; TRISD = 0b00000000; seg = 0b00000000; } void display(unsigned char c) // subrountine to display the text on the screen { while (TXIF == 0); TXREG = c; } unsigned char receive(void) // subrountine to receive text from PC { while (RCIF == 0); a = RCREG; return a; } void main(void) { init(); while(1) // wait for 'ok' to be entered { a = receive(); if (a == 'o') { a = receive(); if (a == 'k') break; } } display('C'); // change the text for different display display('y'); display('t'); display('r'); display('o'); display('n'); display(0x0a); display(0x0d); display('P'); display('r'); display('e'); display('s'); display('s'); display(0x20); display('a'); display('n'); display('y'); display(0x20); display('n'); display('u'); display('m'); display('b'); display('e'); display('r'); seg = 1; while(1) // wait for number and display it on 7 segment { a = receive(); if (a=='1'||a=='2'||a=='3'||a=='4'||a=='5'||a=='6'||a=='7'||a=='8'||a=='9'||a=='0') { seg = a-0x30; } } }