View difference between Paste ID: BvZ3TWe3 and h7LqeSdV
SHOW: | | - or go back to the newest paste.
1
#include <pic.h>
2
#include  "delay.h"
3
4
#define brisi_flag timer_flag=0
5
6
unsigned char timer;
7
unsigned char impuls;
8
unsigned char ton_koji_ne_svira;
9
static bit disable @ (unsigned)&PORTA*8+4;
10
static bit izlaz @ (unsigned)&PORTA*8+1;
11
static bit izlaz_inv @ (unsigned)&PORTA*8+0;
12
static unsigned char stanja @ 0x2e;
13
static bit stanje_izlaza @ (unsigned)&stanja*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)
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 ton_1_2(unsigned char onaj_drugi_ton)
43
{
44
	 izlaz=0;
45
	 izlaz_inv=1;
46
	 stanje_izlaza=0;
47
	 TMR0=timer; 
48
	 ton_1_2_start:
49
	 brisi_flag;
50
 	 disable=0;
51
	 ton_1_2_sviranje:
52
	 while(timer_flag==0)
53
	      {
54
		if((TMR0-timer)>=impuls)
55
	         {izlaz=0;
56
	          izlaz_inv=0;
57
	         }
58
	      }
59
	 brisi_flag;
60
	 TMR0=timer;
61
	 if(stanje_izlaza==0)
62
	    izlaz_inv=1;
63
	 else   
64
	    izlaz=1;
65
	 stanje_izlaza=stanje_izlaza+1;   
66
	 if((PORTA&0x0c)==onaj_drugi_ton)
67
	    return;
68
	 asm("CLRWDT");
69
	 goto ton_1_2_sviranje;                 
70
}
71
72
void main()
73
{
74
 	CMCON=0x07;//portA su normalni ulazi (za 16F628A)
75
 	TRISA=0x0c;
76
	TRISB=0xff;
77
	 disable=1;
78
 	OPTION=0x81;   //WDT na 18 msec, preset TMR0 sa 4   
79
	
80
	izlaz=0;
81
 	izlaz_inv=0;
82
83
 	timer=107;
84
        impuls=0x1d;
85
86
 	ton_1_2(ton_koji_ne_svira);
87
}