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.

Need Help With Pic Simulator Ide

Status
Not open for further replies.

WHO

New Member
hello fellow lovers of micro controllers

i speak as a rookie in the game and i am programing a PIC16f877a.
i am using PIC simulator IDE but if aint looking good for me..
the thing is i have to use this PIC SIMULATOR IDE cause it's a joint project.

if anyone can help me with writting code in C for my project please by all means.

this is how i am starting my code, and if possible, let me know if you can help me fix it up.

the idle state of the project is all pins are logic low, when i hit a panic button (i.e. the pin gets a high) i need another pin to go high...

let me know if my if statements are ok.. thanks ..
and i'll be online a lot in the next week or so.. i would like a mentor...
if you out there.. don't be shy and i'll be glad to hear on wisdom from pros..

thanks
WHO?


// the start of my project looks like this...
i am using pic simulator ide ( basic compiler)


TRISA = 0xff ' INPUT
TRISB = 0x00 ' OUTPUT
TRISC = 0x00 ' OUTPUT
TRISD = 0xff ' INPUT
TRISE = 0x00 ' OUTPUT

' INITIALIZE PORT C AND D AS LOGIC LOW (0)

PORTA = 0xff
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0

' instead of writing the output or input port and pin
' we used a shortcut using SYMBOL and then the name of the PIN


Symbol buzzer = PORTC.1
Symbol sec_center = PORTC.2
Symbol to_voice_1 = PORTC.4
Symbol to_voice_2 = PORTC.5

Symbol panic_1 = PORTD.4
Symbol panic_2 = PORTD.5
Symbol panic_3 = PORTD.6


main:






panic: If panic_1 = 1 Then ' SITUATION FOR PANIC BUTTON 1
sec_center = 1
WaitMs 1000
Endif

If panic_2 = 1 Then ' SITUATION FOR PANIC BUTTON 2
sec_center = 1
WaitMs 1000
to_voice_1 = 1
WaitMs 1000
to_voice_2 = 1
WaitMs 1000
Endif

If panic_3 = 1 Then ' SITUATION FOR PANIC BUTTON 3
buzzer = 1
WaitMs 1000
sec_center = 1
WaitMs 1000
to_voice_1 = 1
to_voice_2 = 1

Endif
Goto panic
 
Your code is not very C like. It looks more like pseudo code. What compiler are you intending to use?

Mike.
 
hey.. thanks for the reply

i am using pic simulator ide to compile ...

can you help me adjust this code..??

let me know..
thanks

who
 
If you haven't already done so I suggest you install MPLAB, it's available free from Microchip. You should also download Hi-Tech Pic C Lite **broken link removed** and install it AFTER you install MPLAB.

You should then look through some of the samples and if you can't follow them then look for a tutorial in C.

Your code in C should look something like,
Code:
#include<pic.h>
#include<htc.h>

__CONFIG(DEBUGEN & WDTDIS & LVPDIS);

#define panic_1 RD4
#define buzzer RC1

void main(){ 
    TRISD=0xff;
    TRISC=0x00;
    while(1){
        if(panic_1==1){
            buzzer=1;
        }else{
            buzzer=0;
        }
    }
}

If this code doesn't make sense to you then you need to learn C.

Mike.
 
Probably ...

Ya,

C is a wonderful language to program microcontrollers...

very easy and very fast...

Well mike...

Did you like those tutorials... I would like to have some comment about those...:eek:

Regards,

Simran..
 
Wel...

Well,

when you see them please tell so that i can recommend them to other people also...

Main thing what is required is easiness with full knowledge...

Regards,

Simran..:)
 
Looks like BASIC

That's because he's using OSHONSOFT picbasic in conjunction with the pic simulator ide from the same place.
I think it's a very good starting place for learning pic hardware and assembly by studying and optimising the generated code.

WHO; to test your code, type it into the basic compiler, hit 'compile assemble and load' from the compiler menu, then click on your input pins in the mcu visualisation to see the effect. you can alter simulation speed down to single step to see how the code works. Couldn't be easier.
 
thanks mokeybiter

i am just starting with this code.. are you experienced in using PIC simulator..
cause i am just learning it and i'd lke to see if you can help me with some basic questions..

let me know..

and i've used the basic compiler, but what i need to know is how to map a DIM to a port.. this is what i have so far...

