- #include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
- #include "DSP2833x_Examples.h" // DSP2833x Examples Include File
- /****************端口宏定义*****************/
- #define S1 GpioDataRegs.GPADAT.bit.GPIO12
- /****************常量宏定义*****************/
- /***************全局变量定义****************/
- Uint32 temp;
- Uint32 direction;
- /****************函数声明*******************/
- void Gpio_select(void); //gpio端口配置子程序
- void delay_loop(void);
- void Scan_Key(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
- // 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();
-
- // 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:
- GpioDataRegs.GPBDAT.all =0x30000000;//GPIO60,61,64,65,66,67,68输出清1,使LED1灯灭
- GpioDataRegs.GPCDAT.all =0x0000001f;
- direction=0;
- for(;;)
- {
- unsigned int i;
- if(direction%2!=0)//控制流水灯的方向
- temp=0x10000000;
- else
- temp=0x20000000;
- while(temp!=0x40000000&&temp!=0x08000000)//轮流点亮GPIO60,61;
- {
- //delay_loop();
- GpioDataRegs.GPBCLEAR.all |=temp;
- delay_loop();
- GpioDataRegs.GPBSET.all |=temp;
- if(direction%2!=0)//控制流水灯的方向
- temp<<=1;
- else
- temp>>=1;
-
- }
- if(temp==0x40000000)//根据temp值选择GPIO64-GPIO67是从64开始还是从67开始点亮LED
- temp=0x00000001;
- else
- temp=0x00000010;
- while(temp!=0x00000020&&temp!=0x00000000)//轮流点亮GPIO64-GPIO67;
- {
- //delay_loop();
- GpioDataRegs.GPCCLEAR.all |=temp;
- delay_loop();
-
- GpioDataRegs.GPCSET.all |=temp;
- if(direction%2!=0)//控制流水灯的方向
- temp<<=1;
- else
- temp>>=1;
-
-
- }
-
- }
- }
- void delay_loop()
- {
- Uint32 i;
- Uint32 j;
- for(i=0;i<4;i++)
- for (j = 0; j < 100000; j++) {Scan_Key();}
- }
- /*------------------------------------------*/
- /*形式参数:void */
- /*返回值:void */
- /*函数描述:扫描键值 */
- /*------------------------------------------*/
- void Scan_Key(void)
- {
- Uint32 i,j;
- if(S1==0)//扫描是否按键按下
- {
- for(i=0;i<10000;i++); //键盘消抖动
- if(S1==0)
- {
- direction+=1;
- for(i=0;i<32;i++)
- for (j = 0; j < 100000; j++) {}
- /*
- if(direction%2!=0)//第一按下按键LED停止闪烁,下次按下时LED又开始闪烁
- {
- while(S1!=0);
- }
- */
复制代码
此帖出自
小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>