AnsweredAssumed Answered

DEMO9S08DZ60 UART code

Question asked by pawan kumar on Jul 13, 2015
Latest reply on Jul 15, 2015 by pawan kumar

Hi Friends,

 

I have purchased the DEMO board and am trying to send a char. through UART @9600bps. 8 bits, 1 stop bit, pairity : None.

 

Please see my code and help me understand my mistake. I am getting junk value at the terminal.

 

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

#define led1  PTBD_PTBD3

#define led2  PTCD_PTCD5

void delay(int m)//delay in ms

{

  int i,p,j;

  for(p=0;p<m;p++)

  {

  for(i=0;i<4;i++)

  {

  for(j=0;j<1000;j++);

  }

  }

}

void main(void) {

  int s;

  s=0;

  SOPT1_COPT = 0; //Disable WDT

 

 

  /* include your code here */

  //Configure Baud rate 9600bps, 8 bit, 1 stop bit.

//MCG not altered, so, BUS_CLK =20MHz

  //9600bps

SCI1BDH=0x00;

SCI1BDL=0x82;

//invert bits

SCI1C3=SCI1C3|SCI1C3_TXINV_MASK;

//Transmission enable

SCI1C2=SCI1C2|SCI1C2_TE_MASK;

SCI1C1=0x00;

 

 

while(1)

{

while(SCI1S1_TDRE==0);

SCI1D=0x61;

//while(SCI1S1_TC==0);

delay(100);

 

}

 

 

 

 

  /* please make sure that you never leave main */

}

 

Thanks in advance for any help.

Pawan

Outcomes