本帖最后由 huangfeng33 于 2014-10-10 14:05 编辑
#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();
<div>SystemObjSystemObj(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. </div>
/*---------------------------------------------------------------------------
若:设置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 SystemObjSystemInit(void)
{
PllInit();//PLL初始化
TIMER0Init();
TIMER1Init();
EintInit();
/*--------------------------------------------------------
注意以下2个变量的作用域的不同
--------------------------------------------------------*/
if (SystemRamTest != 0x55aa) {//全局变量SystemRamTest
SystemRamTest = 0x55aa;//改写全局变量
}
if (SystemRamTest != 0x55aa) {//类成员变量SystemRamTest
SystemRamTest = 0x55aa;//改写类成员变量
}
IOXF = 0;
}
void SystemObjPllInit(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 SystemObjTIMER0Init(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 SystemObjTIMER1Init(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 SystemObjEintInit(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中断
}
LcdObjLcdObj(void)
{
LcdInit();
}
void LcdObjLcdSpiSetup(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);//禁止串口发送
&
一周热门 更多>