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.

[SOLVED] PIC16F1933 MPLABX ASM: simple AND operation driving me crazy

Status
Not open for further replies.

righteous

Full Member level 2
Joined
Nov 29, 2017
Messages
130
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,282
Gents,

My objective is simply to read bits 2:0 on PORTB and AND it with a bit mask, but the AND operation always yields 0x07 regardless of PORTB value. It's just one of those things that makes me stupider the longer I try to solve it. Anyway here's my environment:

MCU: PIC16F1933
Product Version: MPLAB X IDE v4.15
Java: 1.8.0_144; Java HotSpot(TM) 64-Bit Server VM 25.144-b01
Runtime: Java(TM) SE Runtime Environment 1.8.0_144-b01
System: Linux version 4.13.0-36-generic running on amd64; UTF-8; en_US (mplab)
Compiler: mpasm(v5.77)
Currently loaded firmware on PICkit 3
Firmware Suite Version.....01.51.08
Firmware type..............Enhanced Midrange

And here is the code:

Code:
    movlw 0x07		    ; sensor mask, retain only the sensor bits
    andwf PORTB,W	    ; get sensor data, AND it with W and store result in W

I added a watch for WREG in the IDE to monitor W register. But it's always 0x07 regardless of PORTB value, what is wrong here?
 

We need to see more code to be sure but the most likely reason is you have the wrong bank selected. If I'm right, you are probably ANDing 0x07 with something else instead of PORTB. Try adding 'banksel PORTB' between the two existing lines.

Brian.
 

We need to see more code to be sure but the most likely reason is you have the wrong bank selected. If I'm right, you are probably ANDing 0x07 with something else instead of PORTB. Try adding 'banksel PORTB' between the two existing lines.

Brian.

Brian, thank you for your suggestion. Yes I was in the wrong bank, but 'banksel PORTB' did not help. Then some error message in red appeared in the output window telling me that the cable to the PIC was pulled out during execution and that I had to reconnect the USB cable to PICkit3. When I did theat then everything worked.
 

I'm glad it worked, sometimes you go round in circles for ages and miss the obvious every time.
The USB issue sounds like you somehow caused a clash between internally generated signals on PORTB and the clock/data ISCP pins which share the same pins. It would be worthwhile checking the recommendations on how to connect those pins to avoid that happening again.

Brian.
 

Yes, thank you again, I was stareing myself blind on the 'andwf' and knew I had to get a second set of eyes to solve it.

The USB thing, it was very odd though, because I did not touch the cables nor circuit, and the clock/data ISCP pins are only connected to PICkit3. But I gained an experience, and lost a bit of confidence in the IDE "If it works in mysterious ways, then reconnect USB cable"
 

The IDE is 'quirky' but it is only the glue that holds the compiler and assembler packages together. The underlying XC8 and MPASM programs that do the real work are rock solid. I think almost everybody agrees it wasn't a smart move to use Netbeans for the IDE but faced with the need to make MPLABX work in OSX and Linux (which I use) as well as Windows, there wasn't a lot of choice.

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top