⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uartc.c

📁 c5x中关于codec的实验
💻 C
字号:
//********************************************************
//;               		SJTU DSP Tech. Center
//;        Copyright (c) 2003 SJTU DSP Tech. Center. All Rights Reserved.
//;
//;  Description:
//;  		TMS320C54x Program for Students Experiment
//;
//;  History:
//;		Date		    Authors			
//;		2003/08/07	    Zheng Yigang	
//;******************************************************************************
#include<stdio.h>
#include<stdlib.h>
#include "board.h"
#include "stdio.h"
#include "mcbsp54.h"
#include "type.h"
#include "uart.h"

//* gloabal variables
//* set default com settings
//* you can change it to assure it same to your com port
UartBaud baud;
UartWordLen wordLength;
UartStopBits stopBits;
UartParity parity;
UartFifoControl fifoControl;
UartLoop loopEnable;
    
struct uartset
{	
	UartBaud         baudset;
	UartWordLen      wordLengthset;
	UartStopBits     stopBitset;
	UartParity       parityset;
	UartFifoControl  fifoControlset;
	UartLoop         loopEnableset;
};
//*global variable
//*to control the end of program
s16 endofpro=OK;
//******************************************************************************
//* Function Prototypes                                                        *
//******************************************************************************

//* This delay routine does not conflict with DSP/BIOS.  It is used in this  *
//* example rather than brd_delay_msec which causes DSP/BIOS conflicts just  *
//* because of this.  If you are not using DSP/BIOS, you can change the code *
//* to use brd_delay_msec.

void delay(int);
int initpro(struct uartset);
void lightled(void);



//*****************************************************************************
//* main
//*****************************************************************************

void main(void)
{	
	struct uartset uartset1;
	uartset1.baudset= UART_BAUD_9600;
	uartset1.wordLengthset= UART_WORD8;
	uartset1.stopBitset= UART_STOP1;
	uartset1.parityset=	UART_DISABLE_PARITY;
	uartset1.fifoControlset= UART_FIFO_DISABLE;
	uartset1.loopEnableset=	UART_NO_LOOPBACK;
		     
	brd_init(100);
	
	if(!initpro(uartset1))
	{
		return;
	}
	
	while (endofpro==OK)
	{
		lightled();
	}
    
    uart_fputs("\n\rProgram end\n\r");
    return;
}


//*****************************************************************************
//* uart init routine
//*****************************************************************************

int initpro(struct uartset us)
{
	baud = us.baudset;
    wordLength = us.wordLengthset;
    stopBits = us.stopBitset;
    parity = us.parityset;
	fifoControl = us.fifoControlset;
    loopEnable = us.loopEnableset;
	
    if(uart_init() == ERROR)
    {
        printf("Error initializing UART for Demo\n");
        return 0;
    }
    
    return 1;
}

//*****************************************************************************
//* light led for a few seconds
//*****************************************************************************
void lightled(void)
{
	int userInput;
	uart_fputs("\n\rSelect a led to light? 0/1/2\n\r");
	uart_fputs("\n\rOr,press 5 to end the program\n\r");
	while((userInput = uart_fgetc()) == EOF);
    
    switch (userInput)
    {
        case '0':    brd_led_enable(BRD_LED0);
                     delay(1000);
                     brd_led_disable(BRD_LED0);
                     break;

        case '1':    brd_led_enable(BRD_LED1);
                     delay(1000);
                     brd_led_disable(BRD_LED1);
                     break;

        case '2':    brd_led_enable(BRD_LED2);
                     delay(1000);
                     brd_led_disable(BRD_LED2);
                     break;
        case '5':	 endofpro=ERROR;
                     break;

        default:     break;
    }
    
}

//*****************************************************************************
//* to delay some time,but do nothing
//*****************************************************************************
void delay(int cnt)
{
 	int x,y,z;
 	z=0;
 	for(x=0;x<cnt;x++)
 		for(y=0;y<3000;y++)
 			z=z+1;
 	return;
}

// programe over

⌨️ 快捷键说明

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