Rename tools to ao-<foo>
[fw/altos] / ao-tools / 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                 i = 211;
51                 while (--i != 0)
52                         nop();
53         }
54 }
55
56 void
57 tone (unsigned char n, unsigned char m)
58 {
59         unsigned char   i = 0;
60         while (--m != 0) {
61                 while (--i != 0) {
62                         P2 = 0xff;
63                         delay(n);
64                         P2 = 0xfe;
65                         delay(n);
66                 }
67         }
68 }
69
70 void
71 high() {
72         tone(1, 2);
73 }
74
75 void
76 low() {
77         tone(2, 1);
78 }
79
80 main ()
81 {
82         CLKCON = 0;
83         /* Set P2_0 to output */
84         P2DIR = 0x01;
85         P1INP = 0x00;
86         P2INP = 0x00;
87         for (;;) {
88                 high();
89 /*              low();          */
90         }
91 }