#include <16F877.h>
#fuses HS,NOLVP,NOPROTECT,NOWDT
#use delay(CLOCK = 20000000)
#define use_portb_lcd
#use fast_io(A)
#define Vbe 0.0012210012210012210012210012210012 // Vref/4095(5/4095)
#define cs PIN_A0 // bit output. //
#define clkm PIN_A1 // bit output. //
#define Dout PIN_A2 // bit input. //
unsigned int16 Read_mcp3201()
{
unsigned int16 digi;
unsigned char z;
output_high(cs);
digi = 0;
output_low(clkm);
output_low(cs);
//clock 1.//
output_low(clkm);
output_high(clkm);
//clock 2.//
output_low(clkm);
output_high(clkm);
//clock 3.//
output_low(clkm);
output_high(clkm);
//clock 4-15.//
for(z=0;z<12;z++)
{
output_low(clkm);
output_high(clkm);
digi = digi << 1;
digi = digi | input(Dout);
}
output_high(cs);
return(digi);
}
void main(void)
{
unsigned int16 a; // digi 12 bit. //
float vol; // volte type float. //
set_tris_a(0xFC); // set port output PINA0,PINA1 ||
while(TRUE)
{
set_tris_a(0xFC);
delay_ms(10);
a = Read_mcp3201();
vol = (a*Vbe);
}
}