htc.h tmr1if
#include<htc.h>
#define ADC_DIR TRISA
#define DISPLAY_DIR TRISB
#define INPUT PORTA
#define OUTPUT PORTB
#define S0_dir TRISC6
#define S1_dir TRISC7
#define S0 RC6
#define S1 RC7
#define IN 0xFF
#define OUT 0x00
#define in 0b1;
#define out 0b0;
unsigned char aaaa;
void delay40us(void)
{
TMR1H=255; //TH
TMR1L=55; //TR
T1CKPS1=0; //PRESCALE BIT
T1CKPS0=0; //PRESCALE BIT
TMR1ON=1; //TRO=1
while(!TMR1IF){} //TFO
TMR1ON=0;
TMR1IF=0;
}
void display(void)
{
aaaa=ADRESH;
S0=1;
S1=0;
OUTPUT = aaaa;
delay40us();
S0 = 0;
S1 = 1;
OUTPUT = ADRESL;
delay40us();
S0 =0;
S1=0;
CCPR1L=aaaa;
CCPR2L=255-aaaa;
}
void initialise(void)
{
GIE = 0;
ADC_DIR = IN;
DISPLAY_DIR = OUT;
S0_dir = out;
S1_dir = out;
ADRESL = 0x00;
ADRESH = 0x00;
display();
pwm();
}
void main(void)
{
initialise();
while(1){
//selecting a/d result format & configuring a/d port
ADCON1 = 0b00001110; // |ADFM = 1(6 msb of adresh=0| ADFCS2|0|0 |ad port conf bits 1111 RA0 analog RA3=vref+ RA2 =vref-|
//selecting A/d input channel
CHS2 =0;
CHS1 =0;
CHS0 =0;
//selecting A/d conversion clock TAD=1.6us required since fosc= 11.0592mhz TAD=32TOSC
ADGO =0;
ADCS2 = 0;
ADCS1 =1;
ADCS0 =0;
//turn on ad module
ADON=1;
while(1){
//wait for required acquistion time
delay40us();
ADGO =1;
while(ADGO){}
ADGO = 0;
delay40us();
delay40us();
display();
delay40us();
delay40us();
}
}
}
this is code written fot hitech c compiler