sci.c

来自「dsp320lf2407上的相关程序文件」· C语言 代码 · 共 58 行

C
58
字号
#include    "f2407_c.h"
#define BAUD_19200 0x0103 	/*40MHz SYSclock*/
#define BAUD_9600 0x0208	
#define BAUD_4800 0x0411
#define BAUD_2400 0x0822
#define BAUD_1200 0x1046

#define LED port40                           
volatile ioport unsigned int port40;


extern void test_sci(void); 


void sci_send(unsigned int data_to_send)
{
	while((*SCICTL2&0x0080)==0);
	*SCITXBUF=data_to_send;	
	asm("	nop");
	asm("	nop");
	asm("	nop");
	asm("	nop");
}
	
unsigned int sci_rec(void)
{
	while((*SCIRXST&0x0040)==0x0000);
	return(*SCIRXBUF);
}	


void sci_init(void)
{
	*SCSR1=*SCSR1|0x0040;	/*enable SCI clock*/
	/**MCRA=0x0003;	/*enable TXD and RXD*/
	*SCICCR=0x0007;
	*SCICTL1=0x0013;
	*SCICTL2=0x0003;
	*SCIHBAUD=(BAUD_9600/0x100);
	*SCILBAUD=(BAUD_9600%0x100);
	*SCICTL1=0x0033;
}



void test_sci(void)
{
	LED = 0x00fb;
	sci_init();
	while(1)
	{
		//sci_send(0x55);
		//asm("	nop");
		sci_send(sci_rec());
	}
		
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?