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.

Problem with OSHONsoft pic18f simulator

Status
Not open for further replies.

sathiya.ks@tekbridge.in

Newbie level 6
Joined
Sep 15, 2010
Messages
12
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,389
hello all,

As a part of my project I am using 16X2 LCD interfaced with pic18f2220. I wrote the code asusual and simulated in MPLAB simulator. It works fine. But, when I load the HEX file in the OSHONsoft pic18f simulator, it says STACK UNDERFLOW and stops.

When I dig the code and what I found was, the parameters are not passing properly to functions. I didnot check the code in the hardware, but confused with this error. Even I loaded the existing code for LCD in C18 compiler.. same error.

can anyone help..?

any suggestion will be appreciated... :-|
 

Can you post the HEX file and I can run it on my simulator
 

thanx Colbhaidh for your reply..
i m uploading the hex file as wel as my c file.
it works on the MPLAB simulator but not in the pic18f sim.



I cannot upload these files as attachments. I m pasting it below.


file name : lcd.c
MCU: pic18f2220

# include <p18f2221.h>
# include <string.h>

# define lcd_line LATB
# define en LATCbits.LATC4
# define rs LATCbits.LATC5

# define message "SATHYA"


void init_lcd(void);
void init_ports(void);
void cmd(unsigned char cmmd);
void print_letter(unsigned char data);
void delay(void);
void print_str(unsigned char *str);

void init_ports(void)
{
TRISB = 0X00;
TRISC = 0X00;

ADCON1bits.PCFG0 = 1;
ADCON1bits.PCFG1 = 1;
ADCON1bits.PCFG2 = 1;
ADCON1bits.PCFG3 = 1;
}

void init_lcd(void)
{
cmd(0X38);
cmd(0X06);
cmd(0X0F);
cmd(0X01);
}


void cmd(unsigned char cmmd)
{
rs = 0;
lcd_line = cmmd;
en = 1;
delay();
en = 0;
}

void print_letter(unsigned char data)
{
rs = 1;
lcd_line = data;
en = 1;
delay();
en = 0;
}

void delay(void)
{
int i;
for(i=0;i<250;i++);
}

void print_str(unsigned char *str)
{
while(*str!='\0')
{
print_letter(*str);
str = str+1;
}
}

void main()
{
char msg[10] = message;

init_ports();
init_lcd();

print_str(msg);

while(1);
}





I don kno whethe it wil work or not...
bt Im pasting the hex file..
copy it into a notepad and save it as ".hex" pls..




:020000040000FA
:0600000017EF01F01200F1
:020006000000F8
:08000800936A946AC180C18271
:10001000C184C1861200380EE66E0ED8E552060E77
:10002000E66E0AD8E5520F0EE66E06D8E552010ECE
:10003000E66E02D8E5521200D9CFE6FFE1CFD9FF34
:100040008B9AFE0EDB508A6E8B8814D88B98E55203
:10005000E7CFD9FF1200D9CFE6FFE1CFD9FF8B8AD6
:10006000FE0EDB508A6E8B8805D88B98E552E7CF61
:10007000D9FF1200D9CFE6FFE1CFD9FF020EE1266A
:10008000DE6ADD6ADECF02F0DDCF03F0D8900350E8
:1000900004E6FA0E025C000E035805E2DF2A010EA8
:1000A00001E3DB2AEFD7020EE15C02E2E16AE552EE
:1000B000E16EE552E7CFD9FF1200D9CFE6FFE1CFDD
:1000C000D9FFFD0EDBCFE9FFFE0EDBCFEAFFEF50DD
:1000D0001DE0FD0EDBCFE9FFFE0EDBCFEAFFEF50A8
:1000E000E66EB9DFE552010EE76EFD0EDBCF02F0E2
:1000F000FE0EDBCF03F0E7500226000E0322FD0EBA
:1001000002C0DBFFFE0E03C0DBFFDBD7E552E7CF0B
:10011000D9FF1200D9CFE6FFE1CFD9FF0A0EE126C1
:10012000D9CFE9FFDACFEAFF530EEE6E410EEE6E45
:10013000540EEE6E480EEE6E590EEE6E410EEE6EE1
:10014000EE6AEE6AEE6AEE6A5FDF65DFD9CFE6FF40
:10015000DACFE6FFB2DFE552E552FFD70A0EE15CE7
:1001600002E2E16AE552E16EE552E7CFD9FF120003
:10017000060EF66E000EF76E000EF86E0001090016
:10018000F550856F0900F550866F03E1856701D052
:100190003DD00900F550806F0900F550816F0900CE
:1001A000F550826F09000900F550E96E0900F5501D
:1001B000EA6E090009000900F550836F0900F55047
:1001C000846F09000900F6CF87F0F7CF88F0F8CFE9
:1001D00089F080C0F6FF81C0F7FF82C0F8FF000100
:1001E000835302E1845307E00900F550EE6E830764
:1001F000F8E28407F9D787C0F6FF88C0F7FF89C007
:0E020000F8FF00018507000E865BBFD71200D5
:02020E00000EE0
:10021000F36E00EE00F0020E01D81200EA6002D088
:0E022000EE6AFCD7F350E9601200EE6AFCD7DC
:02022E0011EECF
:1002300000F021EE00F0F86A019CB8EC00F025EC2B
:0A02400001F08AEC00F0FBD7120079
:02024A001200A0
:00000001FF
 

I loaded the HEX file and just ran it on the ONSOFT simulator and it did not give any errors.
I am using the PIC18 Simulator IDE v2.73. I will try run with the ONSOFT LCD simulator but so far, no errors....

---------- Post added at 17:28 ---------- Previous post was at 16:20 ----------

There is a problem around the c code:


void main()
{
char msg[10] = message;

init_ports();
init_lcd();

print_str(msg);

while(1);
}



void print_str(unsigned char *str)
{
while(*str!='\0')
{
print_letter(*str);
str = str+1;
}
}


I only program in assembler, not C, but the disassembly of the above code is wrong.
print_str(msg); in main is passing the wrong memory location for msg to the print_str subroutine.
Can you change the C code to :

void main()
{
unsigned char msg[10] = message;

init_ports();
init_lcd();

print_str(msg);

while(1);
}

and try that.
 

thnk u Colbhaidh..
i tried that prog in other compilers..
it worked...
i think this is the issue over c18 compiler that doesnt work...
sorry 4 d late reply...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top