SHOW:
|
|
- or go back to the newest paste.
1 | #include <pic.h> | |
2 | #include "delay.h" | |
3 | ||
4 | #define delete_flag timer_flag=0 | |
5 | ||
6 | unsigned char timer; | |
7 | unsigned char impulse; | |
8 | unsigned char tone_that_not_play; | |
9 | static bit disable @ (unsigned)&PORTA*8+4; | |
10 | static bit out @ (unsigned)&PORTA*8+1; | |
11 | static bit out_inverse @ (unsigned)&PORTA*8+0; | |
12 | static unsigned char states@ 0x2e; | |
13 | static bit state_out@ (unsigned)&states*8+1; | |
14 | static bit timer_flag @ (unsigned)&INTCON*8+2; | |
15 | ||
16 | void | |
17 | DelayMs_2(unsigned char cnt) | |
18 | { | |
19 | unsigned char i; | |
20 | do { asm("CLRWDT"); | |
21 | - | if(ton_1) |
21 | + | if(tone_1) |
22 | return; | |
23 | i = 4; | |
24 | do { | |
25 | DelayUs(250); | |
26 | } while(--i); | |
27 | } while(--cnt); | |
28 | } | |
29 | ||
30 | void | |
31 | DelayMs(unsigned char cnt) | |
32 | { | |
33 | unsigned char i; | |
34 | do { asm("CLRWDT"); | |
35 | i = 4; | |
36 | do { | |
37 | DelayUs(250); | |
38 | } while(--i); | |
39 | } while(--cnt); | |
40 | } | |
41 | ||
42 | void tone_1_2(unsigned char that_another_tone) | |
43 | { | |
44 | out=0; | |
45 | out_inverse=1; | |
46 | state_out=0; | |
47 | TMR0=timer; | |
48 | tone_1_2_start: | |
49 | delete_flag; | |
50 | disable=0; | |
51 | tone_1_2_playing: | |
52 | while(timer_flag==0) | |
53 | { | |
54 | if((TMR0-timer)>=impulse) | |
55 | {out=0; | |
56 | out_inverse=0; | |
57 | } | |
58 | } | |
59 | delete_flag; | |
60 | TMR0=timer; | |
61 | if(state_out==0) | |
62 | out_inverse=1; | |
63 | else | |
64 | out=1; | |
65 | state_out=state_out+1; | |
66 | if((PORTA&0x0c)==that_another_tone) | |
67 | return; | |
68 | asm("CLRWDT"); | |
69 | goto tone_1_2_playing; | |
70 | } | |
71 | ||
72 | void main() | |
73 | { | |
74 | CMCON=0x07;//portA are normal inputs (for 16F628A) | |
75 | TRISA=0x0c; | |
76 | TRISB=0xff; | |
77 | disable=1; | |
78 | OPTION=0x81; //WDT 18 msec, preset TMR0 with 4 | |
79 | ||
80 | out=0; | |
81 | out_inverse=0; | |
82 | ||
83 | timer=107; | |
84 | impulse=0x1d; | |
85 | ||
86 | tone_1_2(tone_that_not_play); | |
87 | } |