我把程序稍微改了一下,你试试看(主要是对TDRE的操作)。
interrupt 20 void SCI0_rx(void) { if (SCI0SR1 & 0x80) { /*If transmission flag is set*/ SCI0SR1; //if(*(SCIStringp++) != '\0') if (g_pSci1TxHead != g_pSci1TxBufEnd) { //if(*SCIStringp > 0xD) //{ /*Avoid to change CR and LF characters*/ // SCI0DRL=*SCIStringp + Stringcase; //} //else{ g_pSci1TxHead++; SCI0DRL= *SCIStringp++;; //} } else { g_pSci1TxHead = SCIString; SCIIniTx=START_CYCLE; /*Start new transmission cycle*/ /*SCI0CR2 &= 0x7F; /*Disable TDRE interrupt*/ } }
if(SCI0SR1 & 0x20){ /*If reception flag is set*/ SCI0SR1; if(SCI0DRL == 'U' || SCI0DRL == 'u'){ Stringcase = 0x00; /*Uppercase the character string*/ } else if(SCI0DRL == 'L' || SCI0DRL == 'l'){ Stringcase = 0x20; /*Lowercase the character string*/ } }
return; }
#pragma CODE_SEG DEFAULT //************************************************************************ // SCI²ÎÊýÉèÖà //************************************************************************ void Init_SCI(void) { //SCI0ÓëMonitorͨÐÅ ////SCI0BDL=6; SCI0BDL=13; SCI0BDH=0; //CLOCK=7.3728MHz, bps=38400 ////SCI0CR1=0x16; //9 bit, żЧÑé SCI0CR1=0x06; //8 bit, żЧÑé SCI0CR2=0x2C; //ÖÐÖ¹·û²úÉúÆ÷¹Ø±Õ SCI0CR2 |= 0x80; /*Enable TDRE interrupt*/ }
void SCITx(unsigned char SCIByte){
SCI0DRL = SCIByte; /*Write data byte to SCIDRL register*/ /*SCI0CR2 |= 0x80; /*Enable TDRE interrupt*/ }
void main(void) { /* DDRB = 1; while (1){ PORTB_BIT0^=1; }*/ /* put your own code here */ EnableInterrupts; Init_SCI(); SCIIniTx = START_CYCLE; /*Initialize transmission cycle flag*/
for (;;) { if(SCIIniTx == START_CYCLE){ SCIIniTx = WAIT_CYCLE;
SCIStringp=SCIString; /*Set pointer to character string*/ SCITx(*SCIStringp + Stringcase);/*Send first byte of string*/ }
} }
[此贴子已经被strongchen于2007-3-30 15:34:02编辑过] |