Timer 0 not start

Discussion in 'Embedded Systems and Microcontrollers' started by FroceMaster, Mar 31, 2015.

  1. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    Hi.
    HAve this code.
    Code (Text):
    1. #include <htc.h>
    2. #include <stdio.h>
    3. #include <stdlib.h>
    4. #include "lcd.h"
    5. #include <string.h>
    6. __CONFIG (CLKOUTEN_OFF & FCMEN_ON & IESO_OFF & BOREN_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTOSC);//XT
    7. __CONFIG (LVP_ON & LPBOR_OFF & BOREN_ON & STVREN_ON & WRT_OFF);
    8. #define _XTAL_FREQ 16000000
    9.  
    10. signed int lightintensity;
    11. unsigned int runs;
    12. bit on_housenumber;
    13.  
    14.   union
    15. {
    16. unsigned int res;
    17. char bytes[2];
    18. }
    19. ADC;
    20. unsigned char ADC_num[6];
    21.  
    22.  
    23. static void interrupt isr(void)   // Here is interrupt function - the name is unimportant.
    24. {
    25.    if(TMR0IF)
    26.    {
    27.         //TMR2=0;
    28.         TMR0IF=0;
    29.         RC7=1;
    30.       }
    31.  
    32.    
    33. }// end interrupt
    34.  
    35. void setup(void)
    36. {  
    37.     SCS1=1;
    38.     SCS0=1;
    39. IRCF3=1;//16MHz clock speed
    40. IRCF2=1;
    41. IRCF1=1;
    42. IRCF0=1;
    43.  
    44.  
    45.  
    46. // timer 0
    47. TMR0CS=0; //fosc/4
    48. PSA=0;// use prescale
    49. PS0=1;
    50. PS1=1; // prescale 1:64
    51. PS2=1;
    52.  
    53.  
    54.  
    55. //Port analog / digital
    56. TRISA=0; //all port ud.
    57. TRISA1=1; //set a1 in
    58. TRISB=0; // out
    59. TRISC=0; //  out.
    60.  
    61. ANSELA=0; // set all digital.
    62. ANSA1=1; //analog
    63. ANSELB=0;
    64. ANSELC=0;//turn off all analog functions
    65. ADFM=1;    //right justified
    66. ADPREF0=1;
    67. ADPREF1=0;
    68.  
    69. TRIGSEL0=1; // use timer0 interrupt to measure analog
    70. TRIGSEL1=1;
    71. TRIGSEL2=0;
    72. TRIGSEL3=0;
    73. CHS0=1;  //an1
    74. CHS1=0;
    75. CHS2=0;
    76. CHS3=0;
    77. CHS4=0; // AN1  analog
    78.  
    79.  
    80. } //end setup
    81.  
    82.  
    83. void housenumber_on (void)
    84. {
    85. RC0=1;
    86. __delay_ms(1);
    87. RC0=0;
    88. RC1=1;
    89. __delay_ms(1);
    90. RC1=0;
    91. RC2=1;
    92. __delay_ms(1);
    93. RC2=0;
    94. RC3=1;
    95. __delay_ms(1);
    96. RC3=0;
    97. RC4=1;
    98. __delay_ms(1);
    99. RC4=0;
    100. RC5=1;
    101. __delay_ms(1);
    102. RC5=0;
    103. RC6=1;
    104. __delay_ms(1);
    105. RC6=0;
    106.  
    107.   }
    108.  
    109.      
    110. void main (void)
    111. {
    112.  
    113. setup();         //runs setup
    114.        ADON=1;
    115.        GIE = 0;  // Global interrupt
    116.  
    117.          on_housenumber=0;
    118.      runs=0;
    119.            while (1)// runs loop
    120.        
    121.        { runs++;
    122.            if (runs==500)
    123.            { runs=0;
    124.            
    125.                 ADC.bytes[0]=ADRESL;
    126.                  ADC.bytes[1]=ADRESH;
    127.                  lightintensity = ADC.res;
    128.                      if (lightintensity>700)
    129.                  {  on_housenumber= 1;
    130.                     }
    131.                 else
    132.                 {on_housenumber=0;
    133.                 }
    134.                  
    135.              
    136.              
    137.            }
    138.            if (on_housenumber==0)
    139.            {
    140.                housenumber_on();
    141.                                 }
    142.            
    143.          }//end while endless loop
    144. }//End main
    But the timer0 is not running, why ?
    Pic 16F1509 btw.
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,137
    1,786
    How do you know that Timer0 is not running?
     
  3. FroceMaster

    Thread Starter Member

    Jan 28, 2012
    400
    4
    just the function was not ok, and in the simulator it was not .
    HAve now testet in real life, and it Works,

    no problemo :)
     
Loading...