Hello. I want to get key from keyboard not using the default Serial #1 but using Serial #2 that i suppose is connected with ASC1. So i configure the port 3, the direction pin, and alternate operation. this is the piece of code.
#include <stdio.h> /* standard I/O .h-file */ #include <XC161.h> /* special function register XC161 */ #include <math.h> signed char _getkey (void) { char c; while (!ASC0_RIC); c = (char) ASC1_RBUF; ASC1_RIC = 0; return (c); } /****************/ /* main program */ /****************/ void main (void) { /* execution starts here */ char nome[10]; int i; int j=0; /* initialize the serial interface */ #ifndef Monitor /* do not initialize if you use Monitor-166 */ P3 |= 0x0400; /* SET PORT 3.10 OUTPUT LATCH (TXD) */ P3 |= 0x0002; DP3 |= 0x0400; /* SET PORT 3.10 DIRECTION CONTROL (TXD OUTPUT) */ DP3 |= 0x0002; DP3 &= 0xF7FF; /* RESET PORT 3.11 DIRECTION CONTROL (RXD INPUT) */ ASC0_TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG */ ASC0_RIC = 0x00; /* DELETE RECEIVE INTERRUPT FLAG */ ASC0_BG = 0x40; /* SET BAUDRATE TO 9600 BAUD @ 20MHz */ ASC0_CON = 0x8011; /* SET SERIAL MODE */ ALTSEL0P3 |= 0x0C00; /* Configure port pins for serial interface 0 */ ASC1_TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG */ ASC1_RIC = 0x00; /* DELETE RECEIVE INTERRUPT FLAG */ ASC1_BG = 0x40; /* SET BAUDRATE TO 9600 BAUD @ 20MHz */ ASC1_CON = 0x8011; /* SET SERIAL MODE */ ALTSEL0P3 |= 0x0002; /* Configure port pins for serial interface 0 */ #endif while (1) { printf("valore registro RSTCON: %0xh \n",RSTCON); printf("Causa del reset: %0xh \n",SYSSTAT); printf("Sorgente di configurazione: %0xh \n",RSTCFG); // printf("valore di SYSCON1 :%0xh \n",SYSCON1); // printf("valore di SYSCON2 :%0xh \n",SYSCON2); printf("valore di SYSCON3 :%0xh \n",SYSCON3); i=-1; nome[0]='a'; /* An embedded program does not stop and */ do { i++; nome[i]=_getkey(); printf("%c",nome[i]); } while (nome[i]!=0x00A); printf("Ciao, "); printf(nome); } /* loop. You may wish to put in your own */ } /* code were we've printed the dots (...). */