TRISA = 0xff ' INPUT
TRISB = 0x00 ' OUTPUT
TRISC = 0x00 ' OUTPUT
TRISD = 0xff ' INPUT
TRISE = 0x00 ' OUTPUT

' INITIALIZE PORT C AND D AS LOGIC LOW (0)

PORTA = 0x00
PORTB = 0x00
PORTC = 0x00
PORTD = 0x00
PORTE = 0x00

' instead of writing the output or input port and pin
' we used a shortcut using SYMBOL and then the name of the PIN


Symbol buzzer = PORTC.1
Symbol sec_center = PORTC.2
Symbol to_voice_1 = PORTC.4
Symbol to_voice_2 = PORTC.5



Dim panic_1 As Bit

If panic_1 Then 'SITUATION FOR PANIC BUTTON 1
sec_center = 1
'WaitMs 1000
Endif

see.. for this to work, i would have to set panic_1=1 so that i may enter into the if statement to make sec_center =1 ... but i don't want to do that, i want to map panic_1 to PORTD.4... so that when i compile and simulate.. when i click on pin d4 the led for port c2 will light.. any suggestions??
 
SYMBOL PANIC_1 = PORTD.4

IF PANIC_1 = 1 THEN
SEC_CENTER = 1
'INSERT ANY OTHER CONDITIONAL CODE HERE
ENDIF
'.....................................................


try that
 
Last edited:
that was my first try...

if instead of saying
symbol panic_1 = Portd.4
can i say Dim panic_1 as bit

but then i need to map that bit (panic_1) to portd.4 cause if i want to give
d.4 a high.. i need sec_center to go high also
 
in my previous example, on putting a high signal into portd.4 pin, the pin on portc.2 [sec_center] will output a high.
if you must have an intermediate variable then you can do this:

DIM PANIC_1 AS BIT

PANIC_1 = PORTD.4
IF PANIC_1 = 1 THEN
SEC_CENTER = 1
'ADDITIONAL CODE
ENDIF
 
hey.. i don't know what's wrong with me... i tried just running this little bit of code that you gave me, i can't get it to enter the looop.. it just ain't working .. can you send me something that you done before so that i may run it and see if i can have a different aproach..

WHO?
 
I've added the endless loop. paste this into your basic compiler, compile assemble and load [one menu selection does this] and run it on the simulator, single stepping. use the microcontroller view from the tools menu on the simulator, manipulate d.4 with a mouse click.
failing that, rtfm, load and run the numerous examples that come with the simulator, and when it all fits into place you'll be fine.

DIM PANIC_1 AS BIT
loop:
PANIC_1 = PORTD.4
IF PANIC_1 = 1 THEN
SEC_CENTER = 1
'ADDITIONAL CODE
ENDIF
goto loop
 
it's good

hey monkeybiter

thanks a lot for all the help..

i realized that this PIC simulator IDE isn't so bad to use..
your a good guy for all the replys that you gave me and you i want you
to kow that i won't forget that you helped and i respect you for that..

stay tuned i hope, cause i might need to contact you with other questions if it's good with you..

take it easy

who?
 
using EEPROM

hey

if i am using eeprom and i would like to enter a password for a keypad, then i would like to keep that password and not enter the loop where i initialize the password, can i use this process..

i start by saying read 0,b to enter the loop initialize, then after i enter the password i would like to set b to 1 so the if satement works.. is my process ok

// note that the variable a, b, code were declared as DIM
Read 0, b ''' ENTERING 0 IN VARIABLE B INSIDE EEPROM

If b = 1 Then
'Goto start
Endif

initialize:

WaitMs 300
Lcdcmdout LcdClear
Lcdout "WELCOME TO YOUR HOME"
Lcdcmdout LcdLine2Home
Lcdout "SECURITY SYSTEM"
Lcdcmdout LcdLine3Home
Lcdout " PLEASE ENTER CODE"

For j = 1 To 5 Step 1

If a > 9 Then
buzzer = 1
WaitMs 1000
buzzer = 0
Goto initialize
Else
code = PORTA And %00001111
Write j, a
Lcdcmdout LcdLine4Home
Lcdout #a
Endif

Next j

Write 11, 1
Write 0, 1
 
I've read your posts, but i can't see the problem. When you you use symbol for your panic pins to direct to the d port it has to work correctly. I just don't see the sec_center pin becomes high , then what!!!!. It stayes high forever. If you tell me what you want with it i can help you further.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top