Timer 0 not start

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Hi.
HAve this code.
Code:
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
#include <string.h>
__CONFIG (CLKOUTEN_OFF & FCMEN_ON & IESO_OFF & BOREN_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTOSC);//XT
__CONFIG (LVP_ON & LPBOR_OFF & BOREN_ON & STVREN_ON & WRT_OFF);
#define _XTAL_FREQ 16000000

signed int lightintensity;
unsigned int runs;
bit on_housenumber;

  union
{
unsigned int res;
char bytes[2];
}
ADC;
unsigned char ADC_num[6];


static void interrupt isr(void)   // Here is interrupt function - the name is unimportant.
{
   if(TMR0IF)
   {
        //TMR2=0;
        TMR0IF=0;
        RC7=1;
      } 
 
    
}// end interrupt
  
void setup(void)
{   
    SCS1=1;
    SCS0=1;
IRCF3=1;//16MHz clock speed
IRCF2=1;
IRCF1=1;
IRCF0=1;



// timer 0
TMR0CS=0; //fosc/4
PSA=0;// use prescale
PS0=1;
PS1=1; // prescale 1:64
PS2=1;



//Port analog / digital
TRISA=0; //all port ud.
TRISA1=1; //set a1 in
TRISB=0; // out
TRISC=0; //  out.

ANSELA=0; // set all digital.
ANSA1=1; //analog
ANSELB=0;
ANSELC=0;//turn off all analog functions
ADFM=1;    //right justified
ADPREF0=1;
ADPREF1=0;

TRIGSEL0=1; // use timer0 interrupt to measure analog
TRIGSEL1=1;
TRIGSEL2=0;
TRIGSEL3=0;
CHS0=1;  //an1
CHS1=0;
CHS2=0;
CHS3=0;
CHS4=0; // AN1  analog


} //end setup


void housenumber_on (void)
{
RC0=1;
__delay_ms(1);
RC0=0;
RC1=1;
__delay_ms(1);
RC1=0;
RC2=1;
__delay_ms(1);
RC2=0;
RC3=1;
__delay_ms(1);
RC3=0;
RC4=1;
__delay_ms(1);
RC4=0;
RC5=1;
__delay_ms(1);
RC5=0;
RC6=1;
__delay_ms(1);
RC6=0;

  }

      
void main (void)
{
  
setup();         //runs setup
       ADON=1;
       GIE = 0;  // Global interrupt

         on_housenumber=0;
     runs=0;
           while (1)// runs loop
        
       { runs++;
           if (runs==500)
           { runs=0;
            
                ADC.bytes[0]=ADRESL;
                 ADC.bytes[1]=ADRESH;
                 lightintensity = ADC.res;
                     if (lightintensity>700)
                 {  on_housenumber= 1;
                    }
                else
                {on_housenumber=0;
                }
                  
             
             
           }
           if (on_housenumber==0)
           {
               housenumber_on();
                                }
            
         }//end while endless loop
}//End main
But the timer0 is not running, why ?
Pic 16F1509 btw.
 
Top