Last active
September 23, 2018 05:54
-
-
Save Ryanhu1015/c1418bc7942b8579ffff3540a147e27c to your computer and use it in GitHub Desktop.
embedded rookie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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