upopads
Newbie level 3
I need to add lines of code and I can't because i do it wrong.
Firstly i have to make the program search 10 stored bytes in the data registers starting from BUFFER. I added ten different REG labels with Hex addresses as specified in my book to do so. Although i am not sure if that was what i was supposed to do.
Next I have to Modify my program to count the number of positive readings. I have tried to implement what i think is correct however it is not working and i do not know how to fix.
I have to do one more thing but i know i could probably figure it out after being helped through these first two road blocks.
Here is my program modified from what was given in a template. This is for school but the teacher does not tell us what to do for whatever reason. I go to a weak engineering school that isn't competitive..
Main:
LIST P=18F4520, F=INHX32
#include <P18F4520.INC>
REG0 EQU 0x56 ;Define data register addresses
REG1 EQU 0x85
REG2 EQU 0x67
REG3 EQU 0x78
REG4 EQU 0x6F
REG6 EQU 0x7F
REG7 EQU 0xF2
REG8 EQU 0x98
REG9 EQU 0x72
REG10 EQU 0x65
BUFFER EQU 0x10 ;Data stored starting from register 10H
ORG 0x20 ;Begin assembly at 0020H
START:
MOVLW D'00'
MOVWF D'00'
CLRF REG0 ;REG0 is used to store maximum temparature
LFSR FSR0,BUFFER ;Set up FSR0 as pointer for data registers
NEXT: MOVF POSTINC0,W ;Get data byte in WREG
BZ FINISH ;Is byte = 0? If yes, data string is finished
BTFSC WREG,7 ;Is byte negative? If yes, go back; otherwise skip
BRA NEXT ;Byte is negative - go back
;CPFSLT REG0,0 ;Is byte larger than previous one? If yes, save
;BRA NEXT ;Byte is smaller - get next one
;MOVWF REG0 ;Save larger byte
CLRF D'00'
INCF D'00'
DECF D'10',1,0
BNZ SUM
MOVWF POS
BRA NEXT ;Go back and check next byte
FINISH NOP
END
Original Program Before i modified it: (This runs with no errors)
Title "IP6-4: Finding Max Temperature"
List p=18F452, f =inhx32
#include <p18F452.inc> ;The header file
REG0 EQU 0x00 ;Define data register address
BUFFER EQU 0x10 ;Data stored starting from register 10H
ORG 0x20 ;Begin assembly at 0020H
START: CLRF REG0 ;REG0 is used to store maximum temparature
LFSR FSR0,BUFFER ;Set up FSR0 as pointer for data registers
NEXT: MOVF POSTINC0,W ;Get data byte in WREG
BZ FINISH ;Is byte = 0? If yes, data string is finished
BTFSC WREG,7 ;Is byte negative? If yes, go back; otherwise skip
BRA NEXT ;Byte is negative - go back
CPFSLT REG0,0 ;Is byte larger than previous one? If yes, save
BRA NEXT ;Byte is smaller - get next one
MOVWF REG0 ;Save larger byte
BRA NEXT ;Go back and check next byte
FINISH NOP
END
Firstly i have to make the program search 10 stored bytes in the data registers starting from BUFFER. I added ten different REG labels with Hex addresses as specified in my book to do so. Although i am not sure if that was what i was supposed to do.
Next I have to Modify my program to count the number of positive readings. I have tried to implement what i think is correct however it is not working and i do not know how to fix.
I have to do one more thing but i know i could probably figure it out after being helped through these first two road blocks.
Here is my program modified from what was given in a template. This is for school but the teacher does not tell us what to do for whatever reason. I go to a weak engineering school that isn't competitive..
Main:
LIST P=18F4520, F=INHX32
#include <P18F4520.INC>
REG0 EQU 0x56 ;Define data register addresses
REG1 EQU 0x85
REG2 EQU 0x67
REG3 EQU 0x78
REG4 EQU 0x6F
REG6 EQU 0x7F
REG7 EQU 0xF2
REG8 EQU 0x98
REG9 EQU 0x72
REG10 EQU 0x65
BUFFER EQU 0x10 ;Data stored starting from register 10H
ORG 0x20 ;Begin assembly at 0020H
START:
MOVLW D'00'
MOVWF D'00'
CLRF REG0 ;REG0 is used to store maximum temparature
LFSR FSR0,BUFFER ;Set up FSR0 as pointer for data registers
NEXT: MOVF POSTINC0,W ;Get data byte in WREG
BZ FINISH ;Is byte = 0? If yes, data string is finished
BTFSC WREG,7 ;Is byte negative? If yes, go back; otherwise skip
BRA NEXT ;Byte is negative - go back
;CPFSLT REG0,0 ;Is byte larger than previous one? If yes, save
;BRA NEXT ;Byte is smaller - get next one
;MOVWF REG0 ;Save larger byte
CLRF D'00'
INCF D'00'
DECF D'10',1,0
BNZ SUM
MOVWF POS
BRA NEXT ;Go back and check next byte
FINISH NOP
END
Original Program Before i modified it: (This runs with no errors)
Title "IP6-4: Finding Max Temperature"
List p=18F452, f =inhx32
#include <p18F452.inc> ;The header file
REG0 EQU 0x00 ;Define data register address
BUFFER EQU 0x10 ;Data stored starting from register 10H
ORG 0x20 ;Begin assembly at 0020H
START: CLRF REG0 ;REG0 is used to store maximum temparature
LFSR FSR0,BUFFER ;Set up FSR0 as pointer for data registers
NEXT: MOVF POSTINC0,W ;Get data byte in WREG
BZ FINISH ;Is byte = 0? If yes, data string is finished
BTFSC WREG,7 ;Is byte negative? If yes, go back; otherwise skip
BRA NEXT ;Byte is negative - go back
CPFSLT REG0,0 ;Is byte larger than previous one? If yes, save
BRA NEXT ;Byte is smaller - get next one
MOVWF REG0 ;Save larger byte
BRA NEXT ;Go back and check next byte
FINISH NOP
END