#include "sfr28.h"
void mcu_init(void);
void io_init(void);
void dma_init(void);
unsigned short rcv_data[8];
void main(void)
{
mcu_init();
io_init();
dma_init();
asm("fset i");
dm0con |=0x08;
u0c1 |=0x05;
while(1);
}
void mcu_init(void)
{
prcr=0x03;
pm0=0x00;//Single-chip mode
pm1=0x08;//No wait,No expansion
cm0=0x08;//XCIN-XCOUT High
cm1=0x20;
pm2=0x00;
pclkr=0x03;//TAi、TBi、SI/O clock select bit
prcr=0x00;//Protects all registers
}
void io_init(void)
{
u0mr=0x05;//UART mode
u0c0=0x10;//BRG f1 or f2
u0brg=129;//n=129
u0c1=0x00;
ucon=0x01;//set U0C1
u2smr=0x00;
u2smr2=0x00;
u2smr3=0x00;
u2smr4=0x00;
s0ric=0;
}
void dma_init(void)
{
dm0sl=0x0a;
dm0con=0x10;
sar0_addr.byte.low=(char)( &rcv_data);
sar0_addr.byte.mid=(char)((unsigned long)(& rcv_data)>>8);
sar0_addr.byte.high=(char)((unsigned long)(& rcv_data)>>16);
dar0_addr.byte.low=(char)(&u0tb);
dar0_addr.byte.mid=(char)((unsigned long)(& u0tb)>>8);
dar0_addr.byte.high=(char)((unsigned long)(& u0tb)>>16);//set DMA0 transfer counter
tcr0=7;
dm0ic=4;//set DMA0 interrupt priority-level=4
}
我尝试在while(1)前加上u0tb=0x5a,但是DMA仍然没有运行,只能收到0x5a本身。