Estoy haciendo pruebas con el ccp en modo captura, para probarlo estoy haciendo un tacometro, pero no logro que funcione, el codigo esta sin comentar si deseais que lo comente no teneis mas que decirlo, el tacometro siempre marca lo mismo ponga lo que ponga en la entrada, ¿Que estoy haciendo mal ?
Gracias.
program tacometro
const res as word = 0xf424
dim contador as word
dim vueltas as longword
dim tem as string[10]
' Declarations section
dim LCD_RS as sbit at RB4_bit
LCD_EN as sbit at RB5_bit
LCD_D4 as sbit at RB0_bit
LCD_D5 as sbit at RB1_bit
LCD_D6 as sbit at RB2_bit
LCD_D7 as sbit at RB3_bit
LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit
sub procedure interrupt
if TestBit(PIR1, TMR1IF) = 1 then
TMR1H = 0x0B
TMR1L = 0xDC
ClearBit(PIR1, TMR1IF)
' ClearBit is realised as an inline function,
' and may be called from within an interrupt
else
if TestBit(PIR1,CCP1IF) = 1 then
contador = (CCPR1H - 0x0B) * 0X0100
CONTADOR = CONTADOR + (CCPR1L - 0xDC)
vueltas = CONTADOR * 4
'vueltas = vueltas / 1000000
'vueltas = 60 / vueltas
TMR1H = 0x0B
TMR1L = 0xDC
ClearBit(PIR1,CCP1IF)
ClearBit(PIR1, TMR1IF)
end if
end if
end sub
main:
INTCON = 192 ' Enable Global & Peripheral Interrupts
T1CON = 48 ' Ticks every 4us
TRISC.2 = 1 ' CCP1 pin is input
CCP1CON = 5 ' catch every rising edge
PIE1.CCP1IE = 1 ' enable CCP1 Interrupt
PIR1.CCP1IF = 0 ' Clear CCP1 INTERRUPT Flag
TMR1H = 0X0B ' reset Timer1
TMR1L = 0XDC
T1CON.TMR1ON = 1 ' Timer1 Running
ADCON0 = 0x00
ADCON1 = 0x0F
TRISB = 0x00
portb = 0
' Main program
Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off
LCD_out(1,11,"RPM")
while true
delay_ms(100)
longWordToStr(vueltas, tem)
LCD_out(1,1,tem)
wend
end.
Ver Imagen: captura1tv17vh.jpgGracias de nuevo.