Helpful ReplyHot!MPLAB X Ide driving me bonkers

Author
Tim K
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2018/04/26 11:51:20
  • Location: 0
  • Status: offline
2018/04/27 21:27:51 (permalink)
0

MPLAB X Ide driving me bonkers

I whipped up this simple code, that when compiled with MPASM 5.20 direct to a hex file, works just fine. (LED's alternate)  it's in a Velleman 8076 board.  
 
but if I compile the very same code in the IDE and load it via the Pickit3 i have, it loads ok.. but just doesn't run..
am I Missing somthing really obvious here?
 
#include P16F628A.INC
 __CONFIG _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _XT_OSC
   code
COUNT1 EQU H'20' ;Used in delay routine
COUNT2 EQU H'21' ; " " "
  
RESET MOVLW B'00000111' ;Disable Comparator module's
  MOVWF CMCON
  ;
  BSF STATUS,RP0 ;Switch to register bank 1
     
  MOVLW B'11010111' ;Set PIC options (See datasheet).
  MOVWF OPTION_REG ;Write the OPTION register.
  ;


  CLRF INTCON ;Disable interrupts
  MOVLW B'11000000'
  MOVWF TRISB ;RB7 & RB6 are inputs.
  BCF STATUS,RP0

;****Turn the LED on****

Start movlw 07h ;Turn the LEDs on by first putting
  movwf PORTB ;it into the w register and then ;on the port

;****Start of the delay loop 1****

Loop1 decfsz COUNT1,1 ;Subtract 1 from 255
  goto Loop1 ;If COUNT is zero, carry on.
  decfsz COUNT2,1 ;Subtract 1 from 255
  goto Loop1 ;Go back to the start of our loop. ;This delay counts goto from
  ;255 to zero, 255 times

;****Delay finished, now f;iop
  swapf PORTB,1 ;it into the w register and then on ;the port

;****Add another delay****

Loop2 decfsz COUNT1,1 ;This second loop keeps the
  goto Loop2 ;LED turned off long enough for
  decfsz COUNT2,1 ;us to see it turned off
  goto Loop2 ;

;****Now go back to the start of the program

  goto Start ;go back to Start and turn LED ;on again

;****End of the program****

  end ;Needed by some compilers,

#1
Danno
Super Member
  • Total Posts : 212
  • Reward points : 0
  • Joined: 2005/09/07 10:12:10
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/02 16:45:15 (permalink)
0
MCLRE is ON.  Do you have a pullup on /MCLR?
#2
Tim K
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2018/04/26 11:51:20
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/14 20:13:42 (permalink)
0
I didn't have a pull up at the time... but I do now.. and still no go.  the PIC just won't do anything when programmed via MPLABx but will work fine if I use MPASM and the IPE
 
#3
Tim K
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2018/04/26 11:51:20
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/14 20:31:57 (permalink)
0
update.. I'm having the same problem with a pic16f1508 in my own board using a PickIt3 and ICSP
 
#4
qɥb
Monolothic Member
  • Total Posts : 3329
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/15 13:52:38 (permalink)
5 (1)
The config words for the PIC16F628A specify an "XT" oscillator.
i.e. an external crystal. Do you have one?
The big difference between MPLAB and MPLABX is that MPLAB can override the CONFIG settings with something else, MPLABX only uses what is on your code.
 
What config settings did you use with the PIC16F1508?

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#5
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2645
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 05:36:41 (permalink)
0
Use the exclusive or instruction on the output port instead of swapping the nibbles.
(The other pins may be in use)
init
movlw 0x10 ;4 on, 1 off
movwf PORTA
...
movlw 0x12
xorwf  PORTA,1
 
leds
10
01
10
01

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#6
PStechPaul
Super Member
  • Total Posts : 2039
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 14:39:56 (permalink)
0
The source code has an extra quote (") in the COUNT2 definition, so the remaining code shows in green, perhaps meaning that it is interpreted as a string literal and not code.
 
movlw 0x12
xorwf  PORTA,1

 
That might cause the infamous RMW problem. Better to use a shadow register and only perform full byte writes to ports.

 
#7
qɥb
Monolothic Member
  • Total Posts : 3329
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 15:05:23 (permalink)
0
PStechPaul
The source code has an extra quote (") in the COUNT2 definition, so the remaining code shows in green, perhaps meaning that it is interpreted as a string literal and not code.


The highlighting assumes C, not assembler, so it doesn't know that is a comment.
Try this version ( removed an errant apostrophe as well) :)

#include P16F628A.INC
 __CONFIG _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _XT_OSC
   code
COUNT1 EQU H'20' ;Used in delay routine
COUNT2 EQU H'21' ; " " " "
 
RESET MOVLW B'00000111' ;Disable Comparator modules
  MOVWF CMCON
  ;
  BSF STATUS,RP0 ;Switch to register bank 1
     
  MOVLW B'11010111' ;Set PIC options (See datasheet).
  MOVWF OPTION_REG ;Write the OPTION register.
  ;


  CLRF INTCON ;Disable interrupts
  MOVLW B'11000000'
  MOVWF TRISB ;RB7 & RB6 are inputs.
  BCF STATUS,RP0

;****Turn the LED on****

Start movlw 07h ;Turn the LEDs on by first putting
  movwf PORTB ;it into the w register and then ;on the port

;****Start of the delay loop 1****

Loop1 decfsz COUNT1,1 ;Subtract 1 from 255
  goto Loop1 ;If COUNT is zero, carry on.
  decfsz COUNT2,1 ;Subtract 1 from 255
  goto Loop1 ;Go back to the start of our loop. ;This delay counts goto from
  ;255 to zero, 255 times

;****Delay finished, now f;iop
  swapf PORTB,1 ;it into the w register and then on ;the port

;****Add another delay****

Loop2 decfsz COUNT1,1 ;This second loop keeps the
  goto Loop2 ;LED turned off long enough for
  decfsz COUNT2,1 ;us to see it turned off
  goto Loop2 ;

;****Now go back to the start of the program

  goto Start ;go back to Start and turn LED ;on again

;****End of the program****

  end ;Needed by some compilers,

post edited by qɥb - 2018/05/16 15:06:42

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#8
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2645
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 15:12:39 (permalink)
0
This would fix RMW
movf PORTA,0
xorlw 0x12
movwf PORTA


MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#9
qɥb
Monolothic Member
  • Total Posts : 3329
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 15:15:15 (permalink)
0
movf PORTA,0
xorlw 0x12
movwf PORTA

is functionally no different to
movlw 0x12
xorwf  PORTA,1

If a pin is in analog mode, or overloaded, then it will still fail.
Only a true shadow register will avoid that.
 
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#10
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2645
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 15:25:23 (permalink)
0
Same thing but I just did because of what Paul said.
 
What shadow registers are available on this chip?
I haven't done any 8bit asm for quite a while.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#11
qɥb
Monolothic Member
  • Total Posts : 3329
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 15:29:44 (permalink)
0
A "Shadow register" is just any general purpose RAM location you maintain yourself to save what should be output by the port.
You manipulate bits in the "shadow register" and then copy it to the PORT, so you NEVER do a read from the PORT register.
i.e. this is a software technique, not a hardware feature of the PIC.
The hardware version is a LAT register, which is exactly what they added in the "enhanced" 8 bit parts that are available now.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#12
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2645
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 15:33:50 (permalink)
0
It's ok.
BSRS
WS
STATUSS
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#13
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2645
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 15:43:36 (permalink)
0
Yeah I know the technique.
When you said shadow registers I thought you meant the actual shadow registers that are also supported in 16bit asm.
 
I'm used to 16bit asm, the last piece code I wrote was a gfx flood-fill function - 59 instructions.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#14
1and0
Access is Denied
  • Total Posts : 8396
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 16:12:25 (permalink) ☄ Helpfulby Tim K 2018/05/16 17:19:31
0
Replace
   code

with
   code 0x0000

or else you'll get two RETLW instructions from the .cinit at the reset vector. ;)
 
#15
Tim K
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2018/04/26 11:51:20
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 16:24:33 (permalink)
0
What is 'RMW' ?
 
#16
1and0
Access is Denied
  • Total Posts : 8396
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 16:26:21 (permalink)
0
KC8OYE
What is 'RMW' ?
 

Read-Modify-Write.  Read this http://www.microchip.com/forums/m478014.aspx
#17
qɥb
Monolothic Member
  • Total Posts : 3329
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 16:28:38 (permalink) ☄ Helpfulby Tim K 2018/05/16 17:19:15
0
KC8OYE
What is 'RMW' ?

read-modify-write
Usually used to describe how the BSF and BCF instructions work on PORT registers.
i.e. they READ the entire port, MODIFY one bit, the WRITE the whole port.
This can lead to unexpected results if the value read from the PORT is not the same as what was last written.
i.e. pins other than the one addressed might change.
 
That can happen if:
  • Some of the pins are in analog mode
  • Some of the pins are still changing from a recent write (can take multiple instructions if there is significant capacitance on the pin)
  • Some of the pins have a high current load. e.g. an LED with a small series resistor, taking tens of milliamps.
 
post edited by qɥb - 2018/05/16 16:29:43

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#18
Tim K
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2018/04/26 11:51:20
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 16:31:08 (permalink)
0
looks like the code 0x0000 was the problem.
it's blinking like it should now.
 
 
#19
Tim K
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2018/04/26 11:51:20
  • Location: 0
  • Status: offline
Re: MPLAB X Ide driving me bonkers 2018/05/16 17:22:26 (permalink)
0
qɥb
The config words for the PIC16F628A specify an "XT" oscillator.
i.e. an external crystal. Do you have one?
The big difference between MPLAB and MPLABX is that MPLAB can override the CONFIG settings with something else, MPLABX only uses what is on your code.
 
What config settings did you use with the PIC16F1508?


in the Velleman board with the 16f627/8 pics I was using an XT osc.. in my own board, this particular application with the 16f1508 I needed all of the i/o pins so I'm using the INTOSC for now.
#20
Jump to:
© 2018 APG vNext Commercial Version 4.5