#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dp256b"
#define CRYSTAL 16000000 /*8Mhz crystal*/
#define LOCK 8
#define PLLSEL 0x80 //; use PLL for system clocks.
#define Eclock 16000000// ; final E-clock frequency (PLL)
#define RefClock 1000000
#define REFDVVal (CRYSTAL/RefClock)-1
#define SYNRVal (Eclock/RefClock)-1
byte c;
/****************************************************************************
* init_PLL() -
*
* To initialize the PLL for system use.
*****************************************************************************/
void init_PLL(void)
{
REFDV = REFDVVal; // set the REFDV register to give us a 1.0 MHz reference.
SYNR = SYNRVal; // set the SYNR register to give us a 8.0 MHz E-clock.
asm nop // nops required for PLL stability.
asm nop
asm nop
asm nop
while ((CRGFLG&LOCK)==0); // wait here till the PLL is locked.
CLKSEL|= PLLSEL; // switch the bus clock to the PLL.
}
/**************************************************************************
* SCI initialization *
***************************************************************************/
void init_SCI() {
SCI0BD=Eclock/16/9600;
SCI0CR2_RE=1;
SCI0CR2_TE=1;
SCI0CR2_RIE=1;
SCI0CR2_TCIE=1;
SCI0CR2_SCTIE=1;
}
/**************************************************************************
* Timer initialization *
***************************************************************************/
void init_Timer() {
TSCR2=0x87; //Enable main timer overflow interrupt
COPCTL =0; // disable cop
TSCR1=0xA0; //Enable main timer functionality
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
#pragma TRAP_PROC
void interrupt SCI0_REC(void){
c = SCI0SR1;
c = SCI0DRL;
PORTB=c;
}
#pragma CODE_SEG DEFAULT
/**************************************************************************
* Main routine *
***************************************************************************/
void main(void) {
/* put your own code here */
//unsigned int i;
// init_PLL();
init_SCI();
//init_Timer();
EnableInterrupts;
DDRB = 0xFF;
for(;;)
{
; // Trans
/* while(!SCI0SR1_TDRE);
SCI0DRL = 0x30;
while(!SCI0SR1_TC);
while(!SCI0SR1_TDRE);
SCI0DRL = 0x31;
while(!SCI0SR1_TC);
//while(!SCI0SR1_RDRF);
//PORTB=SCI0DRL;
if(TCNT==0xff00)
PORTB++;
if(TFLG2_TOF==1)
i=TCNT;
/*i=0xFFFF;
PORTB=0x0F;
while((i--)!=0);
i=0xFFFF;
PORTB=0xF0;
while((i--)!=0);*/
} /* wait forever */
} |