void main(void) { /* put your own code here */ char inData[]="Wait for character"; char input; int length; int flag; InitSci(B9600);//baudrate =9600 flag=IntStatusSci(); while (flag==0){//print message every second message_out(inData); DelayHalfSec(); } input=GetSci();//get inputted character if(input == 'n') length=Message(inData,sizeof(inData)); /*read the message*/ ... }
void InitSci(unsigned int rate){ SCIBDH=0; switch(rate){ /* br=MCLK/(16*baudRate)*/ case B110/*110*/ : SCIBDL=4545 ;break; case B150/*150*/ : SCIBDL=3333 ;break; case B300/*300*/ : SCIBDL=1667 ;break; case B600/*600*/ : SCIBDL=833 ;break; case B1200/*1200*/ : SCIBDL=417 ;break; case B2400/*2400*/ : SCIBDL=208 ;break; case B4800/*4800*/ : SCIBDL=104 ;break; case B9600/*9600*/ : SCIBDL=52 ;break; case B19200/*19200*/: SCIBDL=26 ;break; case B38400/*38400*/: SCIBDL=13 ;break; } SCICR1=0;/* PE=0, no parity*/ SCICR2=0x0C;/*TE=1, enable transmitter and RE=1, enable receiver*/ } /******************** /*Status function*/ int IntStatusSci(void){ return(SCISR1 & 0x20);//0x020->RDRF bit }
while (!IntStatusSci()){//print message every second message_out(inData); DelayHalfSec(); }