#include <16F877A.h>
#device *= 16
#FUSES NOWDT //No Watch Dog Timer
#FUSES CPD //No EEPROM Code Protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //RB3 as digital IO
#FUSES NODEBUG
#FUSES HS
#use delay( crystal = 16MHz )
#use rs232(baud=9600, xmit=pin_c6, rcv=pin_c7)
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte TRISC = 0x87
#byte TRISD = 0x88
#byte TRISE = 0x89
#BYTE PORTA = 0x05
#BYTE PORTB = 0x06
#BYTE PORTC = 0x07
#BYTE PORTD = 0x08
#BYTE PORTE = 0x09
#bit RA0 = 0X05.0
#BIT RA1 = 0X05.1
#BIT RA2 = 0X05.2
#BIT RA3 = 0X05.3
#BIT RA4 = 0X05.4
#BIT RA5 = 0X05.5
#BIT RB0 = 0X06.0
#BIT RB1 = 0X06.1
#BIT RB2 = 0X06.2
#BIT RB3 = 0X06.3
#BIT RB4 = 0X06.4
#BIT RB5 = 0X06.5
#BIT RB6 = 0X06.6
#BIT RB7 = 0X06.7
#BIT RC0 = 0X07.0
#BIT RC1 = 0X07.1
#BIT RC2 = 0X07.2
#BIT RC3 = 0X07.3
#BIT RC4 = 0X07.4
#BIT RC5 = 0X07.5
#BIT RC6 = 0X07.6
#BIT RC7 = 0X07.7
#BIT RD0 = 0X08.0
#BIT RD1 = 0X08.1
#BIT RD2 = 0X08.2
#BIT RD3 = 0X08.3
#BIT RD4 = 0X08.4
#BIT RD5 = 0X08.5
#BIT RD6 = 0X08.6
#BIT RD7 = 0X08.7
#BIT RE0 = 0X09.0
#BIT RE1 = 0X09.1
#BIT RE2 = 0X09.2
#byte TXSTA = 0x98
#byte RCSTA = 0x18
#byte TXREG = 0x19
#byte SPBRG = 0x99
#bit TRMT = 0x98.1
#define SPEED RB0
#define PWDN RB1
#define SCLK RB2
#define DRDYDOUT input(PIN_C4)
#define HIGH 1
#define LOW 0
#define CONVERSION_READY 1
#define NORMAL_SPEED 0
#define ENABLED 1
#define DISABLED 0
void IO_Initiallisation()
{
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x10;
TRISD = 0x00;
TRISE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
}
//*************** Output Pins Reset ********************************************//
void Pin_Reset()
{
SPEED = 0;
delay_ms(1);
PWDN = 0;
delay_ms(1);
SCLK = 0;
delay_ms(1);
return;
}
void delay()
{
unsigned int8 i =0;
for(i=0;i<5;i++);
}
void main()
{
unsigned int1 ADC_CONVERSION_READY = 0,
ADC_DATA_READY = 0;
unsigned int8 DATA_OUT = 0;
unsigned int32 ADC_DATA_VALUE = 80001000;
TXSTA = 0x24;
RCSTA = 0x90;
SPBRG = 103;
IO_Initiallisation(); // Function is used to set input output configurations
Pin_Reset(); // Making all the output pins as zero
PWDN = HIGH;
delay_ms(2);
SPEED = 0;
delay_ms(2);
SCLK = LOW;
TXREG = '*';
while(!TRMT);
printf( "\n fdsfds %Lu",ADC_DATA_VALUE );
while( True )
{
if( ( DRDYDOUT == 1 ) && ( ADC_CONVERSION_READY == DISABLED ) )
{
if( DRDYDOUT == 0 )
{
ADC_CONVERSION_READY = ENABLED;
}
}
if( ADC_CONVERSION_READY == ENABLED )
{
ADC_DATA_VALUE = 0;
for( DATA_OUT = 0; DATA_OUT < 24; DATA_OUT++ )
{
SCLK = HIGH;
delay_cycles(10);
if( DRDYDOUT == HIGH )
{
ADC_DATA_VALUE = ( ADC_DATA_VALUE | 1 );
}
ADC_DATA_VALUE = ADC_DATA_VALUE << 1 ;
SCLK = LOW;
delay_cycles(10);
}
ADC_CONVERSION_READY = DISABLED;
ADC_DATA_READY = ENABLED;
}
if( ADC_DATA_READY == ENABLED )
{
printf( "\n %Lu",ADC_DATA_VALUE );
ADC_DATA_READY = DISABLED;
}
}
}