Device = 18F452
Clock = 20
// some LCD options...
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.2
#option LCD_EN = PORTB.3
// import LCD library...
Include "LCD.bas"
Include "utils.bas"
Include "ISRTimer.bas"
Include "convert.bas"
Dim
up As PORTA.0,
dw As PORTA.1,
RBIF As INTCON.0,
RBIE As INTCON.3
Dim CW As Word,
CCW As Word
// Start Of Program...
SetAllDigital
ADCON1 = %00000110
Input(up)
Input(dw) // Make the Hall-Effect sensor pin an input
DelayMS(150) // Allow the LCD to warm up
Cls // Clear the LCD, and display
WriteAt(1,1,"degrees rotation") // default information
// Create an infinite loop
// Reset PreScaler register
Interrupt PORTA0_Change()
end
Save(0) // Save the system variables
If RBIF = 1 Then // Check if the interrupt was a PORTA change
RBIF = 0
WREG = PORTB // Be sure to read the contents of PORTB to
EndIf
end interrupt
Restore // Restore the system variables
// clear the missmatch
// PORTB 7:4 has changed, do what you want here...
While true
//interupt routine
// PORTB 7:4 has changed, do what you want here...
Sub PORTA_Interrupts(Control As Boolean) // Small routine to enable/disable PORTA Interrupts.
If Control = True Then //
RBIE = 1 //
Enable(PORTA_Change) //
Else //
RBIE = 0 //
Disable(PORTA_Change) //
EndIf //
End Sub
Inline Sub Sleep()
ASM
Sleep
End ASM
End Sub
// Start Of Program...
TRISB = %11110000 //????????? Make PORTB7:4 all inputs
TRISC = %00000000 // ??????Make PORTC all outputs
PORTA_Interrupts(True) // Enable PORTA interrupts
While True // Infinite loop
If up> dw Then
Repeat Until
up = dw // check if A0 is high and A1 is low loop
// when up = dw then add to cw count
CW = CW + 1 // add 1 degree rotation
If dw> up Then
Repeat Until
dw = up //check if A1 is high and A0 is low loop
If up > dw Then
CCW = CCW + 1
EndIf
WriteAt(2,1,DecToStr(PreScaler, 4)) // Display the variable on the LCD
// (always show 4 digits)
Wend