/**************************************************************************
Aim of project : Aim of the project is to develop source code for configuring the microcontroller. The configuration
code should make the microcontroller to read the analog inputs and convetr it to digital counts. Based on these
count values the pressure is calculated. Finally the calculated pressure value should be transmitted to an
external device(in this case a PC) and the sent data should follow a protocol.
Version No & Revision no of the project : 1.0
Project Author/s : Avinash James, Gowravi S B, Sivashakthi S
Date Written : 20-Jan -2010
Other files required to build the entire software with path (and with a brief description of each file) or Give ref. to a separate file containing
these build files e.g.,Compile.doc : main.h contains all the function and variable declerations. Also include all the configuration
control register values.
Compiling and linking information (Also refer to linker file path) Or Give ref. to a separate file containing these build files e.g.,Compile.doc :
Pragma Directives used in the Project, along with :
description
Floating Point Standard Used for the Project : NA
Character Set used for the Project : Universal character set
Implementation of Integer Division as done : -5/3 = -1 reminder -2 OR -5/3 = -2 reminder +1 by the compiler
/**************************************************************************
HEADER FILES
**************************************************************************/
#include "main.h"
/**************************************************************************
MAIN
**************************************************************************/
void main(void)
{
Processor_Init();
TRISE=0;
PORTE=0x00;//CHECK_Key();
while(LOOP)
{
PORTE=0xFF;//CHECK_Key();
usnDelay=0;
while(usnDelay<500)
usnDelay++;
CalculatePRESSURE();
PORTE=0x00;//CHECK_Key();
usnDelay=0;
while(usnDelay<500)
usnDelay++;
}
}
/**************************************************************************
PROCESSOR INITIALIZATION
Module name : PROCESSOR INITIALIZATION
Module ID : Processor_1
Purpose of the module : To initialize the processor to work on the internal oscillator at a frequency of 8MHz
This is done by configuring the OSCCON register
Author/s :Avinash James
Date written : 20 Jan 2010
Global Variables Referred : Nil
Global Variables Modified : Nil
Functions called : Nil
**************************************************************************/
void Processor_Init(void)
{
OSCCON=0x76; // bit 7 0 = Device enters Sleep mode on SLEEP instruction
// bit 6-4 111 = 8 MHz (INTOSC drives clock directly)
// bit 3 0 = Oscillator Start-up Timer time-out is running; primary oscillator is not ready
// bit 2 1 = INTOSC frequency is stable
// bit 1-0 1x = Internal oscillator
}
/**************************************************************************
ADC
**************************************************************************/
/**************************************************************************
ADC Configuration
Module name : ADC Configuration
Module ID : ADC_Config_2
Purpose of the module :To configure the ADC to read from a specific channel on the controller and setting all the voltage references
I/O ports,justification of the result and also selection of the clock
Author/s :Avinash James
Date written : 18 Jan 2010
Global Variables Referred : Nil
Global Variables Modified : Nil
Functions called : Nil
**************************************************************************/
void Config_ADC(void)
{
ADCON0 = 0x05; //Select A/D input channel
//Turn on A/D module
ADCON1 = 0x0D; //Configure voltage references
//Configue A/D ports
ADCON2 = 0xBF; //Select A/D Acquisition Time
//Selct A/D Conversion Clock
//A/D Result Format(right or left justified)
}
/**************************************************************************
ADC Convert
Module name : ADC Convert
Module ID : ADC_Convert_3
Purpose of the module :To start the A/D conversion and wait till the conversion is over
Author/s :Avinash James
Date written : 18 Jan 2010
Global Variables Referred : Nil
Global Variables Modified : Nil
Functions called : Nil
**************************************************************************/
void Convert_ADC(void)
{
ADCON0bits.GO=1; //Start A/D Conversion
while(ADCON0bits.GO == 1); //Check wherther conversion is over
}
/**************************************************************************
ADC Read
Module name : ADC Read
Module ID : ADC_Read_4
Purpose of the module :To read the ADC count value and store it into another register
Author/s :Avinash James
Date written : 18 Jan 2010
Global Variables Referred : Nil
Global Variables Modified : nADC_Data
Functions called : Nil
**************************************************************************/
void Read_ADC(void)
{
nADC_Data=ADRES; //Read the ADC count into a temp register
}
/**************************************************************************
ADC Close
Module name : ADC Close
Module ID : ADC_Close_5
Purpose of the module :To disable the A/D copnvetre after use
Author/s :Avinash James
Date written : 18 Jan 2010
Global Variables Referred : Nil
Global Variables Modified : Nil
Functions called : Nil
**************************************************************************/
void Close_ADC(void)
{
ADCON0bits.ADON=0; //Disable the ADC
}
/**************************************************************************
ADC Call
Module name : ADC Call
Module ID : ADC_Call_6
Purpose of the module :To call all the ADC functions from a single point
Author/s :Avinash James
Date written : 18 Jan 2010
Global Variables Referred : Nil
Global Variables Modified : Nil
Functions called : Config_ADC()
Convert_ADC()
Read_ADC()
Close_ADC()
**************************************************************************/
void ADC_Call(void)
{
Config_ADC();
Convert_ADC();
Read_ADC();
Close_ADC();
}
/**************************************************************************
EEPROM
**************************************************************************/
/**************************************************************************
EEPROM Write
Module name : EEPROM Write
Module ID : EEPROM_Write_7
Purpose of the module :To enable the EEROM and to wite data to the EEPROM at a particular location specified by the passing parameters
Author/s :Avinash James
Date written : 18 Jan 2010
Global Variables Referred : Nil
Global Variables Modified : Nil
Functions called : Nil
**************************************************************************/
void EEPROM_Write(unsigned char address, unsigned int *_data)
{
EEDATA = *_data; //data to be written