Munaf
If you want us to help you, you need to help yourself first,
You will mot find anybody that will write the code for you that's to easy
what you need to do is write some code and try to get it working if not them upload your code that you have wrote then we may be able to help you becuase what you want to do is asking a lot sorry to say
There is also quite a few ways you can do it using interuptts or then simple way here is some code to get you going
[size=2]
[b]Device [/size][size=2][color=#000080]16F877
[/b][/color][/size][size=2][b]Dim [/b]NUM [b]As Word
[/b]
[b]Input [/b]= [/size][size=2][color=#008000]PORTB[/color][/size][size=2].x
[b]Symbol [/b]LED2 = [/size][size=2][color=#008000]PORTC[/color][/size][size=2].[/size][size=2][color=#ff0000]1 [/color][/size][i][size=2][color=#000080]'FLASHING LED
[/i][/color][/size][size=2]start:
[/size][i][size=2][color=#000080]'first part of the program - adin etc.
[/i][/color][/size][size=2]
[b]Input [/b][/size][size=2][color=#008000]PORTB[/color][/size][size=2].x
[b]If [/b][/size][size=2][color=#008000]PORTB[/color][/size][size=2].x = [/size][size=2][color=#ff0000]1 [/color][/size][b][size=2]Then GoTo [/b]rest of the program
[b]DelayMS [/b][/size][size=2][color=#ff0000]5000
[/color][/size][size=2][b]If [/b][/size][size=2][color=#008000]PORTB[/color][/size][size=2].x = [/size][size=2][color=#ff0000]0 [/color][/size][b][size=2]Then GoTo [/b]delay : [b]Else GoTo [/b]rest of the program
[/size][i][size=2][color=#000080]'test if Portb.x has been low for 5 secs - if so, goto delay
[/i][/color][/size][size=2]
delay: [b]For [/b]NUM = [/size][size=2][color=#ff0000]1 [/color][/size][b][size=2]To [/b][/size][size=2][color=#ff0000]1800 [/color][/size][b][size=2]Step [/b][/size][size=2][color=#ff0000]1 [/color][/size][i][size=2][color=#000080]'30 minute delay
[/i][/color][/size][size=2][b]DelayMS [/b][/size][size=2][color=#ff0000]500
[/color][/size][size=2][b]High [/b]LED2 [/size][i][size=2][color=#000080]'not necesary but good to see if it is happening
[/i][/color][/size][size=2][b]DelayMS [/b][/size][size=2][color=#ff0000]500
[/color][/size][size=2][b]Low [/b]LED2
[b]Next
[/b][b]Sleep[/b] [/size][i][size=2][color=#000080]'do nothing else until reset or repowered
[/i][/color][/size][size=2]
[/size]
and here is the interuptt way
[left][size=2][size=2][color=#000000][b][size=2][color=#000000][b]INCLUDE[/b] [/color][/size][size=2][color=#0000f0]"PROTON_4.INC"[/color][/size][size=2][color=#000000]
[b]DIM[/b] RAW1 [b]AS[/b] [b]WORD[/b]
[b]DIM[/b] VOLTS1 [b]AS[/b] [b]FLOAT[/b]
[b]DIM[/b] RAW2 [b]AS[/b] [b]WORD[/b]
[b]DIM[/b] VOLTS2 [b]AS[/b] [b]FLOAT[/b]
[b]DIM[/b] RAW3 [b]AS[/b] [b]WORD[/b]
[b]DIM[/b] VOLTS3 [b]AS[/b] [b]FLOAT[/b]
[b]DIM[/b] RAW4 [b]AS[/b] [b]WORD[/b]
[b]DIM[/b] VOLTS4 [b]AS[/b] [b]FLOAT[/b]
[b]Dim[/b] M_Second_Counter [b]as[/b] [b]Word[/b]
[b]Dim[/b] Second_Counter [b]as[/b] [b]Byte[/b]
[b]Dim[/b] Minute_Counter [b]as[/b] [b]Byte[/b]
[b]Dim[/b] Voltmeter_Update_Timer [b]as[/b] [b]Word[/b]
[b]SYMBOL[/b] [/color][/size][b][size=2][color=#ff0000]LED1[/color][/size][/b][size=2][color=#000000] = [/color][/size][size=2][color=#008000]PortC[/color][/size][size=2][color=#000000].[/color][/size][size=2][color=#ff0000]0[/color][/size][size=2][color=#000000] 'FLASHING LED
[b]SYMBOL[/b] QUANTA = [/color][/size][size=2][color=#ff0000]5.0[/color][/size][size=2][color=#000000] / [/color][/size][size=2][color=#ff0000]1024[/color][/size][size=2][color=#000000] ' Calculate the quantasising value
[b]INPUT[/b] [/color][/size][size=2][color=#008000]Portb[/color][/size][size=2][color=#000000].[/color][/size][size=2][color=#ff0000]7[/color][/size][size=2][color=#000000] ' set it as input
[b]Output[/b] [/color][/size][b][size=2][color=#ff0000]Led1[/color][/size][/b][size=2][color=#000000] ' set it as output
[/color][/size][b][size=2][color=#800000]ADIN_RES[/color][/size][/b][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ' Set the resolution to 10
[/color][/size][b][size=2][color=#800000]ADIN_TAD[/color][/size][/b][size=2][color=#008000]FRC[/color][/size][size=2][color=#000000] ' Choose the RC osc for ADC samples
[/color][/size][b][size=2][color=#800000]ADIN_STIME[/color][/size][/b][size=2][color=#ff0000]50[/color][/size][size=2][color=#000000] ' Allow 50us for charge time
[b]Delayms[/b] [/color][/size][size=2][color=#ff0000]200[/color][/size][size=2][color=#000000] ' Wait for PICmicro to stabilize
[/color][/size][size=2][color=#008000]TRISA[/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#ff0000]%00001111[/color][/size][size=2][color=#000000] ' Configure AN0 (PORTA.0) as an input
[/color][/size][size=2][color=#008000]ADCON1[/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#ff0000]%10001110[/color][/size][size=2][color=#000000] ' Set analogue input on PORTA (VREF RA3)
[/color][/size][b][size=2][color=#ff0000]Led1[/color][/size][/b][size=2][color=#000000]=[/color][/size][size=2][color=#ff0000]0[/color][/size][size=2][color=#000000] ' LED is off
[b]GOSUB[/b] Voltmeter ' update voltmeter display
[b]Goto[/b] Start ' Jump over subrutines
'******************************************
Voltmeter:
RAW1 = [b]ADIN[/b] [/color][/size][size=2][color=#ff0000]0[/color][/size][size=2][color=#000000]
RAW2 = [b]ADIN[/b] [/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000]
RAW3 = [b]ADIN[/b] [/color][/size][size=2][color=#ff0000]2[/color][/size][size=2][color=#000000]
RAW4 = [b]ADIN[/b] [/color][/size][size=2][color=#ff0000]3[/color][/size][size=2][color=#000000]
VOLTS1 = RAW1 * QUANTA
VOLTS2 = RAW2 * QUANTA
VOLTS3 = RAW3 * QUANTA
VOLTS4 = RAW4 * QUANTA
[b]PRINT[/b] [b]at[/b] [/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000],[/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000],[b]DEC2[/b] VOLTS1 * [/color][/size][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ,[/color][/size][size=2][color=#0000f0]" V "[/color][/size][size=2][color=#000000] , [b]DEC2[/b] VOLTS2 * [/color][/size][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ,[/color][/size][size=2][color=#0000f0]" V "[/color][/size][size=2][color=#000000]
[b]PRINT[/b] [b]at[/b] [/color][/size][size=2][color=#ff0000]2[/color][/size][size=2][color=#000000],[/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000],[b]DEC2[/b] VOLTS3 * [/color][/size][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ,[/color][/size][size=2][color=#0000f0]" A "[/color][/size][size=2][color=#000000] , [b]DEC2[/b] VOLTS4 * [/color][/size][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ,[/color][/size][size=2][color=#0000f0]" A "[/color][/size][size=2][color=#000000]
[b]Return[/b]
'*******************************************
START:
[b]If[/b] Voltmeter_Update_Timer = [/color][/size][size=2][color=#ff0000]500[/color][/size][size=2][color=#000000] [b]then[/b] ' check if it it is time to update the display
[b]GOSUB[/b] Voltmeter ' update voltmeter display
[b]Clear[/b] Voltmeter_Update_Timer ' reset the update timer
[b]EndIF[/b]
[b]If[/b] [/color][/size][size=2][color=#008000]PORTB[/color][/size][size=2][color=#000000].[/color][/size][size=2][color=#ff0000]7[/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#ff0000]0[/color][/size][size=2][color=#000000] [b]then[/b] ' Check the switch status if On (0)
[b]Delayms[/b] [/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000]
[b]Inc[/b] M_Second_Counter ' Inc the ms timer (1 ms)
[b]Inc[/b] Voltmeter_Update_Timer ' Inc the update timer (1 ms)
[b]Else[/b] ' If the switch is OFF (1)
[b]Clear[/b] M_Second_Counter ' reset M_Second_Counter
[b]Inc[/b] Voltmeter_Update_Timer ' Inc the update timer (1 ms)
[b]Endif[/b]
[b]If[/b] M_Second_Counter < [/color][/size][size=2][color=#ff0000]2500[/color][/size][size=2][color=#000000] [b]then[/b] [b]goto[/b] START 'if switch is OFF or ON for less than 5 seconds then loop
' 2500 will give you about 5 sec., 5000 about 10 sec. the figures should be tuned
' you should compensate for other instrections Execution time specially (print).
' if reached here then the switch is on for 5 seconds
' start your 30 munite timer
[b]Clear[/b] M_Second_Counter ' reset M_Second_Counter
[b]Clear[/b] Second_Counter ' reset Second_Counter
[b]Clear[/b] Minute_Counter ' reset Minute_Counter
Delay:
[b]Delayms[/b] [/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000]
[b]Inc[/b] M_Second_Counter
[b]If[/b] M_Second_Counter = [/color][/size][size=2][color=#ff0000]500[/color][/size][size=2][color=#000000] [b]then[/b] [b]Toggle[/b] [/color][/size][b][size=2][color=#ff0000]LED1[/color][/size][/b][size=2][color=#000000] ' flash the LED
[b]If[/b] M_Second_Counter = [/color][/size][size=2][color=#ff0000]1000[/color][/size][size=2][color=#000000] [b]then[/b]
[b]Toggle[/b] [/color][/size][b][size=2][color=#ff0000]LED1[/color][/size][/b][size=2][color=#000000] ' flash the LED
[b]GOSUB[/b] Voltmeter ' update voltmeter display
[b]CLEAR[/b] M_Second_Counter
[b]INC[/b] Second_Counter
[b]IF[/b] Second_Counter = [/color][/size][size=2][color=#ff0000]60[/color][/size][size=2][color=#000000] [b]THEN[/b]
[b]INC[/b] Minute_Counter
[b]CLEAR[/b] Second_Counter
[b]IF[/b] Minute_Counter = [/color][/size][size=2][color=#ff0000]30[/color][/size][size=2][color=#000000] [b]THEN[/b] [b]GOTO[/b] START ' 30 min is completede go to start scanning the switch
[b]ENDIF[/b]
[b]ENDIF[/b]
[b]Goto[/b] Delay
[b]END
[/b][/color][/size][/b][/color][/size][/size][/left]
that should be a start for you
wizpic