介面設計專題實務 object teaching of interface design 實驗五 cpu 計時器實驗
DESCRIPTION
介面設計專題實務 Object Teaching of Interface Design 實驗五 CPU 計時器實驗. 授課教師:任才俊. 實驗目的. (a) 熟悉 F2812 的 CPU 計時器。 (b) 掌握 F2812 的 CPU 計時器的控制方法。 (c) 學會使用 CPU 計時器中斷方式控制程式流程。. 實驗說明. F2812 的 CPU 計時器不同於事件管理器模組 (EVA 、 EVB) 中的通用計時器 (GP) 。 - PowerPoint PPT PresentationTRANSCRIPT
介面設計專題實務 Object Teaching of Interface Design
實驗五 CPU 計時器實驗
授課教師:任才俊
實驗目的 • (a) 熟悉 F2812 的 CPU 計時器。• (b) 掌握 F2812 的 CPU 計時器的控制方法
。• (c) 學會使用 CPU 計時器中斷方式控制程
式流程。
實驗說明 • F2812 的 CPU 計時器不同於事件管理器模組
(EVA 、 EVB) 中的通用計時器 (GP) 。• F2812 的 CPU 共有三個計時器,其中, CPU 計
時器 1 和 2 被保留用做即時操作系統 OS( 例如DSPBIOS) , CPU 計時器 0 可以供用戶使用。
• 計時器的一般操作如下:將週期暫存器 PRDH: PRD 中的值裝入 32 位元計數器暫存器 TIMH: TIM 。 然 後 計 數 器 暫 存 器 以 F281x 的SYSCLKOUT 速率遞減。當計數器減到 0 時,就會產生一個計時中斷輸出信號 ( 一個中斷脈衝 ) 。
/*************************頭文件 *********************************/#include "DSP281x_Device.h" // DSP281x Headerfile Include File#include "DSP281x_Examples.h" // DSP281x Examples Include File
/*************************定義函數說明 ***************************/// Prototype statements for functions found within this file.interrupt void cpu_timer0_isr(void);
/*************************主程序 *********************************/void main(void){// PLL, WatchDog, enable Peripheral Clocks// This example function is found in the DSP281x_SysCtrl.c file. InitSysCtrl();
// Disable CPU interrupts DINT;
// Initialize the PIE control registers to their default state. 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();
// 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
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0 to interrupt every second:// 100MHz CPU Freq, 1 second Period (in uSeconds) ConfigCpuTimer(&CpuTimer0, 150, 1000000); StartCpuTimer0();
// Enable CPU INT1 which is connected to CPU-Timer 0: 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
for(;;){ if(CpuTimer0.InterruptCount<1)
{asm(" nop ");*(int *)0x88001=0x0081;
}else if(CpuTimer0.InterruptCount<2){
asm(" nop ");*(int *)0x88001=0x0042;
}else if(CpuTimer0.InterruptCount<3){
asm(" nop ");*(int *)0x88001=0x0024;
}else if(CpuTimer0.InterruptCount<4){
asm(" nop ");*(int *)0x88001=0x0018;
}
else if(CpuTimer0.InterruptCount<5){
asm(" nop ");*(int *)0x88001=0x0024;
}else if(CpuTimer0.InterruptCount<6){
asm(" nop ");*(int *)0x88001=0x0042;
}else if(CpuTimer0.InterruptCount<7){
asm(" nop ");*(int *)0x88001=0x0081;
}else
CpuTimer0.InterruptCount = 0;
}}
interrupt void cpu_timer0_isr(void){
CpuTimer0.InterruptCount++;
// Acknowledge this interrupt to receive more interrupts from group 1PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
練習題• 更改範例程式,試以開關 1 設定 LED 每 0.5 秒動作一次;試以開關 2 設定 LED 每 1 秒動作一次;試以開關 3 設定 LED 每 2 秒動作一次;試以開關 4 設定LED 每 3 秒動作一次。 ( 不可利用中斷除頻 )
• 設計一個跑馬燈,以遞增的方式亮燈,讓 8 顆 LED依序點亮,開關 1 設定 LED 每 0.5 秒動作一輪;試以開關 2 設定 LED 每 1 秒動作一輪;試以開關 3 設定 LED 每 2 秒動作一輪;試以開關 4 設定 LED 每 3秒動作一輪。 ( 不可利用中斷除頻 ) 。