📄 delay.c
字号:
/*****************************************************/
/* Target MCU : Philips ARM7-LPC2103 */
/* X-TAL : 19.6608 MHz */
/* : Run Speed 58.9824MHz (With PLL) */
/* Keil Editor : uVision3 V3.03a */
/* Compiler : Keil CARM V2.50a */
/* Create By : Pascal Gubler */
/* Last Update : 04-09-2006 KMIT North Bankok */
/* : WWW.KMITNB.AC.TH */
/* Function : Delay Functions for Robotic Purposes*/
/*****************************************************/
//*Specifications
//***************
//* MAT0.3 = Delay in s/ms/us (NoPortConnected)
//* MAX Delay 15s!
//* --> Ports are not Connected
//* --> Timer 0 is used for Delay Functions
#include "LPC214x.H" // LPC2148 MPU Register
//*********************************/;
//* Initialize the Timer */;
//*********************************/;
void init_delay(void){
//Initial Timer Operate
T0TCR &= 0xFFFFFFFE;
T0TC = 0x00000000; // Timer Start = 0
T0PR = 0x00000000; // Prescale = 0
T0PC = 0x00000000; // Prescale Count = 0
//Initial Timer0 Match Operate
T0MCR &= 0xFFFE; // Disable Interrupt on Match-0 (1111 1111 1111 111x)
T0MCR &= 0xFFFD; // Disable Reset TC on Match-0 (1111 1111 1111 11x1)
T0MCR &= 0xFFFB; // Disable Stop TC on Match-0 (1111 1111 1111 1x11)
T0MCR &= 0xFFF7; // Disable Interrupt on Match-1 (1111 1111 1111 x111)
T0MCR &= 0xFFEF; // Disable Reset TC on Match-1 (1111 1111 111x 1111)
T0MCR &= 0xFFDF; // Disable Stop TC on Match-1 (1111 1111 11x1 1111)
T0MCR &= 0xFFBF; // Disable Interrupt on Match-2 (1111 1111 1x11 1111)
T0MCR &= 0xFF7F; // Disable Reset TC on Match-2 (1111 1111 x111 1111)
T0MCR &= 0xFEFF; // Disable Stop TC on Match-2 (1111 111x 1111 1111)
T0MCR |= 0x0800; // Enable Stop TC on Match-3 (0000 x000 0000 0000)
T0MCR |= 0x0400; // Enable Reset TC on Match-3 (0000 0x00 0000 0000)
T0MCR &= 0xFDFF; // Disable Interrupt on Match-3 (1111 x111 1111 1111)
//Initial Timer0 Interrupt
T0IR &= 0xFE; // Disable MAT0 Interrupt (1111111x)
T0IR &= 0xFD; // Disable MAT1 Interrupt (111111x1)
T0IR &= 0xFB; // Disable MAT2 Interrupt (11111x11)
T0IR &= 0xF7; // Disable MAT3 Interrupt (1111x111)
T0IR &= 0xEF; // Disable CAP0 Interrupt (111x1111)
T0IR &= 0xDF; // Disable CAP1 Interrupt (11x11111)
T0IR &= 0xBF; // Disable CAP2 Interrupt (1x111111)
//Initial Timer0 External Match Register
T0EMR = 0x000; //Set States to 0000 0000 0000 0000
T0EMR |= 0x800; //Set Match0.3 to Go High on Match 10xx xxxx xxxx
T0EMR &= 0xCFF; //Set Match0.2 to Do Nothing on Match xx00 xxxx xxxx
T0EMR &= 0xF3F; //Set Match0.1 to Do Nothing on Match xxxx 00xx xxxx
T0EMR &= 0xFCF; //Set Match0.0 to Do Nothing on Match xxxx xx00 xxxx
}
//*********************************/;
//* Delay Function [Microseconds] */;
//*********************************/;
void delay_us(unsigned int val){
T0MR3 = val*29;
T0EMR &= 0xFFFFFFF7;
T0TC = 0x00000000;
T0TCR=1;
while((T0EMR & 0x00000008)==0);
}
//************************************/
//* Delay Function [Miliseconds] */
//************************************/
void delay_ms(unsigned int val){
T0MR3 = val*29498;
T0EMR &= 0xFFFFFFF7;
T0TC = 0x00000000;
T0TCR=1;
while((T0EMR & 0x00000008)==0);
}
//************************************/
//* Delay Function [Seconds] */
//************************************/
void delay_s(unsigned int val){
T0MR3 = val*29498500;
T0EMR &= 0xFFFFFFF7;
T0TC = 0x00000000;
T0TCR=1;
while((T0EMR & 0x00000008)==0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -