Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simulation of PIC C Code...

Status
Not open for further replies.

koolguy

Active Member
HI,

I want to test code whether it will work or not in PIC like simulating the codes....
so, i am using MAP LAB for converting HEX file, i have listen of Proteus ISI but it is not free so can i test the code by any other mean(Software).

Thanks
 
I have programmed the PIC 16F877A with this code:
and PIC was connected as per schematic using 4Mhz the problem is that the LED was not blinking as the output from port B is zero all the time, why??

Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT);


#define _XTAL_FREQ 4000000

void main (void)
{
TRISB=0b00000000;//all pins set as ouput
PORTB=0;
while (1)
 {//endless loop
  PORTB = !PORTB;
  __delay_ms(1000);
 }
}

Code:
hex code 
:060000000A128A11DC2F38
:100FB80083010A128A11E02F831603138601831214
:100FC80003138601E72F83120313860800300319E1
:100FD800013086000630F2001330F100B130F00025
:100FE800F00BF42FF10BF42FF20BF42FFB2FE72F5C
:080FF800E72F0A128A110028FC
:02400E0031FF80
:00000001FF
 
Last edited:
I just compiled the same code... MPLAB 8.83

Code:
:060000000A128A11DC2F38
:100FB80083010A128A11E02F831603138601831214
:100FC80003138601E72F83120313860800300319E1
:100FD800013086000630F2001330F100B130F00025
:100FE800F00BF42FF10BF42FF20BF42FFB2FE72F5C
:080FF800E72F0A128A110028FC
:02400E0031FF80
:00000001FF

No problem here.....
 
That's cool...
so, what will be the problem should i open the outer cover of wire and solder on PCB??
and someone suggest to use PORTB = ~PORTB
 
All the tutorials that I produced were tested to be working... Both simulation and on Nigel's hardware ( otherwise there would be no point posting it )

So I know the code works...

Have you got a scope? to check your oscillator is running?
 
Hi,

I am working further on programming i have modified this code and compiled successfully...
but i want to know will it work any procedure to check??


Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT);


#define _XTAL_FREQ 4000000

void main (void)
{
TRISB=0b00000000;//all pins set as ouput
PORTB=0;
while (1)
 {//endless loop
  PORTB = 0x1;
  __delay_ms(1000);
PORTB = 0x2;
  __delay_ms(1000);
PORTB = 0x4;
  __delay_ms(1000);
PORTB = 0x8;
  __delay_ms(1000);
PORTB = 0xff;
  __delay_ms(1000);


 }
}
 
Ritesh.... Do this..
Code:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT);
 
 
#define _XTAL_FREQ 4000000
 
void main (void)
	{
	TRISB=0b00000000;//all pins set as ouput
	PORTB=0;
	while (1)
		{//endless loop
		PORTB = 0x1;
		NOP(); //__delay_ms(1000);
		PORTB = 0x2;
		NOP(); //__delay_ms(1000);
		PORTB = 0x4;
		NOP(); //__delay_ms(1000);
		PORTB = 0x8;
		NOP(); //__delay_ms(1000);
		PORTB = 0xff;
		NOP(); //__delay_ms(1000);
		}
	}
And run it in the MPLAB sim... The nop's will speed things up a bit.
 
When you software sim... The code takes an age to delay(1000)... so we replace the delay with a nop.. 1 instruction just for sim purposes.

Have you ever simulated the code in MPLAB? Goto the Debugger menu.. Select tool.. option 5 ... MPLAB SIM ..
 
Have you ever simulated the code in MPLAB? Goto the Debugger menu.. Select tool.. option 5 ... MPLAB SIM ..

Not so much aware of it..and only arrow is following can't we get more info from it??
 
Status
Not open for further replies.

Latest threads

Back
Top