Procedures and Modules

General discussion on mikroBasic.
Post Reply
Author
Message
SBA
Posts: 73
Joined: 10 Jan 2005 23:16
Location: Virginia

Procedures and Modules

#1 Post by SBA » 13 Jan 2005 22:38

Ok, now that I know the signal need to be inverted on a Serial LCD to work off the chip, here is my next question.......

I created a sub procedure to clear the LCD, but when i run it , the pic hangs. Now if i put the code in with out making it a procedure it works. This is the same when i make it a module. code below

Does not work....
program CountIt
include "Blnk.pbas"
dim sup1 as byte
dim sil1 as string[20]
const Brate = 2400 'Baud-rate for LCD 2400 or 9600

'signal out needs to be inverted for lcd to work
main:
Blnk_LCD
'send command for lcd clear, then prints out sil1
Delay_ms(1000)
sil1=" ***STARTING***"
Delay_ms(1000)
Soft_Uart_Init(PortA,0,1,Brate)
for sup1=1 to length(sil1)
Soft_Uart_Write(sil1[sup1])
next sup1

end.

Module:
module Blnk
sub procedure Blnk_LCD
delay_ms(1000)
Soft_Uart_Init(PortA,0,1,Brate)
delay_ms(10)
Soft_Uart_Write(254)
Delay_ms(10)
Soft_Uart_Write(1)
delay_ms(10)
end sub
end.


Now if i do this, it works (see next code segment)
works

program CountIt

dim sup1 as byte
dim sil1 as string[20]
const Brate = 2400 'Baud-rate for LCD 2400 or 9600

'signal out needs to be inverted for lcd to work
main:
delay_ms(1000)
Soft_Uart_Init(PortA,0,1,Brate)
delay_ms(10)
Soft_Uart_Write(254)
Delay_ms(10)
Soft_Uart_Write(1)
delay_ms(10)
'send command for lcd clear, then prints out sil1
Delay_ms(1000)
sil1=" ***STARTING***"
Delay_ms(1000)
Soft_Uart_Init(PortA,0,1,Brate)
for sup1=1 to length(sil1)
Soft_Uart_Write(sil1[sup1])
next sup1

end.

I have trird it without using Brate and having 2400 there as well.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

#2 Post by LGR » 13 Jan 2005 22:56

mE is going to have to answer the question for sure, but I suspect that you are overflowing the stack. Procedure calls always use one stack register, and the library routines have their own internal calls. All you have to work with on the 16F series is 8. Not a conducive environment for structured programming.

If you have an 18F chip handy, you might want to see if it works. They have 32 stack registers.

SBA
Posts: 73
Joined: 10 Jan 2005 23:16
Location: Virginia

#3 Post by SBA » 13 Jan 2005 23:00

Wish i did, i have 35+ 16F84a , 10 16F873, 1 16F877, 29 12F805
No 18F chips, guess I'll have to get some.

SBA
Posts: 73
Joined: 10 Jan 2005 23:16
Location: Virginia

#4 Post by SBA » 13 Jan 2005 23:16

LGR
You are right, just complied it with a 18F and looked at the stats

On the 16F it overlaps, but not on the 18F, so i assume from that, that it would run ao an 18F. Oh well, guess ihave to do it the one file route :roll:

Post Reply

Return to “mikroBasic General”