波特率自适应技术在DSP5402上的应用之C++测试程序
/*-------------------------------------------------
波特率自适应技术在DSP5402上的应用之C++测试程序
菜农 HotPower@126.com
2005.6.33 21:58 于西安大雁塔村队部
菜地: http://hotpower.21ic.org
-------------------------------------------------*/
#include <cstdio> //C语言可以用stdio.h
#include <cstring>//C语言可以用string.h
#include "C5402DEF.h"//DSP菜鸟HotPower创建
#include "class.h"
#define ccsdebug 1//1--IO模拟SPI; 0--硬件McBSP模块
extern "C" interrupt void Timer0Isr();//注意加extern "C"
extern "C" interrupt void Timer1Isr();
extern "C" interrupt void Eint0Isr();
extern "C" interrupt void Eint1Isr();
extern "C" interrupt void Eint2Isr();
extern "C" interrupt void Eint3Isr();
SystemObj::SystemObj(void)
{
Disable();//关中断
SREG->IMR = 0x0000;//
SREG->IFR = 0xffff;//清除
//设置0x0080为中断向量表首址,在第2个128页内。
SREG->PMST = (0x01 << PMST_IPTR) | (1 << PMST_MP_MC) | (1 << PMST_OVLY);
// SREG->PMST |= (1 << PMST_DROM);//数据可const.
/*---------------------------------------------------------------------------
若:设置0x0100为中断向量表首址,在第3个128页内。
则:*.cmd文件应该改为:
PAGE 0: VECS: origin=0x0100, length=0x66
则:
SREG->PMST = (0x02 << PMST_IPTR) | (1 << PMST_MP_MC) | (1 << PMST_OVLY);
----------------------------------------------------------------------------*/
SystemInit();//系统初始化
}
void SystemObj::SystemInit(void)
{
PllInit();//PLL初始化
TIMER0Init();
TIMER1Init();
EintInit();
/*--------------------------------------------------------
注意以下2个变量的作用域的不同
--------------------------------------------------------*/
if (::SystemRamTest != 0x55aa) {//全局变量SystemRamTest
::SystemRamTest = 0x55aa;//改写全局变量
}
if (SystemRamTest != 0x55aa) {//类成员变量SystemRamTest
SystemRamTest = 0x55aa;//改写类成员变量
}
::IOXF = 0;
}
void SystemObj::PllInit(void)
{
volatile unsigned int start;
SREG->SWWSR = 0x2000;
do {
SREG->CLKMD = 0;
__nop();
}
while(SREG->CLKMD & (1 << CLKMD_PLLSTATUS));
// SREG->CLKMD = (0 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);//10M
SREG->CLKMD = (9 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);// 100M
// SREG->CLKMD = (14 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);//150M
for (start = 0; start < 10000; start ++);//等待外设上电复位正常结束
}
void SystemObj::TIMER0Init(void)
{
TIMER0->TCR = (1 << TCR_TSS);//关闭定时器0
TIMER0->PRD = 60000;//设置定时周期
TIMER0->TIM = 60000;//设置定时计数器
TIMER0->TCR &= ~(1 << TCR_TSS);//启动定时器0
SREG->IMR |= (1 << IMR_TINT0);//允许TINT0中断
}
void SystemObj::TIMER1Init(void)
{
TIMER1->TCR = (1 << TCR_TSS);//关闭定时器1
TIMER1->PRD = 0xffff;//设置定时周期
TIMER1->TIM = 0xffff;//设置定时计数器
// TIMER1->TCR &= ~(1 << TCR_TSS);//启动定时器1
// SREG->IMR |= (1 << IMR_TINT1);//允许TINT1中断
}
void SystemObj::EintInit(void)
{
SREG->IMR |= (1 << IMR_INT0);//允许INT0中断
SREG->IMR |= (1 << IMR_INT1);//允许INT1中断
SREG->IMR |= (1 << IMR_INT2);//允许INT2中断
SREG->IMR |= (1 << IMR_INT3);//允许INT3中断
}
LcdObj::LcdObj(void)
{
LcdInit();
}
void LcdObj::LcdSpiSetup(void)
{
#if (ccsdebug == 0)
/*-----------------------------------------------------------
硬件McBSP模块配置为SPI接口
实验目的:
演练硬件McBSP模块配置为SPI接口的应用。
------------------------------------------------------------*/
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
// McBSP1->SPSD &= ~(1 << SPCR1_RRST);//禁止串口接收
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
// McBSP1->SPSD &= ~(1 << SPCR2_XRST);//禁止串口发送
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = (0x02 << SPCR1_CLKSTP);//CLKSTP=10b
_delay_loop_(1);//延时等待
McBSP1->SPSA = PCR;
McBSP1->SPSD = (1 << PCR_FSXM) //设置FSX引脚为输出,控制LCD12864的片选信号SS
| (0 << PCR_FSXP) //FSX引脚平时输出低电平(LCD12864的片选信号SS无效)
| (1 << PCR_CLKXM) //设置CLKX引脚为输出
| (1 << PCR_CLKXP);//CLKXP引脚平时输出高电平
_delay_loop_(1);//延时等待
McBSP1->SPSA = SRGR1;
McBSP1->SPSD = (0x07 << SRGR1_FWID) //0x00~0x07~0xff
| (0x80 << SRGR1_CLKGDV);//速率0x80
_delay_loop_(1);//延时等待
McBSP1->SPSA = SRGR2;
McBSP1->SPSD = (1 << SRGR2_CLKSM);//
_delay_loop_(1);//延时等待
McBSP1->SPSA = RCR1;
McBSP1->SPSD = (0x00 << RCR1_RFRLEN1);//8BIT
_delay_loop_(1);//延时等待
McBSP1->SPSA = XCR1;//延时等待
McBSP1->SPSD = (0x00 << XCR1_RFRLEN1);//8BIT
_delay_loop_(1);//延时等待
McBSP1->SPSA = RCR2;
McBSP1->SPSD = (0x02 << RCR2_RDATDLY);//0x01
_delay_loop_(1);//延时等待
McBSP1->SPSA = XCR2;
McBSP1->SPSD = (0x02 << XCR2_RDATDLY);//0x01
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
McBSP1->SPSD |= (1 << SPCR2_GRST) | (1 << SPCR2_XRST) | (1 << SPCR2_FRST);
_delay_loop_(1);//延时等待
#else
/*-----------------------------------------------------------
硬件McBSP模块配置为普通IO软件模拟SPI时序
实验目的:
演练硬件McBSP模块配置为普通IO的应用.以备IO紧缺时急用。
------------------------------------------------------------*/
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
McBSP1->SPSD &= ~(1 << SPCR1_RRST);//禁止串口接收
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
McBSP1->SPSD &= ~(1 << SPCR2_XRST);//禁止串口发送
&
/*-------------------------------------------------
波特率自适应技术在DSP5402上的应用之C++测试程序
菜农 HotPower@126.com
2005.6.33 21:58 于西安大雁塔村队部
菜地: http://hotpower.21ic.org
-------------------------------------------------*/
#include <cstdio> //C语言可以用stdio.h
#include <cstring>//C语言可以用string.h
#include "C5402DEF.h"//DSP菜鸟HotPower创建
#include "class.h"
#define ccsdebug 1//1--IO模拟SPI; 0--硬件McBSP模块
extern "C" interrupt void Timer0Isr();//注意加extern "C"
extern "C" interrupt void Timer1Isr();
extern "C" interrupt void Eint0Isr();
extern "C" interrupt void Eint1Isr();
extern "C" interrupt void Eint2Isr();
extern "C" interrupt void Eint3Isr();
SystemObj::SystemObj(void)
{
Disable();//关中断
SREG->IMR = 0x0000;//
SREG->IFR = 0xffff;//清除
//设置0x0080为中断向量表首址,在第2个128页内。
SREG->PMST = (0x01 << PMST_IPTR) | (1 << PMST_MP_MC) | (1 << PMST_OVLY);
// SREG->PMST |= (1 << PMST_DROM);//数据可const.
/*---------------------------------------------------------------------------
若:设置0x0100为中断向量表首址,在第3个128页内。
则:*.cmd文件应该改为:
PAGE 0: VECS: origin=0x0100, length=0x66
则:
SREG->PMST = (0x02 << PMST_IPTR) | (1 << PMST_MP_MC) | (1 << PMST_OVLY);
----------------------------------------------------------------------------*/
SystemInit();//系统初始化
}
void SystemObj::SystemInit(void)
{
PllInit();//PLL初始化
TIMER0Init();
TIMER1Init();
EintInit();
/*--------------------------------------------------------
注意以下2个变量的作用域的不同
--------------------------------------------------------*/
if (::SystemRamTest != 0x55aa) {//全局变量SystemRamTest
::SystemRamTest = 0x55aa;//改写全局变量
}
if (SystemRamTest != 0x55aa) {//类成员变量SystemRamTest
SystemRamTest = 0x55aa;//改写类成员变量
}
::IOXF = 0;
}
void SystemObj::PllInit(void)
{
volatile unsigned int start;
SREG->SWWSR = 0x2000;
do {
SREG->CLKMD = 0;
__nop();
}
while(SREG->CLKMD & (1 << CLKMD_PLLSTATUS));
// SREG->CLKMD = (0 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);//10M
SREG->CLKMD = (9 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);// 100M
// SREG->CLKMD = (14 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);//150M
for (start = 0; start < 10000; start ++);//等待外设上电复位正常结束
}
void SystemObj::TIMER0Init(void)
{
TIMER0->TCR = (1 << TCR_TSS);//关闭定时器0
TIMER0->PRD = 60000;//设置定时周期
TIMER0->TIM = 60000;//设置定时计数器
TIMER0->TCR &= ~(1 << TCR_TSS);//启动定时器0
SREG->IMR |= (1 << IMR_TINT0);//允许TINT0中断
}
void SystemObj::TIMER1Init(void)
{
TIMER1->TCR = (1 << TCR_TSS);//关闭定时器1
TIMER1->PRD = 0xffff;//设置定时周期
TIMER1->TIM = 0xffff;//设置定时计数器
// TIMER1->TCR &= ~(1 << TCR_TSS);//启动定时器1
// SREG->IMR |= (1 << IMR_TINT1);//允许TINT1中断
}
void SystemObj::EintInit(void)
{
SREG->IMR |= (1 << IMR_INT0);//允许INT0中断
SREG->IMR |= (1 << IMR_INT1);//允许INT1中断
SREG->IMR |= (1 << IMR_INT2);//允许INT2中断
SREG->IMR |= (1 << IMR_INT3);//允许INT3中断
}
LcdObj::LcdObj(void)
{
LcdInit();
}
void LcdObj::LcdSpiSetup(void)
{
#if (ccsdebug == 0)
/*-----------------------------------------------------------
硬件McBSP模块配置为SPI接口
实验目的:
演练硬件McBSP模块配置为SPI接口的应用。
------------------------------------------------------------*/
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
// McBSP1->SPSD &= ~(1 << SPCR1_RRST);//禁止串口接收
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
// McBSP1->SPSD &= ~(1 << SPCR2_XRST);//禁止串口发送
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = (0x02 << SPCR1_CLKSTP);//CLKSTP=10b
_delay_loop_(1);//延时等待
McBSP1->SPSA = PCR;
McBSP1->SPSD = (1 << PCR_FSXM) //设置FSX引脚为输出,控制LCD12864的片选信号SS
| (0 << PCR_FSXP) //FSX引脚平时输出低电平(LCD12864的片选信号SS无效)
| (1 << PCR_CLKXM) //设置CLKX引脚为输出
| (1 << PCR_CLKXP);//CLKXP引脚平时输出高电平
_delay_loop_(1);//延时等待
McBSP1->SPSA = SRGR1;
McBSP1->SPSD = (0x07 << SRGR1_FWID) //0x00~0x07~0xff
| (0x80 << SRGR1_CLKGDV);//速率0x80
_delay_loop_(1);//延时等待
McBSP1->SPSA = SRGR2;
McBSP1->SPSD = (1 << SRGR2_CLKSM);//
_delay_loop_(1);//延时等待
McBSP1->SPSA = RCR1;
McBSP1->SPSD = (0x00 << RCR1_RFRLEN1);//8BIT
_delay_loop_(1);//延时等待
McBSP1->SPSA = XCR1;//延时等待
McBSP1->SPSD = (0x00 << XCR1_RFRLEN1);//8BIT
_delay_loop_(1);//延时等待
McBSP1->SPSA = RCR2;
McBSP1->SPSD = (0x02 << RCR2_RDATDLY);//0x01
_delay_loop_(1);//延时等待
McBSP1->SPSA = XCR2;
McBSP1->SPSD = (0x02 << XCR2_RDATDLY);//0x01
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
McBSP1->SPSD |= (1 << SPCR2_GRST) | (1 << SPCR2_XRST) | (1 << SPCR2_FRST);
_delay_loop_(1);//延时等待
#else
/*-----------------------------------------------------------
硬件McBSP模块配置为普通IO软件模拟SPI时序
实验目的:
演练硬件McBSP模块配置为普通IO的应用.以备IO紧缺时急用。
------------------------------------------------------------*/
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
McBSP1->SPSD &= ~(1 << SPCR1_RRST);//禁止串口接收
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
McBSP1->SPSD &= ~(1 << SPCR2_XRST);//禁止串口发送
&