📄 jsq.c
字号:
// 倒数计时器实验
#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
interrupt void ISRTimer1(void);
interrupt void ISRTimer2(void);
void delay_loop(void); //短延时子程序
void delay_loop1(void); //长延时子程序
void Gpio_select(void); //设置GPIO端口
void Display(void); //显示子程序
unsigned int cont1=1; //十位数设置
unsigned int cont2=0; //个位数设置
unsigned int Set_Flag;
//unsigned int Stop_Flag=0;
long int k;
unsigned int Discode[16]={0x3F,0x06,0x5B,0x4F,
0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,
0x39,0x3E,0x79,0x71
};// 0-9及A-F的显示代码
void main(void)
{
InitSysCtrl();
// Disable and clear all CPU interrupts:
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitCpuTimers();
EALLOW;
PieVectTable.XINT13 = &ISRTimer1;
PieVectTable.TINT2 = &ISRTimer2;
EDIS;
IER |= M_INT13;
IER |= M_INT14;
EINT;
ERTM;
Gpio_select();
while(1)
{
Display();//显示初始数据
//设置记数值
if(GpioDataRegs.GPADAT.bit.GPIOA12==0)
{
Set_Flag=0;
Display();
ConfigCpuTimer(&CpuTimer1, 150, 1000);
StartCpuTimer1();
}
if(GpioDataRegs.GPADAT.bit.GPIOA13==0)
{
Set_Flag=1;
Display();
ConfigCpuTimer(&CpuTimer1, 150, 1000);
StartCpuTimer1();
}
//倒计数判断
if(GpioDataRegs.GPADAT.bit.GPIOA11==0)
{
ConfigCpuTimer(&CpuTimer2, 150, 1000000);
StartCpuTimer2();
}
}
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.all=0x0000;
GpioMuxRegs.GPDMUX.all=0x0000;
GpioMuxRegs.GPADIR.all=0xC7FF; //Set GPIOA PORTs DIR
GpioMuxRegs.GPDDIR.all=0xC7FF; //Set GPIOD PORTs DIR
GpioMuxRegs.GPAQUAL.all=0x0000; // Set GPIOA input qualifier values
GpioMuxRegs.GPDQUAL.all=0x0000; // Set GPIOD input qualifier values
EDIS;
}
void Display()
{
GpioDataRegs.GPADAT.all =Discode[cont1];//显示十位数
GpioDataRegs.GPDDAT.bit.GPIOD1=1;
delay_loop();
GpioDataRegs.GPDDAT.bit.GPIOD1=0;
GpioDataRegs.GPADAT.all =Discode[cont2];//显示个位数
GpioDataRegs.GPDDAT.bit.GPIOD0=1;
delay_loop();
GpioDataRegs.GPDDAT.bit.GPIOD0=0;
}
//CUPTimer1中断服务子程序
interrupt void ISRTimer1(void)
{
StopCpuTimer1();
//个位数设定
if( Set_Flag==1)
{
if(cont2==9) cont2=0;
else cont2++;
}
//十位数设定
if( Set_Flag==0)
{
if(cont1==9) cont1=0;
else cont1++;
}
Display();
}
//CUPTimer2中断服务子程序
interrupt void ISRTimer2(void) //倒计数
{
// CpuTimer2.InterruptCount++;
if(cont2!=0) //个位减
cont2--;
else
if(cont1!=0) //十位减
{
cont2=9;
cont1--;
}
if(cont1==0 && cont2==0) //中止并复位
{
StopCpuTimer2();
Display();
GpioDataRegs.GPADAT.bit.GPIOA7=1; //蜂鸣器置位
GpioDataRegs.GPADAT.bit.GPIOA14=1; //发光管置位
delay_loop1();
GpioDataRegs.GPADAT.bit.GPIOA14=0;
GpioDataRegs.GPADAT.bit.GPIOA15=0;
}
Display();
}
void delay_loop()
{
for(k=0;k<1000;k++) {}
}
void delay_loop1()
{
for(k=0;k<11000000; k++) {}
}
//===========================================================================
// End Of Program.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -