#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
/***********全局变量***********************/
unsigned char Data_chg[4];
unsigned char Number ;
/*-------锁相环初始化程序----------------------*/
void PLL_init(void) {
REFDV = 1;
SYNR = 2;
while( !(CRGFLG&0x08) );
CLKSEL = 0x80;
}
/*-------串口初始化程序----------------------*/
void SCI_init(void) {
SCI0CR2 = 0x0c;
SCI0CR1=0; /*normal,no parity*/
SCI0BDL = 0x9c;
}
/*-------发射端程序----------------------*/
void SCI_Tx(unsigned char text) {
unsigned char temp;
temp=SCI0SR1; /*clear flag*/
while (!(SCI0SR1&0x80)); /* wait for output buffer empty */
SCI0DRH=0;
SCI0DRL=text;
}
/*-------接受端程序----------------------*/
char SCI_Rx(void){
char result,temp;
temp=SCI0SR1; /*clear flag*/
while(!(SCI0SR1&0x20));
result=SCI0DRL;
return result;
}
/*-------数据处理-----------------------*/
void Data_Prc(unsigned char data){
unsigned char Temp_Prc;
unsigned char j;
Temp_Prc = data;
Number = 1;
while(Temp_Prc){
Temp_Prc = Temp_Prc/10;
Number++;
}
for( j = 0; j < Number; j++ ) {
if( --Number == j ){
Data_chg[j] = data % 10 +48;
}
else{
Data_chg[j] = data / 10 + 48;
}
}
Data_chg[Number] = 44;
}
/*-------主函数--------------------------*/
void main(void) {
/* put your own code here */
unsigned char data;
unsigned char temp,Temp_Tx;
unsigned char i;
unsigned char out[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
EnableInterrupts;
PLL_init();
SCI_init();
for(i = 0; i < 4; i++){
Data_chg = 0;
}
for( i = 0; i < 10; i++){
temp = out;
Data_Prc(temp);
for( i = 0; i
Temp_Tx = Data_chg;
SCI_Tx(Temp_Tx);
}
}
data = SCI_Rx();
DDRB = 0XFF;
PORTB = data;
for(;;) {} /* wait forever */
/* please make sure that you never leave this function */
}
|