📄 comm_try.c
字号:
/************************************/
/* down level DSP communication */
/************************************/
#include "c240.h"
unsigned int TX_data,RX_data;
void dsp_setup()
{
unsigned int temp;
/*********************************************/
/* Disable watchdog timer */
/*********************************************/
temp = WDCR;
temp = temp|0x68;
WDCR = temp;
/*********************************************/
/* initialize PLL module (20 MHz XTAL1) */
/*********************************************/
CKCR1 = 0x60; /* crystal=20MHz CPUCLK = 20MHz */
/* and 1x PLL mult ratio */
CKCR0 = 0xc3; /* low–power mode 0, */
/* ACLK enabled, */
/* PLL enabled, */
/* SYSCLK=CPUCLK/2 */
SYSCR = 0x40c0;
}
/*****************************/
/*初始化SCI*/
void SCI_init()
{SCICCR=0x0017; /* 1 stop bit,no odd check,8 data bits,
asynchronism mode,idle line */
SCICTL1=0x0013; /* inner clock,enable recive and transmit,disable
receive erro int ,sleep and woke */
SCICTL2=0x0002; /* enable recive int and disable transmit int */
SCILBAUD=0x0000;
SCILBAUD=0x0082; /* Baud rate=9600 kbps */
SCIPC2=0x0022; /* enable recive port and transmit port */
SCICTL1=0x0033; /* let SCI return from reset state */
SCIPRI=0x0000; /* RX int is high-priority int */
}
void disable_interrupts()
{
asm(" SETC INTM");
}
void enable_interrupts()
{
IFR = 0xffff; /* Clear pending interrupts */
IMR = 0x0001 ; /* Enable CPU Interrupts:INT 1 */
asm(" CLRC INTM"); /* Global interrupt enable */
}
void c_int1()
{ unsigned int y1,y2,y3;
unsigned int x3,x4;
IFR=0x0001 ;
y1=SYSIVR;
if (y1==0x0006) /* have a RX int */
{
y2=SCIRXST;
if (y2&0x80) /* receive wrongly */
{ SCI_init();
y3=SCIRXST;
}
else
{x3=SCIRXST;
if (x3&0x40) /* when RXREADY=1 read SCIRXBUF */
{x4=SCIRXEMU;
x3=x3&0x0000;
TX_data='a';
SCITXBUF=TX_data;}
}
}
}
main ()
{unsigned int x1,x2,x5;
int i,k;
char x;
disable_interrupts();
dsp_setup();
SCI_init();
enable_interrupts();
for(;;)
{
for (;SCICTL2&0x80==0;);
if (SCICTL2&0x80)
{k=k+1;
TX_data='m';
SCITXBUF=TX_data;
x1= SCITXBUF; }
for (;SCIRXST&0x40==0;); /* ready to receive data */
if (SCIRXST&0x40)
x2=SCIRXEMU;
x=SCIRXBUF; /* when RXREADY=1 read SCIRXBUF */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -