Jump to content
Sign in to follow this  
c58_4311

Function Not Returning The Expected Value

Recommended Posts

Dear Dave,

 

I have written a programe in boostbasic that typically use the lcd, i2c routines. A point is reached when using even a single variable more, that has been defined previously creates a problem.

 

 

At this point if I reffer any variable in the main() like, o2 = 0, then the i2c_readbyte() function declared in the include file 877i2cbas.h, gives out nothing. And if I remove this variable refrence, I again get the correct value from the function.

 

Is it like that I am running out of stack or something like that? But in the compilation process everything seems to be correct.

 

 

The complete code is given here for your reference

 

 

 

#pragma CLOCK_FREQ 4000000

 

#include <877lcdbas.h>

#include <877i2cbas.h>

 

 

'************* variable declaration *****************

Dim a1 as byte

Dim b1 as byte

Dim c1 as byte

Dim d1 as byte

Dim e1 as byte

Dim f1 as byte

Dim g1 as byte

Dim h1 as byte

Dim i1 as byte

Dim j1 as byte

Dim k1 as byte

Dim l1 as byte

Dim m1 as byte

Dim n1 as byte

Dim o1 as byte

Dim p1 as byte

Dim q1 as byte

Dim r1 as byte

Dim s1 as byte

Dim t1 as byte

Dim u1 as byte

Dim v1 as byte

Dim w1 as byte

Dim x1 as byte

Dim y1 as char

 

Dim z1 as integer

Dim a2 as integer

Dim b2 as integer

Dim c2 as integer

 

Dim d2 as long

Dim e2 as long

Dim f2 as long

Dim g2 as long

Dim h2 as long

Dim i2 as long

Dim j2 as long

Dim k2 as long

Dim l2 as long

Dim m2 as long

Dim n2 as long

Dim o2 as long

 

Dim p2 as word

Dim q2 as word

Dim r2 as word

 

Dim s2(8) as byte

Dim t2(8) as byte

Dim u2(2) as byte

Dim v2(3) as byte

Dim w2(6) as byte

Dim x2(6) as byte

Dim y2(16) as byte

'************ variable declaration ends*****************

 

 

 

'******************* interrupt routines ********************

sub interrupt()

 

if ((pir1 & 0x01) <> 0) then

pir1.TMR1IF = 0 'clear the tmr1 overflow flag

tmr1l = 0

tmr1h = 11

tmr1l = 220

p2 = p2 + 1

end if

 

if (intcon & 0x02) <> 0 then

intcon.INTF = 0 'clear the RB0 flag bit

b1 = 1

end if

 

end sub

'******************** interrupt routines ends *********************

 

 

 

Sub main()

Dim temp_local as byte

 

 

call lcd_init() 'Initialize the LCD to appropriate format

call i2c_init() 'Initialize the i2c software routines

call lcd_clear() 'Clears the LCD

 

call lcd_putch(call i2c_read_random(3))

call lcd_putch(call i2c_read_random(4))

call lcd_putch(call i2c_read_random(5))

call lcd_putch(call i2c_read_random(6))

call lcd_putch(call i2c_read_random(7))

 

a1 = 0

b1 = 0

c1 = 0

d1 = 0

e1 = 0

f1 = 0

g1 = 0

h1 = 0

i1 = 0

j1 = 0

k1 = 0

l1 = 0

m1 = 0

n1 = 0

o1 = 0

p1 = 0

q1 = 0

r1 = 0

s1 = 0

t1 = 0

u1 = 0

v1 = 0

w1 = 0

x1 = 0

y1 = 0

 

z1 = 0

a2 = 0

b2 = 0

c2 = 0

 

d2 = 0

e2 = 0

f2 = 0

g2 = 0

h2 = 0

i2 = 0

j2 = 0

k2 = 0

l2 = 0

m2 = 0

n2 = 0 'adding any variable after this causes problem

 

o2 = 0

 

 

Do while 1

Loop

 

 

End Sub

 

 

 

 

 

___________________________________________________________________

just adding any variable makes the i2c_readbyte() function not to return anything

 

o2 = 0

 

 

Memory Usage Report

===================

RAM available:368 bytes, used:99 bytes (27.0%), free:269 bytes (73.0%),

Heap size:269 bytes, Heap max single alloc:95 bytes

ROM available:8192 words, used:432 words (5.3%), free:7760 words (94.7%)

 

 

Successful

Done

 

 

____________________________________________________________________

here if we comment out the following line like

 

'o2 = 0

 

then the i2c_readbyte() function returns the correct value

 

 

 

Memory Usage Report

===================

RAM available:368 bytes, used:95 bytes (25.9%), free:273 bytes (74.1%),

Heap size:272 bytes, Heap max single alloc:95 bytes

ROM available:8192 words, used:420 words (5.2%), free:7772 words (94.8%)

 

 

Successful

Done

Share this post


Link to post
Share on other sites

c58_4311,

 

This is my guess as to what is wrong:

In some of your functions you add bank switching manually. This is not necessary, because linker adds an required bankswitching.

 

In fact this is very bad, because linker is not quite intelligent enough to track manual banks switching. So what happens is the code ends up with the wrong banks selected when writing to some vars, so the data goes into the wrong location.

 

This problem probably only came to light when you use so many variables that some of them ended up in a different bank to before.

 

Take your manual bank switching out and I think you will find everything works as expected ;)

To find the bank switch, search all your files for "status".

 

Regards

Dave

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×