#include <main.h>


unsigned int a=10;					//define variables.
unsigned int flag=0;
unsigned int pot1=0;
unsigned int but1=0;
									//define variables end

#INT_TIMER2
void  TIMER2_isr(void) 
{
    a--;												// increment a in the interrupt routine half second
	if(!a)	flag+=0x01;
/*	b--;
	if(!b)  flag+=0x00;									// enable flag bit 0x01 and 0x08  1 sec
	f--;
	if(!f)  flag+=0x00;									// increment a in the interrupt routine 750mS
*/

}


void func1();			// prototypes for our functions

									// prototypes for our functions end
#define LCD_ENABLE_PIN PIN_B2
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7

#include <lcd.c>



void main()
{
	setup_adc_ports(AN0_TO_AN1);					// select a0 & a1 as analogue
	setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
	setup_timer_2(T2_DIV_BY_16,178,14);				//716 us overflow, 10.0 ms interrupt


	enable_interrupts(INT_TIMER2);					// enable timer 2 overflow interrupt
	enable_interrupts(GLOBAL);						// enable global interrupts
	
   lcd_init();										// initiate LCD

	while(TRUE)										// Main program while loop
	{

		if(flag & 0x01) func1();					// if flag 0x01 set - call our function 1

		if((pot1>128) && (input(pin_A2)))
				{ output_high(Pin_A6); output_low(Pin_A7);}
		else
				{ output_low(Pin_A6); output_high(Pin_A7);}


	}												// main program while loop end
	

}													// END PROGRAM


void func1()
			{															// read analogue inputs
				set_adc_channel(0);
				delay_us(20);
				pot1 = read_adc();

				a=10;
				flag-=4;
			}

