Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lcd hello world #8

Open
wants to merge 30 commits into
base: LCD_Hello_World
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a1f769d
Update
minniewang12 Nov 28, 2023
aad9faf
Update
minniewang12 Nov 28, 2023
92f9f3f
Keypad module contains subroutine for Keypad reading
minniewang12 Nov 28, 2023
593eea7
Age Input Code Update
minniewang12 Nov 28, 2023
23b4749
End of session 2 working code (30/11)
minniewang12 Nov 30, 2023
3bdfe21
Division Subroutine Integrated with Module Clean Up
minniewang12 Nov 30, 2023
15354bf
Started Table Subroutine
minniewang12 Nov 30, 2023
3fbf709
Table Access Code Works
minniewang12 Nov 30, 2023
f880d57
Update: HRZ Table Read/Write
minniewang12 Dec 1, 2023
c8bfbf6
Timer0 interrupt
alexncoleman Dec 4, 2023
19f3a0b
HRZ Table Read/Write updated
minniewang12 Dec 4, 2023
8f6fd6e
Merge branch 'LCD_Hello_World' of https://github.com/alexncoleman/Hea…
alexncoleman Dec 4, 2023
2197c1a
Update RRInterval.s
alexncoleman Dec 4, 2023
168d8a8
Cleaned some unnecessary variables
minniewang12 Dec 4, 2023
33c088b
Example Routine for Timer added
minniewang12 Dec 4, 2023
7ee5556
Update main.s
minniewang12 Dec 4, 2023
f9c80f4
HRZ Table Compare Code added, deleted unnecessary files
minniewang12 Dec 5, 2023
bf24c34
Subtraction and Addition Subroutines in RRInterval.s added and checked
minniewang12 Dec 5, 2023
5184c13
HRZ Search Subroutine integrated into main.s
minniewang12 Dec 5, 2023
7a5684b
16 bit Division Subroutine
minniewang12 Dec 6, 2023
fd463fc
07/12 End of Session Update
minniewang12 Dec 7, 2023
344e508
IIR Filter Subroutine added
minniewang12 Dec 7, 2023
1deefa4
Sensor Pulse Pulling Routine
minniewang12 Dec 8, 2023
78f3221
calculation of heart rate from overflow added
minniewang12 Dec 8, 2023
796c0af
LCD
alexncoleman Dec 12, 2023
a08b587
12/12 Session Code Update
minniewang12 Dec 12, 2023
846ffd5
Nested Overflow Counter Added
minniewang12 Dec 12, 2023
affaa92
LCD Display working for age input and hr display
minniewang12 Dec 13, 2023
6e81c02
Loop routine formatted
minniewang12 Dec 13, 2023
f99fa62
Final Code Update
minniewang12 Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
295 changes: 295 additions & 0 deletions Calculations.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
#include <xc.inc>

global Divide_By_20, Divide_By_Ten, Load_HRZ_Table, Divide_By_Hundred, Determine_HRZ, IIR_Filter
global measured_heart_rate_zone_address, heart_rate_zone_address
; this includes subroutines for calculations: e.g. max heart rate calculation, boundary calculations
psect udata_acs
myDenominator_low:ds 1
myNumerator:ds 1
myQuotient:ds 1
myRemainder:ds 1
myDiff:ds 1
STATUS_CHECK:ds 1
HR_max:ds 1
Zone_Value:ds 1
HR_Measured:ds 1 ; reserve one byte for measured HR value from sensor

x1:ds 1
x2:ds 1
x3:ds 1
x1x2H:ds 1
x1x2L:ds 1
x1x2x3H:ds 1
x1x2x3L:ds 1
myDen_low:ds 1
myQuo:ds 1
myRem:ds 1


psect calculations_code,class=CODE

Divide_By_20: ; divide the number stored in WREG by 20
; Ensure myDenominator is not zero
; MOVWF myNumerator

MOVLW 19 ; Think this needs to be n - 1, where n is the denominator??
MOVWF myDenominator_low ; divide by 20

MOVLW 0 ; Move 0 into WREG to check if denominator is zero
CPFSEQ myDenominator_low
GOTO Clear ; Check the MSB of myDenominator
GOTO DivisionError ; If zero, handle division by zero
Clear: ; Perform division algorithm
CLRF myQuotient ; Clear the quotient register
CLRF myRemainder ; Clear the remainder register

