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.

Need Set of Eyes to Find Error - PIC18F4550

Status
Not open for further replies.

SamanthaL

Junior Member level 2
Joined
Feb 4, 2009
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,474
Hello everyone!

I'm getting a really weird error from my code and I can't figure out where its coming from! Below is a snippet of my code. I've been commenting out a lot of stuff to try and isolate this error. Below is the code that I believe is executing. (If it isn't, I can't find why!)

Start
;goto Debug ; Debugging code
clrf TRISB ; Make PORTB pins all outputs
clrf PORTB ; Clear PORTB outputs

clrf TRISD ; Make PORTD pins all outputs
clrf PORTD ; Clear PORTD outputs

clrf Test_Count ; Counter of test cases - start at 0
clrf Test_Case ; Stores 8 bits of test case - start at 0
MOVLF b'00000011', TRISC ;Set I/O for port C

Generate_Test_Cases
movf b'11111111', W
movwf Test_Case
bsf PORTC,6 ; MC code is 01
bcf PORTC,2 ; MC now ready to send data
; DEBUGGING CODE
goto MC_Transmission_Ready

MC_Transmission_Ready
movf Test_Case, W
movwf PORTD
goto Wait
bsf PORTC,2 ; MC code is now 10
bcf PORTC,6 ; MC ready for data from FPGA
goto Contact_FPGA

etc...

The above code should just turn on all the LED's. Instead of 1111, I'm getting 0100. (I'm only looking at the first 4 bits because I only have 4 LED's.) Can you see where this output is coming from? I thought for a while that the Contact FPGA subroutine was the source of the problem, but I commented it out and jumped over it and am still getting weird stuff. Please help!

The original code and screenshot of the config bits is attached.

Thanks everyone for your time!
 

instruction " movf b'11111111', W"
does not move b'11111111' into WREG
It moves value stored at address b'11111111 to WREG

to load WREG do this:

movlw b'11111111'

George
 

    SamanthaL

    Points: 2
    Helpful Answer Positive Rating
Wow. Thank you! I knew it was something simple like that I wasn't seeing!

So the difference between l and f is the actual literal vs the address? When I'm assigning b'11111111' to Test_Case, b'11111111' is the literal and Test_Case is an address where that literal is stored. Am I understanding that correctly?
 

Yes
when you use code:
cblock Bank0RAM
Test_Count ; Counter variable to see how many test cases have
; been applied
Test_Case ; Test case

you are assiging address to these variables and compilier substitues this address for the variable

If you View Disassembly listing you will see this.

George
 

    SamanthaL

    Points: 2
    Helpful Answer Positive Rating
SamanthaL said:
Wow. Thank you! I knew it was something simple like that I wasn't seeing!

So the difference between l and f is the actual literal vs the address? When I'm assigning b'11111111' to Test_Case, b'11111111' is the literal and Test_Case is an address where that literal is stored. Am I understanding that correctly?

Ok while what you've said here is correct, being apparently new it's hard to tell if you've got it all exactly right so may need a little more..

Say you equate Test_Case to address dec 64. Then you load your b'11111111' there.

So there's decimal 255 in location 64.

It is the instruction that determines how the next item is used, so even if you give it what you meant between the literal or address, it can still come up wrong if you haven't used the correct instruction.

movlw moves a LITERAL into w. It won't care if you've correctly specified an address like you wanted, it will use that address as a literal value instead of getting the value from the address.

IOW you will normally use:

movf Test_Case,w ..........moves the contents of address Test_Case into w
or
movlw b'11111111' .........moves decimal 255 into w, just specified as binary..

BUT these also still work!
movf b'11111111' .........moves the contents of address d255 into W
or
movlw Test_Case .........moves dec 64 that Test_Case equates to into W, not the value at that location.


Make sure you recognize and understand all 4 possibilities. By far the first two are used the most, and will almost always be what you meant to do. 3 and 4 are sometimes used when calculating indexes and indexing into memory arrays or similar, but they are used a lot less often. IOW the last two are almost always a mistake unless you know exactly why you would be using them.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top