📄 f2407sci2.c
字号:
/************************************************************************/
/* Testprogram for serial communication SCI */
/* running on TMS320LF2407 EVM */
/* external clock is 14.7456 MHz, PLL * 2 , CPU-Clock then 29.49 MHz */
/************************************************************************/
/************************************************************************/
/* SCI-communication RS232 from EVA-board to PC- COM2 */
/* Receiving from Windows-95 Hyperterminal-Session */
/* write a textfile containing a one line text and a <CR> and send this */
/* file by Hyperterminal to the LF2407 ( "Transmission - Text file" ) */
/* 9600 Baud , 8bit, no parity , 1 Stopbit , no protocol */
/* The F2407 monitors the receiver by its interrupt service routine,when*/
/* the received character was a <CR> the string 'READY' is transmitted */
/* uses both TXD-interrupt- and RXD-interrupt-service */
/* program-name : F2407SCI2.c / project : lab8.mak */
/* date : 07/17/2001 (c) Frank.Bormann@fh-zwickau.de */
/************************************************************************/
#include "regs2407.h"
/************* SETUP for the MCRA - Register **************/
#define MCRA15 0 /* 0 : IOPB7 1 : TCLKIN */
#define MCRA14 0 /* 0 : IOPB6 1 : TDIR */
#define MCRA13 0 /* 0 : IOPB5 1 : T2PWM */
#define MCRA12 0 /* 0 : IOPB4 1 : T1PWM */
#define MCRA11 0 /* 0 : IOPB3 1 : PWM6 */
#define MCRA10 0 /* 0 : IOPB2 1 : PWM5 */
#define MCRA9 0 /* 0 : IOPB1 1 : PWM4 */
#define MCRA8 0 /* 0 : IOPB0 1 : PWM3 */
#define MCRA7 0 /* 0 : IOPA7 1 : PWM2 */
#define MCRA6 0 /* 0 : IOPA6 1 : PWM1 */
#define MCRA5 0 /* 0 : IOPA5 1 : CAP3 */
#define MCRA4 0 /* 0 : IOPA4 1 : CAP2/QEP2 */
#define MCRA3 0 /* 0 : IOPA3 1 : CAP1/QEP1 */
#define MCRA2 0 /* 0 : IOPA2 1 : XINT1 */
#define MCRA1 1 /* 0 : IOPA1 1 : SCIRXD */
#define MCRA0 1 /* 0 : IOPA0 1 : SCITXD */
/****************************************************************/
/************* SETUP for the MCRB - Register **************/
#define MCRB9 0 /* 0 : IOPD1 1 : XINT2/EXTSOC */
#define MCRB8 1 /* 0 : CKLKOUT 1 : IOPD0 */
#define MCRB7 0 /* 0 : IOPC7 1 : CANRX */
#define MCRB6 0 /* 0 : IOPC6 1 : CANTX */
#define MCRB5 0 /* 0 : IOPC5 1 : SPISTE */
#define MCRB4 0 /* 0 : IOPC4 1 : SPICLK */
#define MCRB3 0 /* 0 : IOPC3 1 : SPISOMI */
#define MCRB2 0 /* 0 : IOPC2 1 : SPISIMO */
#define MCRB1 1 /* 0 : BIO 1 : IOPC1 */
#define MCRB0 1 /* 0 : XF 1 : IOPC0 */
/****************************************************************/
/************* SETUP for the MCRC - Register **************/
#define MCRC13 0 /* 0 : IOPF5 1 : TCLKIN2 */
#define MCRC12 0 /* 0 : IOPF4 1 : TDIR2 */
#define MCRC11 0 /* 0 : IOPF3 1 : T4PWM/T4CMP */
#define MCRC10 0 /* 0 : IOPF2 1 : T3PWM/T3CMP */
#define MCRC9 0 /* 0 : IOPF1 1 : CAP6 */
#define MCRC8 0 /* 0 : IOPF0 1 : CAP5/QEP3 */
#define MCRC7 0 /* 0 : IOPE7 1 : CAP4/QEP2 */
#define MCRC6 0 /* 0 : IOPE6 1 : PWM12 */
#define MCRC5 0 /* 0 : IOPE5 1 : PWM11 */
#define MCRC4 0 /* 0 : IOPE4 1 : PWM10 */
#define MCRC3 0 /* 0 : IOPE3 1 : PWM9 */
#define MCRC2 0 /* 0 : IOPE2 1 : PWM8 */
#define MCRC1 0 /* 0 : IOPE1 1 : PWM7 */
#define MCRC0 0 /* 0 : IOPE0 1 : CLKOUT */
/****************************************************************/
/************* SETUP for the WDCR - Register **************/
#define WDDIS 1 /* 0 : Watchdog enabled 1: disabled */
#define WDCHK2 1 /* 0 : System reset 1: Normal OP */
#define WDCHK1 0 /* 0 : Normal Oper. 1: sys reset */
#define WDCHK0 1 /* 0 : System reset 1: Normal OP */
#define WDSP 7 /* Watchdog prescaler 7 : div 64 */
/****************************************************************/
/************* SETUP for the SCSR1 - Register **************/
#define CLKSRC 0 /* 0 : intern(30MHz) */
#define LPM 0 /* 0 : Low power mode 0 if idle */
#define CLK_PS 1 /* 001 : PLL multiply by 2 */
#define ADC_CLKEN 0 /* 0 : No ADC-service in this test */
#define SCI_CLKEN 1 /* 1 : Use SCI-service in this test */
#define SPI_CLKEN 0 /* 0 : No SPI-servide in this test */
#define CAN_CLKEN 0 /* 0 : No CAN-service in this test */
#define EVB_CLKEN 0 /* 0 : No EVB-Service in this test */
#define EVA_CLKEN 0 /* 0 : No EVA-Service in this test */
#define ILLADR 1 /* 1 : Clear ILLADR during startup */
/****************************************************************/
/************* SETUP for the WSGR - Register **************/
#define BVIS 0 /* 10-9 : 00 Bus visibility OFF */
#define ISWS 0 /* 8 -6 : 000 0 Waitstates for IO */
#define DSWS 0 /* 5 -3 : 000 0 Waitstates data */
#define PSWS 0 /* 2 -0 : 000 0 Waitstaes code */
/****************************************************************/
/************* SETUP for the IMR - Register **************/
#define INT6 0 /* 5 : Level INT6 is masked */
#define INT5 0 /* 4 : Level INT5 is masked */
#define INT4 0 /* 3 : Level INT4 is masked */
#define INT3 0 /* 2 : Level INT3 is masked */
#define INT2 0 /* 1 : Level INT2 is masked */
#define INT1 1 /* 0 : SCI -Level INT1 is unmasked */
/************* SETUP for the SCICCR - Register **************/
#define STOPBITS 0 /* 0 : one stop bit */
#define EVENODD 0 /* 0 : odd parity */
#define PARITY 0 /* 0 : no parity */
#define LOOPBACKENA 0 /* 0 : Loop Back Test Mode disabled*/
#define ADDRIDLE 0 /* 0 : IDLE-line mode for multipr. */
#define SCICHAR 7 /* 111 : 8-bit data transmission */
/****************************************************************/
/************* SETUP for the SCICTL1 - Register *************/
#define RXERRINT 0 /* 0 : disable Rx Error Interrupts */
#define SWRESET 0 /* 0 : apply reset state */
/* 1 : reenabling SCI, after config.*/
#define TXWAKE 0 /* 0 : no wakeupfunction now */
#define SLEEP 0 /* 0 : sleep mode disabled */
#define TXENA 1 /* 1 : Transmitter enabled */
#define RXENA 1 /* 1 : Receiver enabled */
/****************************************************************/
/************* SETUP for the SCICTL2 - Register *************/
#define RXBKINT 1 /* 0 : enable RX and Break inter. */
#define TXINT 1 /* 1 : enable TXRDY-interrupt */
/****************************************************************/
/************* SETUP for the SCIPRI - Register **************/
#define TXPRIORITY 0 /* TXD-int on high Priority (INT1) */
#define RXPRIORITY 0 /* RXD-int on high Priority (INT1) */
#define SCISOFTFREE 2 /* on emulator suspend complete SCI */
/****************************************************************/
#define BRR 383 /* baudrate register constant */
/* 383 = (29,4912e+6/(9600Baud *8)) -1 */
static char index=0;
const char message[7]="READY\n\r";
void c_dummy1(void)
{
while(1); /*Dummy ISR used to trap spurious interrupts*/
}
interrupt void SCI_ISR(void)
{
if((PIVR-0x0007)==0) /*Verify type of interrupt ( 7 = TxD ) */
{
if(index<=6) SCITXBUF=message[index++]; /* Transmit next byte */
else index=0; /* reset message pointer */
}
if((PIVR-0x0006)==0) /* 6 = receiver interrupt */
{
if(SCIRXBUF==0x0D) SCITXBUF=message[index++];
/* when <CR> received then start transmission */
}
}
void main(void)
{
asm (" setc INTM");/*Disable all interrupts */
asm (" clrc SXM"); /*Clear Sign Extension Mode bit */
asm (" clrc OVM"); /*Reset Overflow Mode bit*/
asm (" clrc CNF"); /*Configure block B0 to data mem. */
WSGR=((BVIS<<9)+(ISWS<<6)+(DSWS<<3)+PSWS);
/* set the external waitstates WSGR */
WDCR=((WDDIS<<6)+(WDCHK2<<5)+(WDCHK1<<4)+(WDCHK0<<3)+WDSP);
/* Initialize Watchdog-timer */
SCSR1= ((CLKSRC<<14)+(LPM<<12)+(CLK_PS<<9)+(ADC_CLKEN<<7)+
(SCI_CLKEN<<6)+(SPI_CLKEN<<5)+(CAN_CLKEN<<4)+
(EVB_CLKEN<<3)+(EVA_CLKEN<<2)+ILLADR);
/* Initialize SCSR1 */
MCRC = ((MCRC13<<13)+(MCRC12<<12)+(MCRC11<<11)+(MCRC10<<10)
+(MCRC9<<9)+(MCRC8<<8)+(MCRC7<<7)+(MCRC6<<6)
+(MCRC5<<5)+(MCRC4<<4)+(MCRC3<<3)+(MCRC2<<2)
+(MCRC1<<1)+MCRC0);
/* Initialize multiplex control register C */
MCRB = ((MCRB9<<9)+(MCRB8<<8)+
(MCRB7<<7)+(MCRB6<<6)+(MCRB5<<5)+(MCRB4<<4)+
(MCRB3<<3)+(MCRB2<<2)+(MCRB1<<1)+MCRB0);
/* Initialize multiplex control register B */
MCRA = ((MCRA15<<15)+(MCRA14<<14)+(MCRA13<<13)+(MCRA12<<12)+
(MCRA11<<11)+(MCRA10<<10)+(MCRA9<<9)+(MCRA8<<8)+
(MCRA7<<7)+(MCRA6<<6)+(MCRA5<<5)+(MCRA4<<4)+
(MCRA3<<3)+(MCRA2<<2)+(MCRA1<<1)+MCRA0);
/* Initialize multiplex control register A */
SCICCR=((STOPBITS<<7)+(EVENODD<<6)+(PARITY<<5)+
(LOOPBACKENA<<4)+(ADDRIDLE<<3)+SCICHAR);
/* Initialize SCI Control Register */
SCICTL1=((RXERRINT<<6)+(SWRESET<<5)+
(TXWAKE<<3)+(SLEEP<<2)+(TXENA<<1)+RXENA);
/* initialize SCI Control Register 1 */
SCICTL2=((RXBKINT<<1)+TXINT);
/* initialize SCI Control Register 2 */
SCIHBAUD=BRR>>8; /* load the Baud-Rate Register */
SCILBAUD=BRR & 0x00FF;
SCIPRI= ((TXPRIORITY<<6)+(RXPRIORITY<<5)+(SCISOFTFREE<<3));
/* Initialize SCI Priority control register */
SCICTL1|=0x0020; /* reenable SCI , SWRESET=1 */
IFR=0xFFFF; /* Reset all core interrupts */
IMR=((INT6<<5)+(INT5<<4)+(INT4<<3)+(INT3<<2)+(INT2<<1)+INT1);
/* enable specific core Interrupts */
asm (" clrc INTM"); /* Enable all unmasked interrupts */
while(1); /* endless loop ; action done by ISR */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -