Skip to content

Instantly share code, notes, and snippets.

@Ryanhu1015
Last active September 23, 2018 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ryanhu1015/c1418bc7942b8579ffff3540a147e27c to your computer and use it in GitHub Desktop.
Save Ryanhu1015/c1418bc7942b8579ffff3540a147e27c to your computer and use it in GitHub Desktop.
embedded rookie
void UART_Init(void);
void txsenddata(short);
char rxreceivedata(void);
uint8_t enableWrite=0;
char ch;
char chstring[]="Please type something to test: ";
void main(){
//initial function setting..
for (int i=0; i<sizeof(chstring); i++) txsenddata(chstring[i]);
while(1){
ch=rxreceivedata();
if (enableWrite){
txsenddata(ch);
enableWrite=0;
}
}
}
void UART_Init(){
//register setting
//include tx, rx port, uart mode (use typical one), baudrate, interrupt...
}
void txsenddata(short da){
S0BUF=da;
while (TI0==0){}
TI0=0;
}
char rxreceivedata(){
while(RI0==0){WDTR = 0x5A;}
RI0=0;
enableWrite=1;
return(S0BUF);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment