Hi, Sorry for the delay. I got a working code that incorporate TMR0.
Code:
CLEAR DEFINE OSC 48
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
asm
;_PLLDIV_2_1L EQU H'F9' ; Divide by 2 (8 MHz oscillator input)
;__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L ' 1
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
;
;__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)
;__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H '2
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
INTCON = 100000 ' Enable global and TMR0 interrupts
T0CON = 000000 ' TMR0, CLK internal, prescaler 1:2, T0ON
ALPHA VAR WORD ;this variable counts in the PauseUS loop
BETA VAR BYTE ;this variable counts interrupt ticks
TRISD = 110100 ;sets the 3 output pins in the D port
PORTD = 000000 ;sets all pins low in the D port
ON INTERRUPT GOTO INTERUPTROUTINE ;This line needs to be early in the program, before
;the routine is called in any case.
MAINLOOP: ;Main loop blinks D0 and D1 alternately
IF PORTD.1 = 0 THEN ;]
PORTD.1 = 1 ;]
PORTD.0 = 0 ;] This part of the program blinks two LEDs in
ELSE ;] the foreground
PORTD.1 = 0 ;]
PORTD.0 = 1 ;]
ENDIF ;]
FOR ALPHA = 1 TO 300 ;The long pause is eliminated with this loop
PAUSEUS 100 ;PAUSE command with short latency
NEXT ALPHA ;
GOTO MAINLOOP ;end of loop
DISABLE ;DISABLE and ENABLE must bracket the interrupt routine
INTERUPTROUTINE: ;this information is used by the compiler only.
BETA = BETA + 1 ;
Lcdout $fe, 128, "Digital Output" ' Display
Lcdout $fe, $c0, "Counter: ", #BETA
IF BETA < 61 THEN ENDINTERRUPT ;one second has not yet passed
BETA = 0 ;
IF PORTD.3 = 1 THEN ;Interrupt loop turns D3 on and off every
PORTD.3 = 0 ;61 times through the interrupt routine.
ELSE ;That is about one second per full cycle
PORTD.3 = 1 ;
ENDIF ;
ENDINTERRUPT: ;
INTCON.2 = 0 ;clears the interrupt flag.
RESUME ;resume the main program
ENABLE ;DISABLE and ENABLE must bracket the int routine
END
I used "000 = 1:2 Prescale value( I think this is the fastest)" is this the pin that should be reading the pulse input?
I'm not really sure how to implement interrupt to the program yet, but I understand that its very important to learn this.
regards
tacbanon
Bookmarks