

#include "define.h"     // file for definition of constants
#include "ADC_HEADER.h"
#include "eeprom.h"
extern bit timeout;

void Input_Configuration(void)    // 
{
unsigned char n;
// set IO pins:  in-out-bidirectional B=00, I=10, O=01, OD=11
    
    P0M1=0x09; // 0.7-0.0  B B B B  I B B OD                   
    P0M2=0x01;
    P1M1=0x80; // 1.7-1.0  O B B B  O B B B
    P1M2=0x88;
    P2M1=0x00; // 2.7-2.0  B B B B  B B B B
    P2M2=0x00;
    P3M1=0x00; // 3.1-3.0  B B B B  B B B B
    P3M2=0x00;

timeout=0;
TMOD=0x01;                  // set timer mode as watchdog for coomunication! T0 16 bits
for (n=0; n<0x8; n++);;     // wait 16 usec before communication with camera starts
}

/***********************************************************************
DESC:    Initializes the ADC
RETURNS: Nothing
CAUTION: Set EA to 1 after calling to enable all interrupts
************************************************************************/
void adc_init(void)
{
  
  ADMODB |= 0x40;   // configure clock divider  
  //P1M1 |= 0x80;   // set adc0 channel pins to input only (disables digital output)
  //P1M2 &= ~0x80;  // channel 0
  
  //P0M1 |= 0x01;   // channel 1
  //P0M2 &= ~0x01;
  
  ADMODB &= ~0x04;  // disable dac0
  
  ADCON0 |= 0x44;   // configure adc0 and enable (also enables dac0)
  
  IP1 &= 0x7F;      // set isr priority to 0
  IP1H &= 0x7F;
    
  EAD = 1;          // enable adc interrupt
}

void Main (void)    // main program
{
   
eeprom_init(); // initialize internal eeprom data transfer
eeprom_write(0x000, 0x00); // 
eeprom_write(0x001, 0x03); // 
eeprom_write(0x002, 0x00); // 

   
while(1) // Loop this section forever
   {   
    Input_Configuration();
    if(!imageup)image_up();             // HC Rocker switch HC mode UP    
    if(!imagedown)image_down();         // HC Rocker switch HC mode DOWN 
    if(!zoom_preset)zoom_set_reset();   // Check to see if zoom recall is active
    if(!freeze)freeze_mode();           // Freeze image on display
    
    
       
      
    adc_init();
    adc_start_ADC0_conversion(ADC_IMMEDIATE, ADC_AUTOSCANCONT, ADC0_CHANNEL0); //Read CH 0
    adc_stop_ADC0_conversion(); // Stop conversion of A/D  ONE SHOT READ PER CYCLE LOOP
    adc_convert_data('0');      // Read result from conversion register
     
    

   }

}


