unwanted reset

Discussion in 'Embedded Systems and Microcontrollers' started by Far, Jul 8, 2009.

  1. Far

    Thread Starter Member

    May 11, 2009
    20
    0
    I have been design a simple pulse generator with an ATmega8. but when i run it in proteus with no reason it starts to reset. i have some touch button to select some modes. the reset happens when i click at this buttons. when i setup the circuit this occurs again. I have not use watchdog timer too! what should i do?
    need your help!
     
    Last edited: Jul 8, 2009
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    If you have configured pin 1 as a reset pin then you have to tight it to Vcc via a resistor. Use a 10K one.
     
  3. Far

    Thread Starter Member

    May 11, 2009
    20
    0
    my circuit is very simple. i just have a LCD and an ATmega8. the reset pin has been pulled up with a resistor. there is no noise source around it. i think its the program problem. here is the cods
    thanks for your help:)


    Code ( (Unknown Language)):
    1. Project :
    2. Version :
    3. Date    : 5/18/2009
    4. Author  : l                              
    5. Company : l                              
    6. Comments:
    7.  
    8.  
    9. Chip type           : ATmega8
    10. Program type        : Application
    11. Clock frequency     : 1.000000 MHz
    12. Memory model        : Small
    13. External SRAM size  : 0
    14. Data Stack size     : 256
    15. *****************************************************/
    16.  
    17. #include <mega8.h>
    18. #include <delay.h>
    19. #include <stdio.h>
    20. // Alphanumeric LCD Module functions
    21. #asm
    22.    .equ __lcd_port=0x18 ;PORTB
    23. #endasm
    24. #include <lcd.h>
    25. char bufer[10];
    26. int key2,i,key,b,mode,count,g=0,h,f,ab,n,a,j,p,v,l,k;  
    27. unsigned int time1,time180,time2,time60,time120,time3,time4,time,d;
    28. void atash(int a);        
    29. int detect_pulse(void);
    30. interrupt [TIM1_OVF] void timer1_ovf_isr(void)
    31. {
    32. // Place your code here  
    33. if(mode==1){
    34. if(h==0){
    35. PORTD=0x01;
    36. TCNT1=time180;
    37. TCCR1B=0x01;
    38. h=1;
    39. g=1;
    40. }  
    41. g++;
    42. if(g>2){
    43. if(g==3){
    44. PORTD=0x02;
    45. d++;
    46. }
    47. /*if(d==6){
    48. d=0;
    49. TCCR1B=0x00;
    50. TCNT1=0x00;
    51. #asm("cli");
    52. mode=1;
    53. p=detect_pulse();
    54. }*/
    55. if(g==4){
    56. PORTD=0x01;
    57. g=2;
    58. }
    59. TCNT1=time180;
    60. TCCR1B=0x01;
    61. }  
    62. }
    63. if(mode==2){
    64. if(h==0){
    65. PORTD=0x03;
    66. TCNT1=time180;
    67. TCCR1B=0x01;
    68. h=1;
    69. g=1;
    70. }  
    71. g++;
    72. if(g>2){
    73. if(g==3)
    74. PORTD=0x0c;
    75. if(g==4){
    76. PORTD=0x03;
    77. g=2;
    78. }
    79. TCNT1=time180;
    80. TCCR1B=0x01;
    81. }  
    82. }
    83. if(mode==3){
    84. if(h==0){
    85. PORTD=0x01;
    86. TCNT1=time120;
    87. TCCR1B=0x01;
    88. h=1;
    89. g=0;
    90. }  
    91. g++;
    92. if(g>2){
    93. if(g==3)
    94. PORTD=0x02;
    95. if(g==4)
    96. PORTD=0x04;
    97. if(g==5){
    98. PORTD=0x01;
    99.  
    100. g=2;
    101. }
    102. TCNT1=time120;
    103. TCCR1B=0x01;
    104. }  
    105. }
    106. if(mode==4){
    107. g++;
    108. if(h==0){
    109. PORTD=0x01;
    110. TCNT1=time60;
    111. TCCR1B=0x01;
    112. h=1;
    113. g=2;
    114. }  
    115. if(g>2){
    116. TCNT1=time60;
    117. if(g==3)
    118. PORTD=0x02;
    119. if(g==4)
    120. PORTD=0x04;
    121. if(g==5)
    122. PORTD=0x08;
    123. if(g==6)
    124. PORTD=0x10;
    125. if(g==7)
    126. PORTD=0x20;
    127. if(g==8){
    128. PORTD=0x01;
    129. g=2;
    130. }
    131. }  
    132. }
    133. }
    134.  
    135. // Declare your global variables here
    136. int set_key(void);
    137. int set_angle(void);
    138.  
    139. void main(void)
    140. {
    141. // Declare your local variables here
    142. char bufer1[10];
    143. float t,t120,t60,div;
    144. unsigned int angle;
    145. PORTB=0x00;
    146. DDRB=0x00;
    147. PORTC=0x00;
    148. DDRC=0x00;
    149. PORTD=0x00;
    150. DDRD=0x3F;
    151. TCCR0=0x00;
    152. TCNT0=0x00;
    153. TCCR1B=0x00;
    154. TCCR1A=0x00;
    155. TCNT1H=0x00;
    156. TCNT1L=0x00;
    157. ICR1H=0x00;
    158. ICR1L=0x00;
    159. OCR1AH=0x00;
    160. OCR1AL=0x00;
    161. OCR1BH=0x00;
    162. OCR1BL=0x00;
    163. TCCR2=0x00;
    164. TCNT2=0x00;
    165. OCR2=0x00;
    166. GICR|=0x00;
    167. MCUCR=0x00;
    168. GIFR=0x00;
    169. TIMSK=0x04;
    170. // LCD module initialization
    171. #asm("cli")
    172. lcd_init(16);
    173. lcd_clear();    
    174. lcd_putsf("ENTER THE MODE");
    175. goto loop1;
    176. loop1:
    177. while(1){
    178. key=set_key();
    179.  if(key>4){
    180.  key=0;
    181.  i=0;
    182.  }  
    183.   mode=key;
    184.  lcd_clear();
    185.  sprintf(bufer,"NUMBER OF MODE:%i",key);
    186.  lcd_puts(bufer);
    187.  delay_ms(500);
    188.  key2 =PINC.3 & 0x01;
    189.  if(key2 ==0x01){
    190.    delay_ms(50);
    191.    key2 =PINC.3 & 0x01;  
    192.       if(key2 ==0x01)
    193.        b=1;
    194.   }
    195.  if(key>0 & b==1){
    196.  lcd_clear();
    197.  lcd_putsf("MODE IS ACCEPT");
    198.  delay_ms(500);
    199.   lcd_clear();
    200.   lcd_gotoxy(0,0);
    201.   sprintf(bufer1,"MODE=%i",mode);
    202.   lcd_puts(bufer1);
    203.   delay_ms(1000);
    204.   goto angel;
    205.  }
    206. }
    207.  br:
    208.   switch(key)
    209. {
    210.     case 1:
    211.      goto mode1;
    212.    case 2:
    213.      goto mode2;
    214.    case 3:
    215.      goto mode3;
    216.    case 4:
    217.      goto mode4;
    218.    case 0:
    219.    goto loop1;
    220.  }
    221. //////////////////////////////
    222. mode1:
    223. mode=1;
    224.  lcd_clear();
    225.  lcd_putsf("mode=1");
    226. div=180/angle;
    227. t=0.01/div;
    228. t=t/0.000001;
    229. time1=65535-t;
    230. time180=65535-10000;
    231. p=detect_pulse();
    232. //////////////////////////////
    233. mode2:
    234. mode=2;
    235.  lcd_clear();
    236.  lcd_putsf("mode=2");
    237. div=angle/180;
    238. t=0.01/div;
    239. t=t/0.000001;
    240. time2=65535-t;
    241. time180=65535-10000;
    242. p=detect_pulse();
    243. //////////////////////////////
    244. mode3:
    245. mode=3;
    246. div=180/angle;
    247. t=0.01/div;
    248. t=t/0.000001;
    249. time3=65535-t;
    250. t120=2*0.01/3;
    251. t120=65535-t120;
    252. t120=t120/0.000001;
    253. time120=65535-t120;
    254. TCCR1B=0x00;
    255. p=detect_pulse();
    256. //////////////////////////////
    257. mode4:
    258. mode=4;
    259. t60=0.01/3;
    260. t60=t60/0.000001;
    261. t60=65535-t60;
    262. time60=t60;
    263. div=180/angle;
    264. t=0.01/div;
    265. t=t/0.000001;
    266. time4=65535-t;
    267.  p=detect_pulse();
    268.  
    269. //////////////////////////////  
    270. angel:
    271. f=0;
    272. angle=0;
    273. goto y;
    274. y:
    275. ab=set_angle();
    276. angle=ab*12;
    277. if (angle>170 | angle<0)
    278. {
    279. angle=168;
    280. f=14;
    281. }  
    282. sprintf(bufer,"ANGLE:%i DEG",angle);
    283.  lcd_gotoxy(0,1);
    284.  lcd_puts(bufer);
    285.  delay_ms(500);
    286.  b=0;
    287.  key2 =PINC.3 & 0x01;
    288.  if(key2 ==0x01)
    289.  {
    290.    delay_ms(50);
    291.    key2 =PINC.3 & 0x01;  
    292.       if(key2 ==0x01)
    293.       {
    294.        b=1;
    295.      }
    296.  }
    297.  if (b==1)
    298.  goto br;
    299.  else
    300. goto y;
    301.  
    302. }
    303.  
    304. //////////////////////////////////
    305. int set_key(void)
    306. {    
    307.  key2 =PINC.1 & 0x01;
    308.  if(key2 ==0x01)
    309.  {
    310.    delay_ms(50);
    311.    key2 =PINC.1 & 0x01;  
    312.       if(key2 ==0x01)
    313.       {
    314.        i++;
    315.       }
    316.  }
    317.  key2 =PINC.2 & 0x01;
    318.  if(key2 ==0x01)
    319.  {
    320.    delay_ms(50);
    321.    key2 =PINC.2 & 0x01;  
    322.    if(key2 ==0x01)
    323.      {
    324.      i--;
    325.      }
    326.   }
    327.   if(i<0)
    328.   {
    329.   i=0;
    330.   }
    331.   return i;
    332.  }
    333. ////////////////////////////////////////////
    334.  int set_angle(void)
    335.  {
    336.  key2 =PINC.1 & 0x01;
    337.  if(key2 ==0x01)
    338.  {
    339.    delay_ms(50);
    340.    key2 =PINC.1 & 0x01;  
    341.       if(key2 ==0x01)
    342.       {
    343.        f++;
    344.       }
    345.  }
    346.  key2 =PINC.2 & 0x01;
    347.  if(key2 ==0x01)
    348.  {
    349.    delay_ms(50);
    350.    key2 =PINC.2 & 0x01;  
    351.    if(key2 ==0x01)
    352.      {
    353.      f--;
    354.      }
    355.   }
    356.   if(i<0)
    357.   {
    358.   i=0;
    359.   }
    360.   return f;
    361.  }
    362.  
    363. ////////////////////////////////////////////      
    364. int detect_pulse(void){  
    365. v=0;
    366. TCCR1B=0x00;
    367. #asm("cli");
    368. goto s;
    369. s:
    370. key2 =PINC.4 & 0x00;
    371.  if(key2 ==0x00){
    372.    goto f;
    373.    f:
    374.    key2 =PINC.4 & 0x01;  
    375.       if(key2==0x01){
    376.        v=1;
    377.        }
    378.        else
    379.        {
    380.        goto f;
    381.        }
    382.   }
    383.   if(v==1){
    384.   atash(mode);
    385.   }
    386.   else
    387.   {
    388.   goto s;
    389.   }
    390.  return v;
    391. }
    392. ////////////////////////////////////////////
    393. void atash(int a){  
    394. #asm("sei")
    395. if(a==1){
    396. TCNT1=time1;
    397. TCCR1B=0x01;
    398. h=0;  
    399. g=1;  
    400. while(1){
    401. }
    402. }
    403. if(a==2){
    404. TCNT1=time2;
    405. TCCR1B=0x01;
    406. h=0;
    407. #asm("sei")
    408. g=1;
    409. while(1){
    410.  
    411. }
    412. }
    413. if(a==3){
    414. TCNT1=time3;
    415. TCCR1B=0x01;
    416. h=0;
    417. #asm("sei")
    418. g=1;
    419. while(1){
    420. }
    421. }  
    422. if(a==4){
    423. TCNT1=time4;
    424. TCCR1B=0x01;
    425. h=0;
    426. #asm("sei")
    427. g=1;
    428. while(1){
    429. }
    430. }
    431. }
     
  4. Far

    Thread Starter Member

    May 11, 2009
    20
    0
    This is a simple firing circuit for thyristors industrial electronic circuits. it makes some pulses with adjustable firing angle. the selected mods are about different types of circuits and thyristors number.
     
  5. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    Decoupling capacitors?
     
  6. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    It is a software problem.
    Do you understand goto statements? Why do you need to use them?
    I'd restructure your program so that it is easier to debug and doesn't jump all around.
    Also double check that you are using the '&' operator correctly.

    For example
    PINC.2 & 0x01 = ??
     
  7. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Check the watchdog fuse.
     
  8. Vaughanabe13

    Active Member

    May 4, 2009
    102
    5
    That code is very poorly structured when it comes to proper coding practices like indenting, comment blocks, etc. Maybe the formatting got all messed up when you copied the code but I can barely read it the way it is.
     
  9. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    The OP states he/she is using Proteus so for now the problem is software related. It is not doing what the OP intended... a quick glance found some potential logical errors. But as the code lacks readable formatting I do not have the time to plod through it in detail.
     
  10. Far

    Thread Starter Member

    May 11, 2009
    20
    0
    Thanks all for your help. I would try to write a new code use a better structure.
     
  11. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Here's the code re-indented.
    Our OP used the dreaded GOTO statement freely. :eek:
    Code ( (Unknown Language)):
    1. /*****************************************************
    2. Project :
    3. Version :
    4. Date    : 5/18/2009
    5. Author  : l                              
    6. Company : l                              
    7. Comments:
    8.  
    9.  
    10. Chip type           : ATmega8
    11. Program type        : Application
    12. Clock frequency     : 1.000000 MHz
    13. Memory model        : Small
    14. External SRAM size  : 0
    15. Data Stack size     : 256
    16. *****************************************************/
    17.  
    18. #include <mega8.h>
    19. #include <delay.h>
    20. #include <stdio.h>
    21. // Alphanumeric LCD Module functions
    22. #asm
    23. .equ __lcd_port=0x18 ;PORTB
    24. #endasm
    25. #include <lcd.h>
    26. char bufer[10];
    27. int key2,i,key,b,mode,count,g=0,h,f,ab,n,a,j,p,v,l,k;  
    28. unsigned int time1,time180,time2,time60,time120,time3,time4,time,d;
    29. void atash(int a);        
    30. int detect_pulse(void);
    31. interrupt [TIM1_OVF] void timer1_ovf_isr(void)
    32. {
    33.     // Place your code here  
    34.     if(mode==1){
    35.         if(h==0){
    36.             PORTD=0x01;
    37.             TCNT1=time180;
    38.             TCCR1B=0x01;
    39.             h=1;
    40.             g=1;
    41.         }  
    42.         g++;
    43.         if(g>2){
    44.             if(g==3){
    45.                 PORTD=0x02;
    46.                 d++;
    47.             }
    48.             /*if(d==6){
    49. d=0;
    50. TCCR1B=0x00;
    51. TCNT1=0x00;
    52. #asm("cli");
    53. mode=1;
    54. p=detect_pulse();
    55. }*/
    56.             if(g==4){
    57.                 PORTD=0x01;
    58.                 g=2;
    59.             }
    60.             TCNT1=time180;
    61.             TCCR1B=0x01;
    62.         }  
    63.     }
    64.     if(mode==2){
    65.         if(h==0){
    66.             PORTD=0x03;
    67.             TCNT1=time180;
    68.             TCCR1B=0x01;
    69.             h=1;
    70.             g=1;
    71.         }  
    72.         g++;
    73.         if(g>2){
    74.             if(g==3)
    75.             PORTD=0x0c;
    76.             if(g==4){
    77.                 PORTD=0x03;
    78.                 g=2;
    79.             }
    80.             TCNT1=time180;
    81.             TCCR1B=0x01;
    82.         }  
    83.     }
    84.     if(mode==3){
    85.         if(h==0){
    86.             PORTD=0x01;
    87.             TCNT1=time120;
    88.             TCCR1B=0x01;
    89.             h=1;
    90.             g=0;
    91.         }  
    92.         g++;
    93.         if(g>2){
    94.             if(g==3)
    95.             PORTD=0x02;
    96.             if(g==4)
    97.             PORTD=0x04;
    98.             if(g==5){
    99.                 PORTD=0x01;
    100.  
    101.                 g=2;
    102.             }
    103.             TCNT1=time120;
    104.             TCCR1B=0x01;
    105.         }  
    106.     }
    107.     if(mode==4){
    108.         g++;
    109.         if(h==0){
    110.             PORTD=0x01;
    111.             TCNT1=time60;
    112.             TCCR1B=0x01;
    113.             h=1;
    114.             g=2;
    115.         }  
    116.         if(g>2){
    117.             TCNT1=time60;
    118.             if(g==3)
    119.             PORTD=0x02;
    120.             if(g==4)
    121.             PORTD=0x04;
    122.             if(g==5)
    123.             PORTD=0x08;
    124.             if(g==6)
    125.             PORTD=0x10;
    126.             if(g==7)
    127.             PORTD=0x20;
    128.             if(g==8){
    129.                 PORTD=0x01;
    130.                 g=2;
    131.             }
    132.         }  
    133.     }
    134. }
    135.  
    136. // Declare your global variables here
    137. int set_key(void);
    138. int set_angle(void);
    139.  
    140. void main(void)
    141. {
    142.     // Declare your local variables here
    143.     char bufer1[10];
    144.     float t,t120,t60,div;
    145.     unsigned int angle;
    146.     PORTB=0x00;
    147.     DDRB=0x00;
    148.     PORTC=0x00;
    149.     DDRC=0x00;
    150.     PORTD=0x00;
    151.     DDRD=0x3F;
    152.     TCCR0=0x00;
    153.     TCNT0=0x00;
    154.     TCCR1B=0x00;
    155.     TCCR1A=0x00;
    156.     TCNT1H=0x00;
    157.     TCNT1L=0x00;
    158.     ICR1H=0x00;
    159.     ICR1L=0x00;
    160.     OCR1AH=0x00;
    161.     OCR1AL=0x00;
    162.     OCR1BH=0x00;
    163.     OCR1BL=0x00;
    164.     TCCR2=0x00;
    165.     TCNT2=0x00;
    166.     OCR2=0x00;
    167.     GICR|=0x00;
    168.     MCUCR=0x00;
    169.     GIFR=0x00;
    170.     TIMSK=0x04;
    171.     // LCD module initialization
    172. #asm("cli")
    173.     lcd_init(16);
    174.     lcd_clear();    
    175.     lcd_putsf("ENTER THE MODE");
    176.     goto loop1;
    177. loop1:
    178.     while(1){
    179.         key=set_key();
    180.         if(key>4){
    181.             key=0;
    182.             i=0;
    183.         }  
    184.         mode=key;
    185.         lcd_clear();
    186.         sprintf(bufer,"NUMBER OF MODE:%i",key);
    187.         lcd_puts(bufer);
    188.         delay_ms(500);
    189.         key2 =PINC.3 & 0x01;
    190.         if(key2 ==0x01){
    191.             delay_ms(50);
    192.             key2 =PINC.3 & 0x01;  
    193.             if(key2 ==0x01)
    194.             b=1;
    195.         }
    196.         if(key>0 & b==1){
    197.             lcd_clear();
    198.             lcd_putsf("MODE IS ACCEPT");
    199.             delay_ms(500);
    200.             lcd_clear();
    201.             lcd_gotoxy(0,0);
    202.             sprintf(bufer1,"MODE=%i",mode);
    203.             lcd_puts(bufer1);
    204.             delay_ms(1000);
    205.             goto angel;
    206.         }
    207.     }
    208. br:
    209.     switch(key)
    210.     {
    211.     case 1:
    212.         goto mode1;
    213.     case 2:
    214.         goto mode2;
    215.     case 3:
    216.         goto mode3;
    217.     case 4:
    218.         goto mode4;
    219.     case 0:
    220.         goto loop1;
    221.     }
    222.     //////////////////////////////
    223. mode1:
    224.     mode=1;
    225.     lcd_clear();
    226.     lcd_putsf("mode=1");
    227.     div=180/angle;
    228.     t=0.01/div;
    229.     t=t/0.000001;
    230.     time1=65535-t;
    231.     time180=65535-10000;
    232.     p=detect_pulse();
    233.     //////////////////////////////
    234. mode2:
    235.     mode=2;
    236.     lcd_clear();
    237.     lcd_putsf("mode=2");
    238.     div=angle/180;
    239.     t=0.01/div;
    240.     t=t/0.000001;
    241.     time2=65535-t;
    242.     time180=65535-10000;
    243.     p=detect_pulse();
    244.     //////////////////////////////
    245. mode3:
    246.     mode=3;
    247.     div=180/angle;
    248.     t=0.01/div;
    249.     t=t/0.000001;
    250.     time3=65535-t;
    251.     t120=2*0.01/3;
    252.     t120=65535-t120;
    253.     t120=t120/0.000001;
    254.     time120=65535-t120;
    255.     TCCR1B=0x00;
    256.     p=detect_pulse();
    257.     //////////////////////////////
    258. mode4:
    259.     mode=4;
    260.     t60=0.01/3;
    261.     t60=t60/0.000001;
    262.     t60=65535-t60;
    263.     time60=t60;
    264.     div=180/angle;
    265.     t=0.01/div;
    266.     t=t/0.000001;
    267.     time4=65535-t;
    268.     p=detect_pulse();
    269.  
    270.     //////////////////////////////  
    271. angel:
    272.     f=0;
    273.     angle=0;
    274.     goto y;
    275. y:
    276.     ab=set_angle();
    277.     angle=ab*12;
    278.     if (angle>170 | angle<0)
    279.     {
    280.         angle=168;
    281.         f=14;
    282.     }  
    283.     sprintf(bufer,"ANGLE:%i DEG",angle);
    284.     lcd_gotoxy(0,1);
    285.     lcd_puts(bufer);
    286.     delay_ms(500);
    287.     b=0;
    288.     key2 =PINC.3 & 0x01;
    289.     if(key2 ==0x01)
    290.     {
    291.         delay_ms(50);
    292.         key2 =PINC.3 & 0x01;  
    293.         if(key2 ==0x01)
    294.         {
    295.             b=1;
    296.         }
    297.     }
    298.     if (b==1)
    299.     goto br;
    300.     else
    301.     goto y;
    302.  
    303. }
    304.  
    305. //////////////////////////////////
    306. int set_key(void)
    307. {    
    308.     key2 =PINC.1 & 0x01;
    309.     if(key2 ==0x01)
    310.     {
    311.         delay_ms(50);
    312.         key2 =PINC.1 & 0x01;  
    313.         if(key2 ==0x01)
    314.         {
    315.             i++;
    316.         }
    317.     }
    318.     key2 =PINC.2 & 0x01;
    319.     if(key2 ==0x01)
    320.     {
    321.         delay_ms(50);
    322.         key2 =PINC.2 & 0x01;  
    323.         if(key2 ==0x01)
    324.         {
    325.             i--;
    326.         }
    327.     }
    328.     if(i<0)
    329.     {
    330.         i=0;
    331.     }
    332.     return i;
    333. }
    334. ////////////////////////////////////////////
    335. int set_angle(void)
    336. {
    337.     key2 =PINC.1 & 0x01;
    338.     if(key2 ==0x01)
    339.     {
    340.         delay_ms(50);
    341.         key2 =PINC.1 & 0x01;  
    342.         if(key2 ==0x01)
    343.         {
    344.             f++;
    345.         }
    346.     }
    347.     key2 =PINC.2 & 0x01;
    348.     if(key2 ==0x01)
    349.     {
    350.         delay_ms(50);
    351.         key2 =PINC.2 & 0x01;  
    352.         if(key2 ==0x01)
    353.         {
    354.             f--;
    355.         }
    356.     }
    357.     if(i<0)
    358.     {
    359.         i=0;
    360.     }
    361.     return f;
    362. }
    363.  
    364. ////////////////////////////////////////////      
    365. int detect_pulse(void){  
    366.     v=0;
    367.     TCCR1B=0x00;
    368. #asm("cli");
    369.     goto s;
    370. s:
    371.     key2 =PINC.4 & 0x00;
    372.     if(key2 ==0x00){
    373.         goto f;
    374. f:
    375.         key2 =PINC.4 & 0x01;  
    376.         if(key2==0x01){
    377.             v=1;
    378.         }
    379.         else
    380.         {
    381.             goto f;
    382.         }
    383.     }
    384.     if(v==1){
    385.         atash(mode);
    386.     }
    387.     else
    388.     {
    389.         goto s;
    390.     }
    391.     return v;
    392. }
    393. ////////////////////////////////////////////
    394. void atash(int a){  
    395. #asm("sei")
    396.     if(a==1){
    397.         TCNT1=time1;
    398.         TCCR1B=0x01;
    399.         h=0;  
    400.         g=1;  
    401.         while(1){
    402.         }
    403.     }
    404.     if(a==2){
    405.         TCNT1=time2;
    406.         TCCR1B=0x01;
    407.         h=0;
    408. #asm("sei")
    409.         g=1;
    410.         while(1){
    411.  
    412.         }
    413.     }
    414.     if(a==3){
    415.         TCNT1=time3;
    416.         TCCR1B=0x01;
    417.         h=0;
    418. #asm("sei")
    419.         g=1;
    420.         while(1){
    421.         }
    422.     }  
    423.     if(a==4){
    424.         TCNT1=time4;
    425.         TCCR1B=0x01;
    426.         h=0;
    427. #asm("sei")
    428.         g=1;
    429.         while(1){
    430.         }
    431.     }
    432. }
     
Loading...