Originally Posted by
lerameur
Hi,
Ok I added an interrupt and wrote the program from what you said. Althouth I get zero on the LCD, seems that the interrupt is not working, can you help me debug it? Do I need to initialize some parameter . I am using the pic16f88
Ken
' Internal Oscillation program
' LCD
' Main loop display the counts and the interrupt routine counts
'/////////////////////////
'// Define section //
'/////////////////////////
INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language
@ DEVICE pic16F88, INTRC_OSC, CCPMX_ON, MCLR_ON
OSCCON=$60 ' use internal 4MHZ osc
CMCON = 7 ' Turn OFF the comparators so pins can be used as digital I/O-pins
'///////////////////////////
'// Interrupt section //
'///////////////////////////
OPTION_REG = %00111000
'Transition on TOCKI (RA4),
'Increment on falling edge
'Prescalar assigned to WDT for a 1:1 TMR0 ratio.
INTCON.2 = 0 ' Clear Timer0 int flag
INTCON.5 = 1 ' Enable Timer0 int
TMR0 = $FF ' Set TMR0 to 255. So one more tick and TMROIF will be set.
'/////////////////////////
'// LCD configuration //
'/////////////////////////
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits) '4 therefore put wire at 4, 5, 6 and 7 of LCD
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
pause 1000
'/////////////////////////
'// PIN configuration //
'/////////////////////////
TRISA = %11110111 ' Set PORTA to all input
' Set PORTA.4 (TOCKI) to input for timer0
TRISB = %00001111 ' Set PORTB to all output
PortA = 0
'///////////////////////////////////////////////
'// Variable Declaration and initialization //
'///////////////////////////////////////////////
Revolution var word
Counter var word
oldCounter var word
feet var word
feet_left var word
feet_right var word
revolution = 0
Counter = 0
feet = 0
PortB.2 = 1 'Put to 5v via a resistor and a pushbutton to ground for reset
ON INTERRUPT GOTO LapCount
Mainloop:
if PortB.2 = 0 then
goto Reset_variables
endif
lcdout $FE,1, "Cter:",dec Counter, " Rev:",dec Revolution
lcdout $FE,$C0, "Feet:",dec feet/12, ".", dec2 feet//12 'This will save feet, and the // will print the decimal to two decimal point
pause 20
GOTO Mainloop
Reset_variables:
revolution = 0
Counter = 0
feet= 0
lcdout $FE,1, "Counter:",dec Counter , " Rev:",dec Revolution
lcdout $FE,$C0, "Feet:",dec feet/12, ".", dec2 feet//12
pause 20
GOTO Mainloop
disable
LapCount:
If INTCON.2 = 1 then
Counter = Counter + 1
endif
toggle PORTB.3
TMR0 = $FF ' Indicate we're in interrupt handler
INTCON.2 = 0 ' Clear TMR0 Interrupt Flag (Bit 2)
'Calculate the distance
if Counter =4 then
Revolution = Revolution + 1
Counter =0
endif
feet_left = Revolution *3
feet_right = Revolution *25
feet_right = feet_right / 100
feet= feet_left +feet_right
Resume
Enable
end
Bookmarks