George Smilov

Serial Port on a QG8

Discussion created by George Smilov on Nov 17, 2006
Latest reply on Nov 18, 2006 by David Payne
im trying to learn how to use the HCS08 (i got a DEMO9S08QG8) for one my classes and am running into some difficulty finding resources, mostly there is an utter lack of sample code and explanation. ive looked through the sticky, which is nice, but it just skips the serial part. so far, ive made a program that turns led1 on when the phototransistor detects no light, and off when it detects light. now, im trying to extend this program to send a character over serial interface whenever LED1 is on. i got the following function from a freescale program.

void SendChar(char s_char) {
byte dummy; // dummy var for reading SCIS1

SCIC2 = 0x08; // enable Tx
dummy = SCIS1; // 1st half of TDRE clear procedure
SCID = s_char; // 2nd half of TDRE clear procedure
while(!SCIS1_TDRE){
feedCOP();
};
while(!SCIS1_TC){
feedCOP();
};
SCIC2_TE = 0;
} //end SendChar

and the following is my program (also put together using pieces of code from freescale)

#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "demo9S08QG8.h" /*include demo board declarations */


void MCU_init(void); /* Device initialization function declaration */

void main(void) {

/* Uncomment this function call after using Device Initialization
to use the generated code */
/* MCU_init(); */

EnableInterrupts; /* enable interrupts */

/* include your code here */

ICSC2_BDIV = 0;
LED1 =0;

PTBDD_PTBDD6 = 1;
PTBDD_PTBDD1 = 0;

MTIMCLK_PS = 8;
MTIMCLK_CLKS = 0;
MTIMMOD = 112;

MTIMMOD = 0; /* modulo = 50 */
MTIMSC = 0x60; /* reset and start MTIM, enable ints */

PTAPE_PTAPE1 = 1;

for(;:smileywink: {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave this function */
}


interrupt 12 void MTIM_ISR(void) {
MTIMSC_TOF=0; /* clear TOF */
LED1 = ~PTAD_PTAD1; /* toggle Port */
if (~PTAD_PTAD1){
SendChar('a');
}

}

can someone please help in figuring out what i need to do to make this code work? for example, how do i setup the serial interface, like the baud rate and such. thanks in advance for any help.

Outcomes