Division_Loop:
MOVFF myDenominator_low, WREG
CPFSLT PRODL ; if lower byte is smaller than denominator: need to borrow
bra Subtract
bra Borrow_or_Done
Borrow_or_Done:
MOVLW 0
CPFSGT PRODH ; Check if done, i.e. if the upper byte is zero.
bra Division_Done
DECF PRODH, 1 ; Borrow from higher byte
;sMOVFF PRODH, PORTB
Subtract:
INCF myQuotient, 1 ; Increment quotient
MOVFF myQuotient, PORTD
MOVFF myDenominator_low, WREG
SUBWFB PRODL, 1 ; myNumerator -= myDenominator
;MOVFF PRODL, PORTC
bra Division_Loop
Division_Done:
;MOVFF myQuotient, PORTC
MOVFF myQuotient, WREG ; return with the quotient in the WREG
RETURN
DivisionError:
RETURN


Load_HRZ_Table: ; call with HR_max in WREG
MOVWF HR_max

movlw heart_rate_zone_address
movwf FSR0

CLRF EEADR ; start at address 0
BCF EECON1, 6 ; set for memory, bit 6 = CFGS
BCF EECON1, 7 ; set for data EEPROM, bit 7 = EEPGD
;BSF EECON1, 2 ; write enable, bit 2 = WREN
;BCF INTCON, 7 ; disable interrupts, bit 7 = GIE

Loop:
;MOVFF EEADR, PORTB
BSF EECON1, 0 ; read current address, bit 0 = RD
nop ; need to have delay after read instruction for reading to complete
MOVFF EEDATA, WREG ; W = multiplier
;MOVFF EEDATA, PORTC
MULWF HR_max

CALL Divide_By_20 ; (HR_max*multiplier)/20, return with quotient in WREG

MOVWF INDF0
INCF FSR0

; MOVWF EEDATA ; move data to EE
;
; MOVLW 0x55
; MOVWF EECON2
; MOVLW 0xAA
; MOVWF EECON2
;
; BSF EECON1, 1 ; to write data, bit 1 = WR
; BTFSC EECON1, 1
; bra $-2 ; wait for write to complete
INCF EEADR, 1 ; Increment address and save back to EEADR

MOVFF EEADR, WREG ; Routine to check if the end has been reached
SUBLW 6
MOVWF STATUS_CHECK
MOVLW 0
CPFSEQ STATUS_CHECK ; comparison to see if the end of the table has been reached
bra Loop
bra End_Write
End_Write:
; Continue on with the rest of the code
;BCF EECON1, 2 ; disenable writing function
MOVLW 0xFF
MOVWF PORTD
RETURN

Determine_HRZ: ; enter with measured HR stored in WREG
movwf HR_Measured

movlw heart_rate_zone_address
movwf FSR2

MOVLW 6
MOVWF Zone_Value ; initialise at 6, highest possible zone value is 5

Table_Compare_Loop:
MOVF POSTINC2, W, A ; move heart rate to WREG
CPFSLT HR_Measured ; skip if f < W
bra Output_Zone_Value
decfsz Zone_Value
bra Table_Compare_Loop
Output_Zone_Value:
MOVFF Zone_Value, WREG
return

IIR_Filter:
MOVWF x3 ; newest measurement WREG -> x3

MOVFF x1, WREG
ADDWF x2, 0 ; 200 + 256 = 456 = 1C8
MOVWF x1x2L

MOVLW 0x00
ADDWFC x1x2H, 1 ; carry to higher byte
INCF x1x2L, 1

; give newest measurement a higher weighting, multiply it by 2
MOVFF x3, WREG ; newest measuremeng in WREG
MULLW 2 ; double the weighting than the other two measurements
; results stored in PRODH:PRODL 2*HR_newest
MOVFF PRODH, WREG
MOVFF PRODL, WREG
ADDWF x1x2L, 0 ; 456 + 200 = 656 = 290
MOVWF x1x2x3L ; contains lower byte of sum

MOVFF PRODH, WREG
ADDWFC x1x2H, 0
MOVWF x1x2x3H ; contains higher byte of sum

; divide by 4

MOVLW 3 ; Think this needs to be n - 1, where n is the denominator??
MOVWF myDen_low ; divide by 4 to find the average

