链接部分
DSP C2000系列F28335调试踩坑
小白之28335残酷的调试过程
关于28335各个模块的理解
对DSP进行开发时,需要对其底层的硬件及外设进行相应的配置,当配置完成后才可以将其相应模块激活,才可以在其内部进行程序编写及调试处理。下面对程序配置及操作进行简单的整理,仅供参考。
第一步:初始化系统控制,PLL,看门狗,使能外设时钟等,一般调用函数InitSysCtrl();
第二步:初始化GPIO,对于不同的硬件系统,进行不同的功能配置;
gpio 介绍
第三步:清除所有的中断并初始化PIE中断向量表
禁用CPU中断
DINT;
初始化PIE控制寄存器为默认状态
InitPieVectTable();
禁用CPU中断并清除所有的CPU中断标志
IER=0x0000;
IFR=0x0000;
初始化PIE中断向量表
InitPieVectTable();
EALLOW;
XXX-------此处填写程序中需要的中断,将其映射到中断向量表中(如
Pie VectTable.SCIRXINTA=&sciaRxFifoIsr;)
EDIS;
第四步:初始化所有外设(如果没有外设结构,此部分可省略);
第五步:用户程序段,使能中断。
以上为初步设计DSP程序的基本框架,具体要实现的功能还需在其中添加!
仿真时导出实时数据并使用matlab处理.data文件
ccs查看pid曲线
变量导出
导出CCS3.3数据及使用matlab处理的方法
实际上使用的是定义一个一千多个数的数组,存进去然后再load memory。。。
ccs error: program “make” not found in path
查了很多地方都不无法得到解决方法。实际上去properties里build中的builder下看到使用的command是make,点击use 初始的命令,再次编译就不会报错了
cannot open source file “math.h”
第一次编译文件需要将ccs自带的include文件夹添加路径,报错找不到什么就放什么。还是在properties中build下的include options下添加路径,将系统的include放进去。如果项目自带的include文件夹,那也得选择workspace然后把文件夹添加进去。
还出现.out的错误说明代码有问题,找一下错误再编译就能成功
多核处理学习
This error was generated by TI’s USCIF driver
查了网络上都说驱动的问题,部分解答为重装,但本人就是懒得重装(mac 装一次就得烧 cpu 一次)
打开系统设置----网络----其他服务发现有四个xds200x emulator 的驱动—都删除服务并不再次开启—重启电脑—插上仿真器—这回自动生成了两个驱动,再次打开 ccs 发现成功重装驱动。
CCS界面 tools->Graph->Signal Time 是黑色的但是点了之后没有任何反应
解决方法:关闭系统,重启ccs。(之前把target configs注释掉了不知道有无影响)
ccs保存一个变量的数据生成图像并导出成dat文件,使用matlab处理
debug界面,tools-graph-single time
buffer 1000 - 32bit signed integer - start adrress:数组名字 - data size 1000
Simulink和ccs联合仿真
下载matlab硬件支持包,安装的时候要联网登陆
其中一篇参考
参考2
epwm
sci
调试总结
pwm触发ADC
sci通信
sci模块
led 闪烁实验
CCS You are required to terminate existing debug…
debug后,直接点 terminate 小方框不行,ccs没停止上一次的 debug。
解决方法DSP程序调试时CCS如何安全退出调试状态
Example02_DSP2833x_LED/targetConfigs line 0
targetconfigs 直接复制过去一直都是感叹号,解决:重新创建一个把原来的删了
//###########################################################################
//
// FILE: Example_2833xGpioToggle.c
//
// TITLE: DSP2833x Device GPIO toggle test program.
//
// ASSUMPTIONS:
//
// This program requires the DSP2833x header files.
//
// ALL OF THE I/O'S TOGGLE IN THIS PROGRAM. MAKE SURE
// THIS WILL NOT DAMAGE YOUR HARDWARE BEFORE RUNNING THIS
// EXAMPLE.
//
// Monitor desired pins on an oscilloscope.
//
// As supplied, this project is configured for "boot to SARAM"
// operation. The 2833x Boot Mode table is shown below.
// For information on configuring the boot mode of an eZdsp,
// please refer to the documentation included with the eZdsp,
//
// $Boot_Table:
//
// GPIO87 GPIO86 GPIO85 GPIO84
// XA15 XA14 XA13 XA12
// PU PU PU PU
// ==========================================
// 1 1 1 1 Jump to Flash
// 1 1 1 0 SCI-A boot
// 1 1 0 1 SPI-A boot
// 1 1 0 0 I2C-A boot
// 1 0 1 1 eCAN-A boot
// 1 0 1 0 McBSP-A boot
// 1 0 0 1 Jump to XINTF x16
// 1 0 0 0 Jump to XINTF x32
// 0 1 1 1 Jump to OTP
// 0 1 1 0 Parallel GPIO I/O boot
// 0 1 0 1 Parallel XINTF boot
// 0 1 0 0 Jump to SARAM <- "boot to SARAM"
// 0 0 1 1 Branch to check boot mode
// 0 0 1 0 Boot to flash, bypass ADC cal
// 0 0 0 1 Boot to SARAM, bypass ADC cal
// 0 0 0 0 Boot to SCI-A, bypass ADC cal
// Boot_Table_End$
//
// DESCRIPTION:
//
// Three different examples are included. Select the example
// (data, set/clear or toggle) to execute before compiling using
// the #define statements found at the top of the code.
//
//
// Toggle all of the GPIO PORT pins
//
// The pins can be observed using Oscilloscope.
//
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
/**************************************宏定义************************************************/
#define LED1_OFF GpioDataRegs.GPBSET.bit.GPIO60 = 1 //LED D10 点亮
#define LED1_ON GpioDataRegs.GPBCLEAR.bit.GPIO60 = 1 //LED D10 熄灭
#define LED2_OFF GpioDataRegs.GPBSET.bit.GPIO61 = 1 //LED D11 点亮
#define LED2_ON GpioDataRegs.GPBCLEAR.bit.GPIO61 = 1 //LED D11 熄灭
#define LED3_OFF GpioDataRegs.GPASET.bit.GPIO2 = 1 //LED D12 点亮
#define LED3_ON GpioDataRegs.GPACLEAR.bit.GPIO2 = 1 //LED D12 熄灭
#define LED4_OFF GpioDataRegs.GPASET.bit.GPIO3 = 1 //LED D13 点亮
#define LED4_ON GpioDataRegs.GPACLEAR.bit.GPIO3 = 1 //LED D13 熄灭
#define LED5_OFF GpioDataRegs.GPASET.bit.GPIO4 = 1 //LED D14 点亮
#define LED5_ON GpioDataRegs.GPACLEAR.bit.GPIO4 = 1 //LED D14 熄灭
#define LED6_OFF GpioDataRegs.GPASET.bit.GPIO5 = 1 //LED D15 点亮
#define LED6_ON GpioDataRegs.GPACLEAR.bit.GPIO5 = 1 //LED D15 熄灭
#define LED7_OFF GpioDataRegs.GPASET.bit.GPIO6 = 1 //LED D16 点亮
#define LED7_ON GpioDataRegs.GPACLEAR.bit.GPIO6 = 1 //LED D16 熄灭
#define LED8_OFF GpioDataRegs.GPASET.bit.GPIO7 = 1 //LED D17 点亮
#define LED8_ON GpioDataRegs.GPACLEAR.bit.GPIO7 = 1 //LED D17 熄灭
#define DELAY_TIME 2000000 //延时时间
/*****************************************************************************************************/
/*********************************************函数声明************************************************/
void Init_LedGpio(void);
void delay(Uint32 t);
/*****************************************************************************************************/
void Init_LedGpio(void)
{
EALLOW; //关闭写保护
//LED D10
GpioCtrlRegs.GPBPUD.bit.GPIO60 = 0; // Enable pullup on GPIO11 使能 GPIO 上拉电阻
GpioDataRegs.GPBSET.bit.GPIO60 = 1; // Load output latch 设置 GPIO 输出高电平
GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 0; // GPIO11 = GPIO 设置为通用 GPIO 功能
GpioCtrlRegs.GPBDIR.bit.GPIO60 = 1; // GPIO11 = output 设置 GPIO 方向为输出
//LED D11
GpioCtrlRegs.GPBPUD.bit.GPIO61 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPBSET.bit.GPIO61 = 1; // Load output latch
GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO61 = 1; // GPIO11 = output
//LED D12
GpioCtrlRegs.GPAPUD.bit.GPIO2 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO2 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; // GPIO11 = output
//LED D13
GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO3 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO3 = 1; // GPIO11 = output
//LED D14
GpioCtrlRegs.GPAPUD.bit.GPIO4 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO4 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO4 = 1; // GPIO11 = output
//LED D15
GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO5 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO5 = 1; // GPIO11 = output
//LED D16
GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO6 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO6 = 1; // GPIO11 = output
//LED D17
GpioCtrlRegs.GPAPUD.bit.GPIO7 = 0; // Enable pullup on GPIO11
GpioDataRegs.GPASET.bit.GPIO7 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0; // GPIO11 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO7 = 1; // GPIO11 = output
EDIS; // 开启写保护
}
/*********************************************延时函数************************************************/
void delay(Uint32 t)
{
Uint32 i = 0;
for (i = 0; i < t; i++);
}
void main(void)
{
// Step 1. Initialize System Control: 系统时钟初始化
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
Init_LedGpio(); //初始化LED的GPIO
// For this example use the following configuration:
// Gpio_select();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
//--------------------------]]]]]]]]]]]]]]]]]]]--------------------------------------------------------
// 烧写FLASH更换cmd文件,添加下面2行代码,并添加DSP2833x_MeMCopy.c(DSP280x_CSMPasswords.asm)文件,重新编译
//------------------------------------------------------------------
// MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// InitFlash();
//-------------------------------------------------------------------
//]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// Step 5. User specific code:
while(1) //死循环
{
LED1_ON; //LED1 D10 点亮
delay(DELAY_TIME); //延时
LED1_OFF; //LED1 D10 熄灭
LED2_ON; //LED2 D11 点亮
delay(DELAY_TIME); //延时
LED2_OFF; //LED2 D11 熄灭
LED3_ON; //LED3 D12 点亮
delay(DELAY_TIME); //延时
LED3_OFF; //LED3 D12 熄灭
LED4_ON; //LED4 D13 点亮
delay(DELAY_TIME); //延时
LED4_OFF; //LED4 D13 熄灭
LED5_ON; //LED5 D14 点亮
delay(DELAY_TIME); //延时
LED5_OFF; //LED5 D14 熄灭
LED6_ON; //LED6 D15 点亮
delay(DELAY_TIME); //延时
LED6_OFF; //LED6 D15 熄灭
LED7_ON; //LED7 D16 点亮
delay(DELAY_TIME); //延时
LED7_OFF; //LED7 D16 熄灭
LED8_ON; //LED8 D17 点亮
delay(DELAY_TIME); //延时
LED8_OFF; //LED8 D17 熄灭
}
}
/*****************************************************************************************************/
蜂鸣器实验
电磁式蜂鸣器发声, 只需提供电源。
压电式蜂鸣器发声, 需提供一 定频率的脉冲信号; 改变频率,就可以调节蜂鸣器音调, 产生各种不同音色、音调的声音。 如果改变输出电平的高低电平占空比,则可以改变蜂鸣器的声音大小。
//功能:初始化GPIO口然后控制蜂鸣器发声
// 根据在RAM中调试的需要,这个项目配置成"boot to SARAM".2833x引导模式
// 表如下显示. 常用的还有"boot to Flash"模式,当程序在RAM调试完善后就
// 可以将代码烧进Flash中并使用"boot to Flash"引导模式.
// $Boot_Table:
//
// GPIO87 GPIO86 GPIO85 GPIO84
// XA15 XA14 XA13 XA12
// PU PU PU PU
// ==========================================
// 1 1 1 1 Jump to Flash
// 1 1 1 0 SCI-A boot
// 1 1 0 1 SPI-A boot
// 1 1 0 0 I2C-A boot
// 1 0 1 1 eCAN-A boot
// 1 0 1 0 McBSP-A boot
// 1 0 0 1 Jump to XINTF x16
// 1 0 0 0 Jump to XINTF x32
// 0 1 1 1 Jump to OTP
// 0 1 1 0 Parallel GPIO I/O boot
// 0 1 0 1 Parallel XINTF boot
// 0 1 0 0 Jump to SARAM <- "boot to SARAM"
// 0 0 1 1 Branch to check boot mode
// 0 0 1 0 Boot to flash, bypass ADC cal
// 0 0 0 1 Boot to SARAM, bypass ADC cal
// 0 0 0 0 Boot to SCI-A, bypass ADC cal
// Boot_Table_End$
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
/****************端口宏定义*****************/
#define BUZZ_CLK_GENER GpioDataRegs.GPATOGGLE.bit.GPIO10 = 1; //蜂鸣器控制IO,IO电平翻转, //产生控制脉冲
#define BELL_DIR GpioCtrlRegs.GPADIR.bit.GPIO10
#define BELL_DAT GpioDataRegs.GPADAT.bit.GPIO10
#define DISABLE_TIMER1_INT IER &= 0xFFFE;
#define ENABLE_TIMER1_INT IER |= M_INT1;
#define BUZZ_OFF GpioDataRegs.GPACLEAR.bit.GPIO10 = 1;
Uint16 Musi[23]={ //单位 us,不同频率下,蜂鸣器发出不同音调的声音
0,
3816, //L_do
3496, //L_re
3215, //L_mi
2865, //L_fa
2551, //L_so
2272, //L_la
2024, //L_xi
1912, //do
1703, //re
1517, //mi
1432, //fa
1275, //so
1136, //la
1013, //xi
956, //H_do
851, //H_re
758, //H_mi
716, //H_fa
638, //H_so
568, //H_la
506, //H_xi
0xFF //STOP
};
Uint16 Song[]={1,2,3,4,5,6,7}; //乐谱:do,re,mi,fa,so,la,xi
/****************函数声明*******************/
void Init_Bell(void);
interrupt void cpu_timer0_isr(void);
void Delay(Uint16 t);
void main(void)
{
Uint16 addr=0;
Uint16 k;
// 步骤 1. 初始化系统控制:
// 设置PLL, WatchDog, 使能外设时钟
// 下面这个函数可以从DSP280x_SysCtrl.c文件中找到.
InitSysCtrl();
// 步骤 2. 初始化通用输入输出多路复用器GPIO:
// 这个函数在DSP280x_Gpio.c源文件中被定义了
// 这个函数使GPIO控制类寄存器初始化到默认状态
BELL_DAT=0;
Init_Bell(); //设置蜂鸣器端口输出
// 步骤 3. 清除所有中断,初始化中断向量表:
// 禁止CPU全局中断
DINT;
// 初始化PIE控制寄存器到他们的默认状态.
// 这个默认状态就是禁止PIE中断及清除所有PIE中断标志
// 这个函数放在DSP280x_PieCtrl.c源文件里
InitPieCtrl();
// 禁止CPU中断和清除所有CPU中断标志
IER = 0x0000;
IFR = 0x0000;
//初始化PIE中断向量表,并使其指向中断服务子程序(ISR)
// 这些中断服务子程序被放在了DSP280x_DefaultIsr.c源文件中
// 这个函数放在了DSP280x_PieVect.c源文件里面.
InitPieVectTable();
// 本例中的中断重新映射到本文件中的中断服务子程序中
EALLOW; //解除寄存器保护
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS; // 添加寄存器保护
// 步骤 4.初始化片内外设:
InitCpuTimers(); // 本例仅需要初始化CPU定时器
// 配置CPU定时器0每秒发生一次中断
// 100MHz的CPU频率, 1000000 (单位是us),通过这两个参数计算出周期寄存器的值;
ConfigCpuTimer(&CpuTimer0, 150, 1000000);
StartCpuTimer0();
// 步骤 5. 用户特定的代码来允许中断
//允许CPU中断线INT1,它是连接到CPU定时器0的;
IER |= M_INT1;
// 在PIE组1中断7中使能TINT0中断;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
//使能全局中断和高优先级的实时调试事件;
EINT; // 使能全局中断INTM
ERTM; // 使能全局实时中断DBGM
// 步骤 6. 中断控制蜂鸣器开关频率,延时函数定义乐拍,7次循环分别让蜂鸣器响7种乐声:
for(k=0;k<7;k++)
{
StopCpuTimer0(); //停止计数
DISABLE_TIMER1_INT; //不使能定时中断
ConfigCpuTimer(&CpuTimer0, 150, Musi[Song[addr]+8]/2); //设置定时时间
StartCpuTimer0(); //重启定时器
ENABLE_TIMER1_INT; //使能定时中断
Delay(8); //音乐节拍延时
StopCpuTimer0(); //停止计数
DISABLE_TIMER1_INT; //不使能定时中断
BUZZ_OFF; //关闭蜂鸣器
Delay(2); //音乐停顿
addr++;
}
while(1);
}
/*------------------------------------------*/
/*形式参数:void */
/*返回值:void */
/*函数描述:初始化蜂鸣器端口为输出 */
/*------------------------------------------*/
void Init_Bell(void)
{
EALLOW; //解除寄存器保护
BELL_DIR=1;//Bell端口输出
EDIS; //寄存器保护
}
/*------------------------------------------*/
/*形式参数:void */
/*返回值:void */
/*函数描述:定时器CPU0中断服务子程序 */
/*------------------------------------------*/
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
BUZZ_CLK_GENER;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
void Delay(Uint16 t) //延时函数
{
Uint32 i=0;
Uint32 gain = 300000; //延时增益
Uint32 base=0;
base=gain*t;
for(i=0;i<=base;i++);
}
生日快乐歌
// DESCRIPTION:
//
// This example configures CPU Timer0, 1, and 2 and increments
// a counter each time the timers assert an interrupt.
//
// Watch Variables:
// CpuTimer0.InterruptCount
// CpuTimer1.InterruptCount
// CpuTimer2.InterruptCount
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
/************************************宏定义蜂鸣器相关操作*********************************************/
#define BUZZ_CLK_GENER GpioDataRegs.GPATOGGLE.bit.GPIO10 = 1; //蜂鸣器控制IO,IO电平翻转,产生控制脉冲
#define DISABLE_TIMER1_INT IER &= 0xFFFE; //关闭定时器
#define ENABLE_TIMER1_INT IER |= M_INT1; //打开定时器
#define BUZZ_OFF GpioDataRegs.GPASET.bit.GPIO10 = 1; //关闭蜂鸣器
/*****************************************************************************************************/
/*********************************************函数申明************************************************/
interrupt void cpu_timer0_isr(void);
void Show(void);
void Buzz_Gpio_Init(void);
void Delay(Uint16 t);
/*****************************************************************************************************/
/*****************************************初始化IO端口************************************************/
void Buzz_Gpio_Init(void)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO10 = 0; // Enable pullup on GPIO35
GpioDataRegs.GPASET.bit.GPIO10 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 0; // GPIO10 = GPIO
GpioCtrlRegs.GPADIR.bit.GPIO10 = 1; // GPIO10 = output
EDIS;
}
/*****************************************************************************************************/
/*********************************************定义曲谱************************************************/
Uint16 Musi[23]={ //单位 us,不同频率下,蜂鸣器发出不同音调的声音
0,
3816, //L_do
3496, //L_re
3215, //L_mi
2865, //L_fa
2551, //L_so
2272, //L_la
2024, //L_xi
1912, //do
1703, //re
1517, //mi
1432, //fa
1275, //so
1136, //la
1013, //xi
956, //H_do
851, //H_re
758, //H_mi
716, //H_fa
638, //H_so
568, //H_la
506, //H_xi
0xFF //STOP
};
/*
Uint16 Song[]={1,1,5,5,6,6,5,4,4,3,3,2,2,1,5,5,4,4,3,3,2,5,5,4,4,3,3,2,22}; //《小小星星亮晶晶》简谱
Uint16 DT[]={2,2,2,2,2,2,4,2,2,2,2,2,2,4,2,2,2,2,2,2,4,2,2,2,2,2,2,4}; //节拍
*/
Uint16 Song[]= {5,5,6,5,8,7,5,5,6,5,8,7,5,5,5,10,8,7,6,11,10,8,9,8,22 }; //《祝你生日快乐》简谱
Uint16 DT[]={2,2,5,4,6,8,2,2,5,6,6,9,4,2,5,4,6,12,2,2,5,6,8,12 }; //节拍
/*****************************************************************************************************/
/*********************************************延时函数************************************************/
void Delay(Uint16 t) //延时函数
{
Uint32 i=0;
Uint32 gain = 200000; //延时增益
Uint32 base=0;
base=gain*t;
for(i=0;i<=base;i++);
}
/*****************************************************************************************************/
/*********************************************歌曲演奏************************************************/
void Show(void)
{
Uint16 addr=0;
while(1)
{
if(Musi[Song[addr]]==0xFF)
{
return; //音乐播放结束
}
else
{
StopCpuTimer0(); //停止计数
DISABLE_TIMER1_INT; //不使能定时中断
ConfigCpuTimer(&CpuTimer0, 150, Musi[Song[addr]+8]); //设置定时时间
StartCpuTimer0(); //重启定时器
ENABLE_TIMER1_INT; //使能定时中断
Delay(DT[addr]); //音乐节拍延时
StopCpuTimer0(); //停止计数
DISABLE_TIMER1_INT; //不使能定时中断
BUZZ_OFF; //关闭蜂鸣器
Delay(8); //音乐停顿
addr++;
}
}
}
/*****************************************************************************************************/
// Prototype statements for functions found within this file.
interrupt void cpu_timer0_isr(void);
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
Buzz_Gpio_Init();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2833x_CpuTimers.c
InitCpuTimers(); // For this example, only initialize the Cpu Timers
ConfigCpuTimer(&CpuTimer0, 150, 50);
// To ensure precise timing, use write-only instructions to write to the entire register. Therefore, if any
// of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in DSP2833x_CpuTimers.h), the
// below settings must also be updated.
// CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
// CpuTimer1Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
// CpuTimer2Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
// Step 5. User specific code, enable interrupts:
// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional):
while(1)
{
Show();
}
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
BUZZ_CLK_GENER;
// Acknowledge this interrupt to receive more interrupts from group 1
// GpioDataRegs.GPBSET.bit.GPIO35 = 1;
// GpioDataRegs.GPBCLEAR.bit.GPIO35 = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
按键控制 LED 灯
#include "DSP2833x_Device.h"
#include "DSP2833x_examples.h"
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
InitSysCtrl();
// Step 2. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
InitPieVectTable();
// Configure GPIO60 and GPIO61 as a GPIO output pin
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO4 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO5 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO6 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO7 = 1;
EDIS;
// Configure GPIO58 and GPIO59 as a GPIO input pin
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO12 = 0; // input
GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO13 = 0; // input
GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO14 = 0; // input
GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO15 = 0; // input
EDIS;
while (1)
{
if (GpioDataRegs.GPADAT.bit.GPIO12==0)
GpioDataRegs.GPADAT.bit.GPIO4=0;
else
GpioDataRegs.GPADAT.bit.GPIO4=1;
if (GpioDataRegs.GPADAT.bit.GPIO13==0 & GpioDataRegs.GPADAT.bit.GPIO12==1)
GpioDataRegs.GPADAT.bit.GPIO5=0;
else
GpioDataRegs.GPADAT.bit.GPIO5=1;
if (GpioDataRegs.GPADAT.bit.GPIO14==0)
GpioDataRegs.GPADAT.bit.GPIO6=0;
else
GpioDataRegs.GPADAT.bit.GPIO6=1;
if (GpioDataRegs.GPADAT.bit.GPIO15==0)
GpioDataRegs.GPADAT.bit.GPIO7=0;
else
GpioDataRegs.GPADAT.bit.GPIO7=1;
}
}
问题一:将其中一个循环取消,设置一个灯不亮,出现另一个灯一直亮着的情况,按了对应的按键能看见明暗变化,但无法关闭该灯。问了老师,说循环太快了,IO 口的写入比较慢就容易出现bug,在出现问题的 IO 置位后面加上 DELAY_US(10); 果然有用了
然后自己 debug 了一下发现开始运行时,初始化 IO 口四个灯依次点亮,然后调试一圈循环以后,灯依次灭了。不太清楚运行的流程(存疑)但问题应该就是循环太快了,所以上次初始化IO 的一个灯正好亮着的时候,循环已经跳过了判断这个按键是否按下(如果没按下就熄灭),如此往复就一直亮着了,如果加了延时,或者手动单步调试,就能使功能完整。
D16 常亮 D17 不亮
while (1)
{
if (GpioDataRegs.GPADAT.bit.GPIO12==0)
GpioDataRegs.GPADAT.bit.GPIO4=0;
else
GpioDataRegs.GPADAT.bit.GPIO4=1; // D14 不亮
if (GpioDataRegs.GPADAT.bit.GPIO13==0 & GpioDataRegs.GPADAT.bit.GPIO12==1) //按位与 有0为0,全1为1 2 号按下和1号没按 才亮
GpioDataRegs.GPADAT.bit.GPIO5=0;
else
GpioDataRegs.GPADAT.bit.GPIO5=1; // D15不亮
if (GpioDataRegs.GPADAT.bit.GPIO14==0)
GpioDataRegs.GPADAT.bit.GPIO6=0;
else
GpioDataRegs.GPADAT.bit.GPIO6=1;
//if (GpioDataRegs.GPADAT.bit.GPIO15==0)
//GpioDataRegs.GPADAT.bit.GPIO7=0;
// else
GpioDataRegs.GPADAT.bit.GPIO7=1; // D17 不亮
}