Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pic.h>
- #include "delay.h"
- #define delete_flag timer_flag=0
- unsigned char timer;
- unsigned char impulse;
- unsigned char tone_that_not_play;
- static bit disable @ (unsigned)&PORTA*8+4;
- static bit out @ (unsigned)&PORTA*8+1;
- static bit out_inverse @ (unsigned)&PORTA*8+0;
- static unsigned char states@ 0x2e;
- static bit state_out@ (unsigned)&states*8+1;
- static bit timer_flag @ (unsigned)&INTCON*8+2;
- void
- DelayMs_2(unsigned char cnt)
- {
- unsigned char i;
- do { asm("CLRWDT");
- if(tone_1)
- return;
- i = 4;
- do {
- DelayUs(250);
- } while(--i);
- } while(--cnt);
- }
- void
- DelayMs(unsigned char cnt)
- {
- unsigned char i;
- do { asm("CLRWDT");
- i = 4;
- do {
- DelayUs(250);
- } while(--i);
- } while(--cnt);
- }
- void tone_1_2(unsigned char that_another_tone)
- {
- out=0;
- out_inverse=1;
- state_out=0;
- TMR0=timer;
- tone_1_2_start:
- delete_flag;
- disable=0;
- tone_1_2_playing:
- while(timer_flag==0)
- {
- if((TMR0-timer)>=impulse)
- {out=0;
- out_inverse=0;
- }
- }
- delete_flag;
- TMR0=timer;
- if(state_out==0)
- out_inverse=1;
- else
- out=1;
- state_out=state_out+1;
- if((PORTA&0x0c)==that_another_tone)
- return;
- asm("CLRWDT");
- goto tone_1_2_playing;
- }
- void main()
- {
- CMCON=0x07;//portA are normal inputs (for 16F628A)
- TRISA=0x0c;
- TRISB=0xff;
- disable=1;
- OPTION=0x81; //WDT 18 msec, preset TMR0 with 4
- out=0;
- out_inverse=0;
- timer=107;
- impulse=0x1d;
- tone_1_2(tone_that_not_play);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement