PIC 16F628 FREQ 18.432 OSCILLATOR CRYSTAL BYTE Pauses WORD Pulses,Pul_div_2 IR_Ext_Begin Pulses=Pulses+1 IR_Ext_End ' 'configure Ports, RB0 is ST-input 'RB3 is reserved for the PWM ' SetPort A , %00000000 SetPort B , %00000001 ' 'wait a bit ' DELAY 1000, 0 ' 'clear variables ' Pulses=0 Pauses=0 ' 'configue and enable RB0 edge-interrupt ' Interrupt_Ext 1, rising Interrupt_Enable ' 'configure and enable PWM ' PWM_Config 888.099, 0, 1, 0 ' ' 'Main Loop ' LOOP : 'waiting 1/4sec provides us a 4Hz resolution DELAY 250, 0 IF PULSES<>0 THEN 'LED-8bit output at 8Hz ' Pul_div_2=Pulses/2 *MOVF PUL_div_2_L,W *ANDLW B'11110110' *MOVWF PORTB *MOVF PUL_div_2_L,W *ANDLW B'00001001' *MOVWF PORTA ' 'PWM at 4Hz 'The next line is to overcome 0.67V problem Pulses=pulses+256 *MOVF Pulses_H,W *ANDLW B'00000011' *MOVWF Pulses_H *ANDLW B'00000011' PWM_Reg Pulses, 1 PULSES=0 ELSE 'wait 1sec to reset if 0 Hz Pauses=Pauses+1 IF Pauses>2 THEN Pauses=0 PortOut A , %00000000 PortOut B , %00000000 PWM_Duty 0, 1 Pulses=0 END IF END IF ' GOTO LOOP