PDA

View Full Version : erratic behavior when using MPASM vs. PM



cool_justin
- 7th June 2006, 05:06
Hi,

I've been programming with PBP 2.42 for a while now, but have never had a problem that I couldn't overcome by reading the forums.

Recently, I tried to get Darrel Taylor's great Instant Interrupt program running. I installed MPASM, no problems there. The blink LED program worked great.

In order to incorporate the instant interrupt functionality back into my main code, I had to get that code assembling with MPASM (versus PM) first. I read all about the configuration fuses and am fairly sure I have them set correctly. The code compiles and loads (via MCS loader) into my 16F877a without any issues (the only warnings are the 'page boundary' warnings, which I ignore). However, the code runs very erratically now. The LCDOUT commands don't work, and the timing on my GPIO seems to be much faster.

After playing around with the configuration fuses, they don't seem to change anything. In fact, I can comment them out of my main code (and the 16F877a.inc file) and get the same erratic results.

I went back to Darrel's Interrupt program just to see if I could get my 16x1 LCD working there...no go.

In conclusion, I believe if someone can tell me why the code below doesn't work with my LCD, I will be able to figure out why it doesn't work in my main program. The portb.1 does toggle (as intended), but I get nothing on my LCD. The hardware is connected correctly as the LCD works with my main code compiled with PM. This program is basically Darrel Taylor's blinky program, but with an LCDOUT after the LCD toggle.

Thanks in advance for the help - there are so many talented people who contribute to this forum and I appreciate your time!


LED1 VAR PORTB.1

define osc 20 'using 20 MHz crystal
define loader_used 1 'using a loader...
define lcd_dreg portb 'set LCD data port
define lcd_dbit 4 'set LCD starting Data bit = 4 (portd.4-7)
DEFINE lcd_rsreg portb 'set LCD register select port
define lcd_rsbit 2 'set LCD register select bit
define lcd_ereg portb 'set LCD enable port
define lcd_egreg 3 'set LCD enable bit
define lcd_bits 4 'set LCD bus size (4 or 8 bits)
define lcd_lines 2 'set number of lines on LCD
define lcd_commandus 2000 'set command delay time in us
define lcd_dataus 50 'set data delay time in us

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

T1CON = $31 ; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

Main:
PAUSE 1
GOTO Main

'---[TMR1 - interrupt handler]--------------------------------------------------
ToggleLED1:
TOGGLE LED1
lcdout $FE, $80, "Hi World"
pause 1000
@ INT_RETURN

\code

Bruce
- 7th June 2006, 12:32
Change define lcd_egreg 3 to DEFINE LCD_EBIT 3

cool_justin
- 7th June 2006, 18:18
Bruce,
Thanks for the suggestion. I changed egreg to ebit in my code, and still no luck.

I took the code posted above, commented out the interrupt portion and moved the LCDOUT command to the main loop (since there's no more interrupt), compiled with PM, and no issues. "Hi World" is displayed on my LCD.

After reading the threads by Melanie and others, my understanding is the only difference in assembling between PM and MPASM is the configuration fuses. However, all the combinations of configuration fuses I've tried does not yield good results. Again, the code compiles, assembled, and loads, but no LCDOUT and timing is erratic...

This code is so small, I know there's got to be a fairly simple answer to this issue, I just can't figure it out...

Here is the code that compiled and worked great with PM:




LED1 VAR PORTB.1

define osc 20 'using 20 MHz crystal
define loader_used 1 'using a loader
define lcd_dreg portb 'set LCD data port
define lcd_dbit 4 'set LCD starting Data bit
DEFINE lcd_rsreg portb 'set LCD register select port
define lcd_rsbit 2 'set LCD register select bit
define lcd_ereg portb 'set LCD enable port
'define lcd_egreg 3 'set LCD enable bit
DEFINE LCD_EBIT 3
define lcd_bits 4 'set LCD bus size (4 or 8 bits)
define lcd_lines 2 'set number of lines on LCD
define lcd_commandus 2000 'set command delay time in us
define lcd_dataus 50 'set data delay time in us

'INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
'INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
'
'ASM
'INT_LIST macro ; IntSource, Label, Type, ResetFlag?
' INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
' endm
' INT_CREATE ; Creates the interrupt processor
'ENDASM

'T1CON = $31 ; Prescaler = 8, TMR1ON
'@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

Main:
lcdout $FE, $80, "Hi World"
PAUSE 1
GOTO Main

'---[TMR1 - interrupt handler]--------------------------------------------------
'ToggleLED1:
' TOGGLE LED1
' lcdout $FE, $80, "Hi World"
' pause 1000
'@ INT_RETURN

mister_e
- 7th June 2006, 22:57
Miip.. forget me... i was wrong... i'll read the whole stuff later and i'll be back :(

Bruce
- 8th June 2006, 00:06
Are you loading your code via a boot-loader? If you are, then config fuse
settings embedded in your compiled file shouldn't matter. Config fuses are
fixed in the loader firmware.

If you're programming it in your device programmer, then make sure your
config fuse settings are the same from one version to the next before burning.

cool_justin
- 8th June 2006, 00:26
Thanks Bruce for your suggestions!

I looked again at Darrel Taylor's instant interrupt program (elapsed timer) and tried to look at the differences between code.

It turns out that MPASM was set as 'case sensitive' under MCS view-> PIC Basic Options -> Assembler.

Not all of my define statements were in all caps and apparently something didn't like that. Anyhow, after turning 'case sensitive' to OFF, everything works great! :)

It did give me one warning I hadn't seen before, though:
"pbppic14.lib 3382:Argument out of range. Least significant bits used."

This sounds disturbing - like it is truncating a variable or something somewhere. Is this anything I should be concerned with? Anyone see it before?

Thanks!!
Justin

Bruce
- 8th June 2006, 01:08
Hi Justin,

Open pbppic14.lib and scroll down to line 3382 to see what that section of
the PBP library is. It's different in V2.46. The library has grown a good deal
since V2.42.