HI, I am not able to make this code work, always leaves me with ORevs = 1 on the LCD.
I also change the oscillation to 20 Mhz but did not see any difference.
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, MCLR_ON
OSCCON=$60 ' use internal 4MHZ osc
ANSEL = 0 : ADCON1 = 7
CCP1CON = 0 'CCP1 module off
'/////////////////////////
'// 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 = %11111111 ' Set PORTA.4 (TOCKI) to input for timer0
TRISB = %00001111 ' Set PORTB
PortA = 0
'///////////////////////////////////////////////
'// Variable Declaration and initialization //
'///////////////////////////////////////////////
Revs var word
ORevs var word
ANSEL = 0 ' disable A/D so RA4 is digital
CMCON = 7 ' disable comparators
OPTION_REG = %00110001 ' RA4 = count input
' inc count every 4th falling edge with 1:4 prescale
' assigned to TMR0
Mainloop:
TMR0 = 0 ' clear count before pause
PAUSE 20 ' Adjust this to set how long it counts revolutions here
Revs = TMR0 ' TMR0 counts 1 rev for every 4 pulses
ORevs = Revs +1
LCDOUT $FE,1,"ORevs: ",DEC ORevs
GOTO Mainloop
end
Bookmarks