Code:
16F88, PBP 2.60, MPASM 5.20
Include "MODEDEFS.BAS" ' Include Shiftin/out modes
Include "DT_INTS-14.bas" ' Darrel's routines.
Include "ReEnterPBP.bas" ' Only needed if Pbp Interrupts used.
Define LCD_DREG PORTB ' Port for LCD Data.
Define LCD_DBIT 4 ' Use upper 4 bits of Port.
Define LCD_RSREG PORTA ' Port for RegisterSelect (RS) bit.
Define LCD_RSBIT 7 ' Port Pin for RS bit.
Define LCD_EREG PORTA ' Port for Enable (E) bit.
Define LCD_EBIT 6 ' Port Pin for E bit.
Define LCD_BITS 4 ' Using 4-bit bus.
Define LCD_LINES 2 ' Using 2 line Display.
Define LCD_COMMANDUS 2000 ' Command Delay (uS).
Define LCD_DATAUS 50 ' Data Delay (uS).
DEFINE DEBUG_REG PORTB ' Debug pin port
DEFINE DEBUG_BIT 1 ' Debug pin bit
DEFINE DEBUG_BAUD 9600 ' Debug baud rate
DEFINE DEBUG_MODE 1 ' Debug mode: 0 = True, 1 = Inverted
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
' DEFINE OSC 8 ' Needed if oscon set for 8Mhz.
' OSCCON = %01110010 ' 8Mhz (F88).
OPTION_REG.6=0 ' 0=Falling-Edge Trigger.
OSCCON = %01100010 ' 4Mhz (F88).
TRISA = %00101111 ' A.5 Set, A.3 WD2, A.2 WS2, A.1 WD1, A.0 WS1.
TRISB = %00001101 ' B.3 -, B.2 +, B.0 Sin.
ANSEL = %00001010 ' PORTA.1,3 analog, remainder digital (F88).
ADCON0 = %11001101 ' Set A/D to Frc, Channel 1, On (F88).
ADCON1 = %10000000 ' R justify (where the 6 MSB of ADRESH read as 0 i.e. 10 bit), Vdd for Vref.
CMCON = 7 ' Comparators off.
pause 100 ' Let everything settle...
RedLED = 0 ' Red LED Off.
clear
debug 10,13,"I'm Alive!",10,13 '
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _MyInt, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'@ INT_ENABLE INT_INT ; enable external (INT) interrupts (enabled further down).
GOTO Satu ' Jump over the subroutines area.
' Subroutines here in the first page...
' Program area...
Satu: ' Operation when system first powered up.
Running: ' Normal running routine.
if x=1 then ' Returning from 1Min Rollover or Interrupt.
gosub ResetAll ' Start fresh count - Clear and reset all.
gosub Read_offsets ' Retrieve stored values.
endif '
@ INT_DISABLE INT_INT ; No Ints during the For/Next loop - ensures complete set for math.
for T = 0 to 2 ' 3 event sliding window.
gosub Blinky ' LED shows sampling.
gosub Get_revs ' Run the count routine.
ch = 1 ' Second channel for direction 1 (ch0 for S1).
gosub Get_Dirn ' Read the realtime direction.
LCDOUT $FE,$CF,Dec T ' Second line, last position - indicates present count.
' This section averages the speed of the latest three samples i.e. derives Gust.
' This section deals with Wind Direction.
' Get instant Wind Direction value.
' Update Max and Min Direction
' Update Sigma Theta
' 1min period report.
if Wsmpls=60 then '
debug 10,10,13,"S1i ",#S1i,", S1x ",#S1x,", Gu1x ",#Gu1x,", Gu1av ",#Gu1av,13,10,_
"AD ",#AD_res,", WD1av ",#WD1d,", Max ",#D1x,", Min ",#D1n,", ST1av ",#ST1av,10,10,13 ' ****
x=1
goto Running ' Reset all and start again.
endif
Continue:
pause z ' This plus sensor 1 count period should equal 1 second
next ' Back to loop testing.
@ INT_ENABLE INT_INT ; enable external (INT) interrupts only after For/Next loop is completed.
goto Running ' Repeat the whole cycle.
'---[INT - interrupt handler]---------------------------------------------------
MyInt:
toggle RedLED ' Blink the LED on interrupt.
' Report the Av wind speed, Maximum Gust, Maximum Speed, Av dirn and Sigma Theta since last interrupt.
debug 10,13,dec3 S1av,".",dec1 S1avr,",",dec3 Gu1x,",",dec3 S1x,",",dec3 WD1d,",",dec3 ST1,13,10
LCDOUT $FE,$C0,"Data out, Reset!" ' Second line.
pause 1000 ' Time enough to read.
x=1 ' Flag the interrupt.
@ INT_RETURN ; Return to point of Interrupt and resume.
Can anyone offer some advice or point out where I am going wrong please?
Bookmarks