This code can produce 38KHz signal compatible with TSOP1838 but I tried another method because I need to use TMR0 as a counter. Device = 16F877 Xtal 4 Dim OnCycle As Byte Dim OffCycle As Byte DelayUS 10 CCP1_Pin = TRISC.2 HPWM 1,127,38000 TSOP1838: clrwdt For OnTime = 1 To 250 TRISC.2 = 0 clrwdt Next For OffTime = 1 To 250 TRISC.2 = 1 clrwdt Next GoTo TSOP1838 I am using TMR0 as a counter,TMR1 as a timer to cause an interrupt after one second and TMR2 as a timer to help produce 38Khz signals compatible with TSOP1838,infrared receiver module. When TMR1 overflows, it goes into interrupt service routine and make CNT =1 so that when return from interrupt we then go to Display so that we print the value of WRD on the LCD. the problem is that it seems TMR2 is not active(not working) because when simulated the output of PORTC.2 using PROTEUS it seems there is no signal (TSOP1838 pulses).At one point the output of PORTC.2 is a DC value that is being decremented starting at 5 volts in steps of 1 volt until it reaches zero volts. Can you help me to debug this program? WHAT IS MOST IMPORTANT NOW IS TO PRODUCE 38KHZ SIGNAL COMPATIBLE WITH TSOP1838 ON PORTC.2 WITH LITTLE ALTERATIONS. But TMR0 should be used as counter and TMR1 as a timer. Device = 16F877 Xtal = 4 LCD_DTPin = PORTB.4 LCD_RSPin = PORTB.2 LCD_ENPin = PORTB.3 LCD_Interface = 4 ' Interface method is 4 bit mode LCD_Lines = 2 ' Number of lines in LCD LCD_Type = 0 ' type of LCD used, alpha numeric Declare LCD_CommandUs = 2000 ' Time to wait in microseconds btwn commands sent to LCD Declare LCD_DataUs = 50 ' Time to wait in microseconds between data sent to LCD All_Digital = True 'Generic way to set all ports to digital mode Symbol State = PORTA.1 'assign the input to count/hold button Symbol Timer1 = TMR1L.Word ' A special way of addressing both TMR1L and TMR1H with one register Symbol GIE = INTCON.7 Symbol TMR1IF = PIR1.0 Symbol TOIF = INTCON.2 Symbol TMR1_EN = T1CON.0 Symbol TMR2_EN = T2CON. Dim Whereto As Byte Dim WRD As Dword Dim CNT As Byte Dim OnTime As Byte Dim OffTime As Byte INTCON = %11100000 'enable GIE,PEIE and TMR0 overflow OPTION_REG = %10110111 'assign TMR0/counter,prescaler to 1:2 and inc on high to low CCP1CON = %00001100 'Set CCP1CON to PWM TRISA = %11111111 PORTA = %11111111 PORTB = %11111100 Whereto = 0 CNT = 0 DelayMS 10 GoTo Main On_Interrupt GoTo Int_Sub Int_Sub: Context Save GIE = 0 WRD = TMR0 TMR1IF = 0 CNT = 1 Whereto = 0 GIE = 1 Context Restore Return Main: Cls Print At 1,1, "-Tinashe Paul-" Print At 2, 1, "welcome" DelayMS 3000 ' Delay for 2 sec while the above text is on display Cls ' Clear LCD Print At 1, 3, "SUPERVISOR" Print At 2, 2, "Eng G Kapungu" DelayMS 3000 ' Delay for 2 sec while the above text is on display Ready: Cls ' Clear LCD Print At 1,1, "Press Count/Hold" Print At 2,6, "Button" DelayMS 1000 CheckStatus: 'check if porta.1 is high(pressed).Count/hold button If State = 1 Then GoTo Start ElseIf Whereto > 0 Then 'hold last value GoTo CheckStatus Else GoTo Ready EndIf Start: PIR1 = %0000000 'clear TMR1 interrupt flag PIE1 = %0000001 'TMR1 overflow interrupt enable CCP1_Pin = PORTC.2 'PORTC.2 is the CCP1 pin on the 16F877 device HPWM 1,127,38000 ' Send a 50% duty cycle PWM signal at 38KHz PR2 = 255 T2CON = %00000100 'TMR2 on,prescaler 1: 1,postscaler 1:1 T1CON = %00110101 'counter mode,rising edge,NO SYNC,prescaler 1:8,TMR1 on TSOP1838_PULSES: Clear TMR2 For OnTime = 1 To 250 TRISC.2 = 0 DelayUS 4 Clear TMR2 Next For OffTime = 1 To 250 TRISC.2 = 1 DelayUS 4 Clear TMR2 Next If CNT = 1 Then GoTo Display Else GoTo TSOP1838_PULSES EndIf Display: TMR1_EN = 0 Cls ' Clear LCD WRD = WRD * 1 'Multiply WRD by 1 and store in WRD Cursor 1,6 Print Dec WRD , " " ' Display the decimal result on the LCD Print At 2,2, "REVS PER MINUTE" DelayUS 500 CNT = 0 Inc Whereto GoTo CheckStatus ' Do it indefinitely End