1 |
/****************************************************/ |
---|
2 |
/* Examples Program For "CP-JR ARM7 LPC2368" */ |
---|
3 |
/* Target MCU : Philips ARM7-LPC2368 */ |
---|
4 |
/* : X-TAL : 12.00 MHz */ |
---|
5 |
/* : PLL Setup = MSEL(12),NSEL(1) */ |
---|
6 |
/* Keil Editor : uVision3 V3.53a */ |
---|
7 |
/* Compiler : Keil Realview MDK V3.20 */ |
---|
8 |
/* Create By : Eakachai Makarn (WWW.ETT.CO.TH) */ |
---|
9 |
/* Last Update : 12/November/2007 */ |
---|
10 |
/* Function : Example Generate Beep on Speaker */ |
---|
11 |
/****************************************************/ |
---|
12 |
|
---|
13 |
#include "LPC23xx.H" // LPC2368 MPU Register |
---|
14 |
|
---|
15 |
// Pin I/O Speaker Control Maskbit |
---|
16 |
#define SPEAKER 0x00000100 // P2.8(0000 0000 0000 0000 0000 000x 0000 0000) |
---|
17 |
|
---|
18 |
#define SPEAKER_ON() FIO2SET = SPEAKER // Speaker Pin = 1 (ON LED) |
---|
19 |
#define SPEAKER_OFF() FIO2CLR = SPEAKER // Speaker Pin = 0 (OFF LED) |
---|
20 |
|
---|
21 |
/* pototype section */ |
---|
22 |
void delay(unsigned long int); // Delay Time Function |
---|
23 |
|
---|
24 |
int main(void) |
---|
25 |
{ |
---|
26 |
unsigned int beep_time; |
---|
27 |
|
---|
28 |
// Config Pin GPIO2[8] |
---|
29 |
PINSEL4 &= 0xFFFCFFFF; // P2[8] = GPIO Function(xxxx xxxx xxxx xx00 xxxx xxxx xxxx xxxx) |
---|
30 |
FIO2DIR |= SPEAKER; // Set GPIO-2[8] = Output(xxxx xxxx xxxx xxxx xxxx xxx1 xxxx xxxx) |
---|
31 |
SPEAKER_OFF(); // Default Speaker Status |
---|
32 |
|
---|
33 |
// Loop Generate Beep on Speaker(P2.8) |
---|
34 |
while(1) // Loop Continue |
---|
35 |
{ |
---|
36 |
for (beep_time = 0; beep_time < 500; beep_time++) // Start Beep |
---|
37 |
{ |
---|
38 |
SPEAKER_ON(); // ON Speaker |
---|
39 |
delay(5000); |
---|
40 |
|
---|
41 |
SPEAKER_OFF(); // OFF Speaker |
---|
42 |
delay(5000); |
---|
43 |
} |
---|
44 |
|
---|
45 |
delay(10000000); // Stop Beep |
---|
46 |
} |
---|
47 |
} |
---|
48 |
|
---|
49 |
/***********************/ |
---|
50 |
/* Delay Time Function */ |
---|
51 |
/* 1-4294967296 */ |
---|
52 |
/***********************/ |
---|
53 |
void delay(unsigned long int count1) |
---|
54 |
{ |
---|
55 |
while(count1 > 0) {count1--;} // Loop Decrease Counter |
---|
56 |
} |
---|