#include "Extent.h" //
#include "MC95FG204.h" // peripheral
#include "Const.h" // constant
#define MyDef extern //
#include "Variable.h" // RAM, Bit define
#include "Intrins.h"
//95gf204的串口测试程序 2009-2-14
#define BAUD_9600 25 // @4MHz
#define BAUD_19200 12
#define BAUD_38400 6
#define BAUD_57600 3
#define BAUD_115200 1
//======================================================================
// task : Uart0 Packet Communication full-duplex
// input :
// R02 TX0
// R03 RX0
//======================================================================
void Delay(void)
{unsigned char i,j;
for(i=0;i<224;i++);
for(j=0;j<244;j++);
}
void Uart_Initial(void)
{
UCTRL1 = 0x06; // 8bit asyn
UCTRL2 = 0x8A; //?建议只开数据寄存器空中断,只允许发送 0x8A
UCTRL3 = 0x00; //
UBAUD = BAUD_9600; // default BAUD = 9600 bps
USTAT = 0x00;
}
//----------------------------------------------------------------------
// task : Uart0 transmission start
//----------------------------------------------------------------------
void put_c(unsigned char c)
{
UDATA=c;
//USTAT &= 0xbf;
while(!(USTAT&0x40)); //TXC=1 exit
USTAT=0x00;
}
void Uart_Transmit(void)
{
put_c(0x65);
//Delay();
put_c(0x66);
//Delay();
put_c(0x67);
//Delay();
put_c(0x68);
//Delay();
put_c(0x69);
}
void port_initial(void)
{
P0IO=0xFD;
P0=0xFC;
P0OD=0xC0;
P0PU=0xC2;
P0PC=0;
}
void main(void)
{
unsigned char i;
WDTR=0xFF;
BCCR=0x0E;
BCCR=0x0E;
IE3=0x10; // BIT time interrupt
IE=0x80;
SCCR=0x81;
PCON=0x03; // stop1
_nop_();
_nop_();
_nop_();
_nop_();
//SCCR=0x80;
port_initial();
Delay();
Delay();
Delay();
Delay();
Delay();
Delay();
Delay();
Delay();
Delay();
Delay();
Uart_Initial(); //打开使能
for(i=0;i<20;i++)
{
Uart_Transmit();
Delay();
}
while(1);
UCTRL2 = 0x80;
}
void BIT_Int(void) interrupt 22 using 1
{
//P11=~P11;
_nop_();
}
这个程序用uart不断发送efghi 这5个字母给PC,经测试,功能正常。