?? 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 + -