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.

Pic Simuator IDE

Status
Not open for further replies.

ktkoota

New Member
hello,
I'm a beginner in using the Pic Simuator IDE ,and I want to ask how can I use 4 switches to control 4 leds on and off.. I mean using the Simulator tools and C program .. I didn't find switches in the tools.. what shall I use?
 
thanks alot, but I'm limitted to use PIC Simulator IDE ,
if I did this:
tools > microcontroller view ..how.. would this be helpful in switching the leds?
 
In the program, there are I/O control registers namely TRISA/TRISB/TRISC that are loaded with the contents of the working register W using movlw and movwf instructions.If a '1' is written in the I/O control register, the respective pin is configured as input(high impedance mode) and if a '0' is written in the I/O control register , the respective pin is configured as output
 
this code is not working,when pressing RB0 RB4 should flash ,RB1 RB5 should flash ,
RB2 RB6 should flash ,RB3 RB7 should flash ,
but nothing isn't working
code:
#include <pic18.h>
#include <config.h>
#include <delay.h>

main(void){

TRISB = 0x0F; //RB4,RB5,RB6 and RB7 are outputs, others inputs

RB4 = 0; // turn LED off
RB5 = 0; // turn LED off
RB6 = 0; // turn LED off
RB7 = 0; // turn LED off

while(1)
{

//if((RB0=1) & (RB1=1) & (RB2=1) & (RB3=1))
//DelayMs(30);

if(!RB0) RB4=1;

else if(!RB1) RB5=1;

else if(!RB2) RB6=1;
else if(!RB3) RB7=1;

//if(!(RB0 & RB1 & RB2 & RB3))
//DelayMs(30);

else
RB4 = 0;
RB5 = 0;
RB6 = 0;
RB7 = 0;

}
}
 
The oshonsoft simulator IDE is basic and 'C' won't work with it. There are plenty of external modules you can use for testing your code too. If you need a hand redo your code in BASIC and maybe I can help you.

Regards Bryan
 
thank you,
now I'm using easypic5 kit and downloading this C code using PICflash..so can anyone help me with this code.. I don't know where is the mistake..
 
Last edited:
Shouldnt your last else have brackets? or the last 3 will always be executed? Actually, since you commented out your "if", this else statement would apply to the "if(!RB0) RB4=1;" so probably not what you want. Always use brackets!!!!
 
This is how it goes....

Hi there,

If you're using PIC Simulator IDE, only BASIC Compiler files (which are *.bas)
can be loaded into the simulator and activated, and BASIC is not hard to learn at all. After installing the simulator, go to start>all programs>PIC Simulator IDE>reference manual, it contains examples of almost everything, including what you're looking for.

Try it out and if you face any problem, come again and ask.

regards.
 
Last edited:
the C code is then converted into hex file through the command prompt.
I really don't know where is the mistake.:confused:
 
this code is not working,when pressing RB0 RB4 should flash ,RB1 RB5 should flash ,
RB2 RB6 should flash ,RB3 RB7 should flash ,
but nothing isn't working
code:
#include <pic18.h>
#include <config.h>
#include <delay.h>

main(void){

TRISB = 0x0F; //RB4,RB5,RB6 and RB7 are outputs, others inputs

RB4 = 0; // turn LED off
RB5 = 0; // turn LED off
RB6 = 0; // turn LED off
RB7 = 0; // turn LED off

while(1)
{

//if((RB0=1) & (RB1=1) & (RB2=1) & (RB3=1))
//DelayMs(30);

if(!RB0) RB4=1;

else if(!RB1) RB5=1;

else if(!RB2) RB6=1;
else if(!RB3) RB7=1;

//if(!(RB0 & RB1 & RB2 & RB3))
//DelayMs(30);

else
RB4 = 0;
RB5 = 0;
RB6 = 0;
RB7 = 0;

}
}

Would you write down in plain english what do you want to accomplish and what PIC,what compiler you're using etc...
 
BASIC = piece of cake...

Hi there,

Maybe the problem is that the simulator does'nt run C files, eventhough they're HEX. I still don't understand why you are not willing to use BASIC, it's very easy straight-through programming, you know.

I'll give you a head start:
'---------------------------
TRISB = 0x0f
Dim i As Bit
i = 1

main:

If RB0 = 1 Then
RB4 = RB4 Xor i
Endif

Goto main

End
'------------------------

this will work in the simulator (press the button on and then switch it off, just like a real switch, so don't keep it pressed on!) and if you press it on again it will turn off.

give it a try!

good luck

regards.
 
Last edited:
I've never used the Oshonsoft simulator but would imagine that it runs a hex file and imports some file for debug information. A bit like MPLAB, it don't care on the language.

My only comment is that birdman0_o had a good suggestion, you need braces around your last else.

Mike.
 
I've never used the Oshonsoft simulator but would imagine that it runs a hex file and imports some file for debug information. A bit like MPLAB, it don't care on the language.

My only comment is that birdman0_o had a good suggestion, you need braces around your last else.

Mike.

My input was probably disregarded :D
 
I am working on a code that is applied that is then written in easypic5 (pi182420) so that if bushbutton is pressed the led must light and if another bushbutton prssed the led ligh no matter if more than one bushbutton are prssed.. pic simulator was giving me wrong initial valus so I am now using MPLAB7 with protus.. so please I need ur tries :(

I put braces and no changes happened..
 
Last edited:
this code is not working,when pressing RB0 RB4 should flash ,RB1 RB5 should flash ,
RB2 RB6 should flash ,RB3 RB7 should flash ,
but nothing isn't working
code:
#include <pic18.h>
#include <config.h>
#include <delay.h>

main(void){

TRISB = 0x0F; //RB4,RB5,RB6 and RB7 are outputs, others inputs

RB4 = 0; // turn LED off
RB5 = 0; // turn LED off
RB6 = 0; // turn LED off
RB7 = 0; // turn LED off

while(1)
{

//if((RB0=1) & (RB1=1) & (RB2=1) & (RB3=1))
//DelayMs(30);

if(!RB0) RB4=1;

else if(!RB1) RB5=1;

else if(!RB2) RB6=1;
else if(!RB3) RB7=1;

//if(!(RB0 & RB1 & RB2 & RB3))
//DelayMs(30);

else
RB4 = 0;
RB5 = 0;
RB6 = 0;
RB7 = 0;

}
}

Have not used C in some time, is there not a missing bracket on the last IF? Maybe a couple. Give this a try.

Code:
#include <pic18.h>
#include <config.h>
#include <delay.h>
 
main(void){
 
 TRISB = 0x0F;  //RB4,RB5,RB6 and RB7 are outputs, others inputs
 
 RB4 = 0; // turn LED off
 RB5 = 0; // turn LED off
 RB6 = 0; // turn LED off
 RB7 = 0; // turn LED off
 
 while(1)
{
 
  //if((RB0=1) & (RB1=1)  & (RB2=1) & (RB3=1)) 
  //DelayMs(30);
 
  if(!RB0) RB4=1;
   else if(!RB1) RB5=1;
   else if(!RB2) RB6=1;
   else if(!RB3)  RB7=1;
 
  //if(!(RB0 & RB1 & RB2 & RB3)) [COLOR=Red]{[/COLOR]
  //DelayMs(30);
 
  [COLOR=Red]}[/COLOR] else [COLOR=Red]{[/COLOR]
  RB4 = 0;
  RB5 = 0;
  RB6 = 0;
  RB7 = 0;
 
  }
}
 
Last edited:
Try Proteus simulator ( student's version is free ). Being limited version there r few PICs in library but enough to play around.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top