Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Assembly Problem PIC 18F4520 Please help/Give hints!!!

Status
Not open for further replies.

upopads

Newbie level 3
Joined
Sep 13, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,340
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
 

bump, so i've figured out i dont need to declare so many registers so i'm going to fix that up.

Added after 17 minutes:

I can enter data in the debugger menu of my MPLAB IDE software and then step through the program that way to figure out what is going on. Creating the loops and count i need to do for the lab is going to be a bear though i will work on it more tomorrow.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top