I want to decode the DCC protocol used for model railroading with a pic microcontroller. I start this project with an experiment: a 15khz square wave is connected to the CCP2 input pin. The CCP module should capture the values of TMR1 on each rising edge and display that value on the lcd.
I know the lcd is connected an configured correctly, but i don't see a value appearing on it. I think the interrupt is not fired and it's likely that i forgot to enable something, but can't find what that might be.
;-------------------------------------------------------------------------------
;programma
;Controller = PIC 16F886
;-------------------------------------------------------------------------------
include 16f886
;Alle mogelijke 'fuses' voor een 16F887
;8MHz intern
pragma target OSC INTOSC_CLKOUT
pragma target clock 8_000_000 -- oscillator frequency
pragma target WDT disabled -- WDT off
pragma target LVP disabled -- no low voltage programming
pragma target PWRTE DISABLED -- power-up timer enable bit
pragma target MCLR Internal -- re3/mclr pin function select bit
pragma target CPD DISABLED -- data code protection bit
pragma target BROWNOUT DISABLED -- brown out reset selection bits
pragma target IESO DISABLED -- internal external switchover bit
pragma target FCMEN DISABLED -- fail-safe clock monitor enabled bit
pragma target DEBUG DISABLED -- in-circuit debugger mode bit
OSCCON_IRCF=0b111 -- set oscillator to full speed 8 Mhz (standard 4 Mhz)
-------------------------------------------------------------------------------
;lcd setup
-------------------------------------------------------------------------------
const byte LCD_ROWS = 2 --LCD with 2 lines
const byte LCD_CHARS = 16 --and 16 characters per line
alias lcd_en is pin_b5 --LCD EN
alias lcd_rs is pin_b4 --LCD RS
pin_b5_direction = output --Beiden
pin_b4_direction = output --als uitgangen
alias lcd_dataport is porta_low --4 databits
porta_low_direction = output --eveneens als uitgang
;De bibliotheek met LCD routines laden
include lcd_hd44780_4
;Gebruik maken van bestaande routines om iets op het LCD tre laten verschijnen
include print
;Getallen geformatteerd weergeven op het LCD met ingebouwde functies uit de
;format bibliotheek
include format
;En het LCDinitialiseren
lcd_init()
--------------------------------------------------------------------------------
;setup registers for capture on ccp2
--------------------------------------------------------------------------------
INTCON_GIE=true -- enable interrupts
INTCON_PEIE=true -- enable peripheral interrupts
PIE2_CCP2IE=true; --enable ccp2 module interrupt
T1CON_TMR1ON=on --enable timer1 as timer, no prescaler
CCP2CON=5; --set ccp module to interrupt on each rising edge
alias dccinput is pin_ccp2 -- input pin for ccp module
pin_ccp2_direction=input
--------------------------------------------------------------------------------
procedure isr is
pragma interrupt
lcd_cursor_position(0,0)
print_byte_dec(lcd,ccpr2h)
lcd_cursor_position(1,0)
print_byte_dec(lcd,ccpr2l)
PIR2_CCP2IF=false
end procedure