You are on page 1of 1

Main

The 10 bit result from ADC is converted to 8bit and given to Timer register. When Timer
0overflows interrupt is called.
#if defined(__XC)
#include <xc.h>
/* XC8 General Include File */
#elif defined(HI_TECH_C)
#include <htc.h>
/* HiTech General Include File */
#endif
#include <stdint.h>
/* For uint8_t definition */
#include <stdbool.h>
/* For true/false definition */
#include "system.h"
/* System funct/params, like osc/peripheral
config */
#include "user.h"
/* User funct/params, such as InitApp */
uint16_t gSpeed;
uint16_t read_speed();
bool toggle=0x00;
void main(void)
{
InitApp();
toggle=0x00;
while(1)
{
gSpeed=read_speed();
gSpeed=gSpeed>>2;
TMR0=gSpeed;
toggle=(0x01^toggle);
RB5=toggle;
}
}
uint16_t read_speed()
{
uint16_t adc_res=0;
ADCON0=0xD9;
GO=0x01;
while(GO);
adc_res=ADRESL; //Take 8bit LSB of ADC Result
adc_res+ =(ADRESH <<8); //Take remaining 2bit MSB of ADC
return adc_res;
}

You might also like