08422082755f07067bbf5f3c67c8edc2a23d9eb1
[fw/altos] / target / beep / beep.c
1 /*
2  * Copyright © 2008 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 sfr at 0x80 P0;
20 sfr at 0x90 P1;
21 sfr at 0xA0 P2;
22 sfr at 0xC6 CLKCON;
23
24 sfr at 0xF1 PERCFG;
25 sfr at 0xF2 ADCCFG;
26 sfr at 0xF3 P0SEL;
27 sfr at 0xF4 P1SEL;
28 sfr at 0xF5 P2SEL;
29
30 sfr at 0xFD P0DIR;
31 sfr at 0xFE P1DIR;
32 sfr at 0xFF P2DIR;
33 sfr at 0x8F P0INP;
34 sfr at 0xF6 P1INP;
35 sfr at 0xF7 P2INP;
36
37 sfr at 0x89 P0IFG;
38 sfr at 0x8A P1IFG;
39 sfr at 0x8B P2IFG;
40
41 #define nop()   _asm nop _endasm;
42
43 void
44 delay (unsigned char n)
45 {
46         unsigned char i = 0;
47
48         n <<= 1;
49         while (--n != 0)
50                 while (--i != 0)
51                         nop();
52 }
53
54 void
55 tone (unsigned char n, unsigned char m)
56 {
57         unsigned char   i = 0;
58         while (--m != 0) {
59                 while (--i != 0) {
60                         P2 = 0xff;
61                         delay(n);
62                         P2 = 0xfe;
63                         delay(n);
64                 }
65         }
66 }
67
68 void
69 high() {
70         tone(1, 2);
71 }
72
73 void
74 low() {
75         tone(2, 1);
76 }
77
78 main ()
79 {
80         CLKCON = 0;
81         /* Set p1_1 to output */
82         P2DIR = 0x01;
83         P1INP = 0x00;
84         P2INP = 0x00;
85         for (;;) {
86                 high();
87                 low();
88         }
89 }