MOVLW 0 ; Move 0 into WREG to check if denominator is zero
CPFSEQ myDen_low
GOTO Clear_1 ; Check the MSB of myDenominator
GOTO DivisionError_1 ; If zero, handle division by zero
Clear_1: ; Perform division algorithm
CLRF myQuo ; Clear the quotient register
CLRF myRem ; Clear the remainder register
Division_Loop_1:
MOVFF myDen_low, WREG
CPFSLT x1x2x3L ; if lower byte is smaller than denominator: need to borrow
bra Check_Equal
bra Borrow_or_Done_1
Borrow_or_Done_1:
MOVLW 0
CPFSGT x1x2x3H ; Check if done, i.e. if the upper byte is zero.
bra Division_Done_1
DECF x1x2x3H, 1 ; Borrow from higher byte
;MOVFF x1x2x3H, PORTB
bra Subtract_1
Check_Equal:
MOVFF myDen_low, WREG
CPFSEQ x1x2x3L
bra Subtract_1
bra Borrow_or_Done_1
Subtract_1:
INCF myQuo, 1 ; Increment quotient
MOVFF myQuo, PORTD
MOVFF myDen_low, WREG
SUBWFB x1x2x3L, 1 ; myNumerator -= myDenominator
;MOVFF x1x2x3L, PORTC
bra Division_Loop_1
Division_Done_1:
bra Update_Vals
MOVFF myQuo, WREG ; 656/4 = 164 ...
RETURN
DivisionError_1:
RETURN
Update_Vals:
MOVFF x2, WREG
MOVWF x1 ; update x1 with value in x2
MOVFF myQuo, WREG
MOVWF x2 ; update x2 with newest measurement
return

Divide_By_Ten:
; Ensure myDenominator is not zero
MOVWF myNumerator
; Think this needs to be n - 1, where n is the denominator??
MOVLW 9
MOVWF myDenominator_low ; divide by 20

MOVLW 0
CPFSEQ myDenominator_low
GOTO Clear_Ten ; Check the MSB of myDenominator
GOTO DivisionError_Ten ; If zero, handle division by zero
Clear_Ten: ; Perform division algorithm??
CLRF myQuotient ; Clear the quotient register
CLRF myRemainder ; Clear the remainder register

Division_Loop_Ten:
MOVFF myDenominator_low, WREG
CPFSLT myNumerator ; if lower byte is smaller than denominator: need to borrow
BRA Subtract_Ten
BRA Division_Done_Ten
;Borrow_or_Done_Ten:
; MOVLW 0
; CPFSGT PRODH ; Check if done, i.e. if the upper byte is zero.
; BRA Division_Done_Ten
; DECF PRODH, 1
; ;MOVFF PRODH, PORTB
Subtract_Ten:
INCF myQuotient, 1
;MOVFF myQuotient, PORTD
MOVFF myDenominator_low, WREG
SUBWFB myNumerator, 1
;MOVFF PRODL, PORTC
BRA Division_Loop_Ten
Division_Done_Ten:
;MOVFF myQuotient, PORTC
MOVFF myQuotient, WREG ; return with the quotient in the WREG
RETURN
DivisionError_Ten:
RETURN

Divide_By_Hundred:
; Ensure myDenominator is not zero
MOVWF myNumerator ; enter routine with numerator in WREG
; Think this needs to be n - 1, where n is the denominator??
MOVLW 99
MOVWF myDenominator_low ; divide by 20

MOVLW 0
CPFSEQ myDenominator_low
GOTO Clear_Hundred ; Check the MSB of myDenominator
GOTO DivisionError_Hundred ; If zero, handle division by zero
Clear_Hundred: ; Perform division algorithm??
CLRF myQuotient ; Clear the quotient register
CLRF myRemainder ; Clear the remainder register

Division_Loop_Hundred:
MOVFF myDenominator_low, WREG
CPFSLT myNumerator ; if lower byte is smaller than denominator: need to borrow
BRA Subtract_Hundred
BRA Division_Done_Hundred
;Borrow_or_Done_Hundred:
; MOVLW 0
; CPFSGT PRODH ; Check if done, i.e. if the upper byte is zero.
; BRA Division_Done_Hundred
; DECF PRODH, 1
; ;MOVFF PRODH, PORTB
Subtract_Hundred:
INCF myQuotient, 1
;MOVFF myQuotient, PORTD
MOVFF myDenominator_low, WREG
SUBWF myNumerator, 1
;MOVFF PRODL, PORTC
BRA Division_Loop_Hundred
Division_Done_Hundred:
;MOVFF myQuotient, PORTC
MOVFF myQuotient, WREG ; return with the quotient in the WREG
RETURN
DivisionError_Hundred:
RETURN


Loading