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.

Software to Simulate PIC Microcontroller

Status
Not open for further replies.

cadvis

Junior Member level 1
Joined
Jun 11, 2008
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,479
Hi,

Iam trying to simulate pic code ( and many other program) using 'Real pic Simulator' but results are not coiming out as iam expecting. following program is to on and off LED for 5 sec. but software shows only on LED not getting it off after 5 sec. any help?
;Equates

TMR0 equ 01h
STATUS equ 03h
TRISA equ 85h
PORTA equ 05h
OPTION_REG equ 81h
COUNT1 equ 08h
COUNT2 equ 09h

;************************************************* ******************************
bsf 03h,5
movlw b'00000010'
movwf 85h
bcf 03h,5
movlw b'00000111'
movwf 81h
movlw 01h


start:
xorwf 05h
call delay
goto start
call delay

delay:
loopA:
clrf TMR0
movf 01h
sublw .160
btfss 03h,2
goto loopA
retlw 0

end





Secondly Recomend any good pic tutorial Website and code simulation software.
 

Hai,

You can use MIkroC for coding and PIC simulator ide for simulation

In mikroc the above program will be

void main()
{

trisb=0x00;
while(1)
{

portb=0xff;
Delay_ms(5);
portb=0x00;
Delay_ms(5)
}
}
 
Best PIC simulator software I've used is OshonSoft PIC Simulator IDE.

About your problem, try using a different delay subroutine (mainly one that uses GP registers rather than a timer, since your TIMER0 configuration might be an issue).

Google "PIC Delay Generator" and use the first website to generate a subroutine that you can paste in the code.
 

Hi,

Iam trying to simulate pic code ( and many other program) using 'Real pic Simulator' but results are not coiming out as iam expecting. following program is to on and off LED for 5 sec. but software shows only on LED not getting it off after 5 sec. any help?






Secondly Recomend any good pic tutorial Website and code simulation software.

Actually there is no proper delay sub routine in your code. For proper delay sub routines refer the text written by Mazidi by the name 8051 controller & embedded systems. Better search by the author in connection with the text name in the net. It is a nice book for learning & acquiring basic knowledge in assembly language programming for controllers.
So write proper delay to your code & then get it simulated once again. Then check if the same error repeats.
Regards,
Jerin. ;-)
 

Hi
Please find the beautiful Software regarding Pic Delay Code Generator for ASM Programmers made by N Golovchenko. This is a very useful Software for those who make Pic Programming in Assembly Language by saving lot of time and energy for delay calculation. This is an online code generator.

screenshot.jpg


**broken link removed**

There's another one I have that works for PIC10 to PIC18. I'll find it and try to post the link.

As for the simulator, I think Proteus is the best.

Hope this helps.
Tahmid.
 

I think it is better to write the code rather than generating the code for a Delay. But in some critical circumstances we'll have to rely on generators like as mentioned above. Anyway nice work Tahmid. Let it be helpful to all.
Regards,
Jerin. ;-)
 

The MPLAB got the simulator also. MPLAB Sim under debugger. It will show u the logic timing diagram (use logic analyzer) and from there u can debug if the correct outputs are coming out. if u need simulated inputs then u can use the stimulus editor inside the MPLAB Sim.
 

The MPLAB got the simulator also. MPLAB Sim under debugger. It will show u the logic timing diagram (use logic analyzer) and from there u can debug if the correct outputs are coming out. if u need simulated inputs then u can use the stimulus editor inside the MPLAB Sim.

Yeah. But it is no so much user friendly like that in MikroC. Thats the reason by which people find alternatives for the simulation of codes.
Regards,
Jerin. ;-)
 

Thanks to all of you for positive feedback.
I am following the book Pic by Project by Dr W Smith. In this book he gave the code for 5 sec. delay. Iam using "Real Pic Simulator' to simulate it but it does not work properly.

TMR0 equ 1h
PORTA equ 5h
PORTB equ 6h ;PORTB is FILE 6.
STATUS equ 3h ;STATUS is file3.
TRISA equ 85h ;TRISA (the PORTA i/o selection)
TRISB equ 86h ;TRISB (the PORTB i/o selection)
option_r equ 81h ;the option register is file 81h
ZEROBIT equ 2 ;ZEROBIT is bit 2.
COUNT equ 0ch ;user ram location.

;**********************************************************
list p=16f84 ;we are using the 16f84
org 0 ;0 is the start address.
goto start ;goto start!

;**********************************************************
;configuration bits
__config h'3ff0' ;selects lp oscillator, wdt off, put on,
;code protection disabled.
;*****************************************************

;subroutine section.

;5 second delay.
delay5 clrf TMR0 ;start tmr0.
loopA movf TMR0,w ;read tmr0
sublw .160 ;time - 160
btfss STATUS,ZEROBIT ;check time-w¼0
goto loopA ;time is not¼160.
retlw 0 ;time is 160, return.

;**********************************************************
;configuration section.

start bsf STATUS,5 ;turn to bank1
movlw b'00011111' ;5 bits of PORTA are i/ps.
movwf TRISA
movlw b'00000000'
movwf TRISB ;PORTB is output
movlw b'00000111'
movwf option_r ;prescaler is /256
bcf STATUS,5 ;return to bank0
clrf PORTA ;clears PORTA
clrf PORTB ;clears PORTB
clrf COUNT
;*********************************************************

;program starts now.

on btfsc PORTA,0 ;check button pressed.
goto on
bsf PORTB,0 ;turn on led.
call delay5 ;call 5 second delay
bcf PORTB,0 ;turn off led.
goto on ;repeat
end


Regards
 

Thanks to all of you for positive feedback.
I am following the book Pic by Project by Dr W Smith. In this book he gave the code for 5 sec. delay. Iam using "Real Pic Simulator' to simulate it but it does not work properly.




Regards

First of all always intend your code properly in an ordered way so that another person who see the code could understand the where about of the code.
Arrange like this:

TMR0 equ 1h
PORTA equ 5h
PORTB equ 6h ;PORTB is FILE 6.
STATUS equ 3h ;STATUS is file3.
TRISA equ 85h ;TRISA (the PORTA i/o selection)
TRISB equ 86h ;TRISB (the PORTB i/o selection)
option_r equ 81h ;the option register is file 81h
ZEROBIT equ 2 ;ZEROBIT is bit 2.
COUNT equ 0ch ;user ram location.

;************************************************* *********
list p=16f84 ;we are using the 16f84
org 0000H ;0x00 is the start address.
goto start ;goto start!

;************************************************* *********
;configuration bits
__config h'3ff0' ;selects lp oscillator, wdt off, put on,
;code protection disabled.
;************************************************* ****

;subroutine section.

;5 second delay.
delay5:
clrf TMR0 ;start tmr0.
loopA:
movf TMR0,w ;read tmr0
sublw 160 ;time - 160
btfss STATUS,ZEROBIT ;check time-w¼0
goto loopA ;time is not¼160.
retlw 0 ;time is 160, return.

;************************************************* *********
;configuration section.

start:
bsf STATUS,5 ;turn to bank1
movlw b'00011111' ;5 bits of PORTA are i/ps.
movwf TRISA
;movlw b'00000000'
;movwf TRISB ;PORTB is output
CLRF TRISB ;is enough
movlw b'00000111'
movwf option_r ;prescaler is /256
bcf STATUS,5 ;return to bank0
clrf PORTA ;clears PORTA
clrf PORTB ;clears PORTB
clrf COUNT
;************************************************* ********

;program starts now.

on:
btfsc PORTA,0 ;check button pressed.
goto on
bsf PORTB,0 ;turn on led.
call delay5 ;call 5 second delay
bcf PORTB,0 ;turn off led.
goto on ;repeat
end

Now the code has been intended properly. Do have a check now for the code.
Regards,
Jerin. ;-)
 

Thanks for your feedback. I have made some modification to have led on for 5 sec and off for 5sec.

Program is showing strange behaviour while simulating with Real Pic Simulator.

Sending you the MPlab file (*.asm) and rpp file
**broken link removed**

**broken link removed**



Let me know where is the problem. may be real sim not working properly?

Regards
 

What where the strange behaviors you found out with the code?
Regards,
Jerin.
 

Hi,
Are you sure it's LP oscillator and not XT or HS? And are you sure it's 16F84 not 16F84A?

---------- Post added at 16:42 ---------- Previous post was at 15:13 ----------

Hi,
I'll look at the code later, but to start with:
Code:
TMR0 equ 1h
PORTA equ 5h
PORTB equ 6h ;PORTB is FILE 6.
STATUS equ 3h ;STATUS is file3.
TRISA equ 85h ;TRISA (the PORTA i/o selection)
TRISB equ 86h ;TRISB (the PORTB i/o selection)
option_r equ 81h ;the option register is file 81h

is unnecessary.

Where you list the micrcocontroller, do this:
Code:
   list p=16f84
   #include <P16F84.INC>
   org 0x00
   goto start

Now, you can use all of the SFRs in the PIC and don't need to declare them as it's done in the #include statement when the corresponding *.inc file is loaded. Just use them all in caps, like PORTB, TRISB and not portb.

Hope this helps.
Tahmid.

---------- Post added at 16:56 ---------- Previous post was at 16:42 ----------

Hi,
I found a mistake for which probably you aren't getting the 5sec delay when LED is off.
Code:
on:
btfsc PORTA,0 ;check button pressed.
goto on
bsf PORTB,0 ;turn on led.
call delay5 ;call 5 second delay
bcf PORTB,0 ;turn off led.
goto on ;repeat
end
You turned on RB0 and called delay, but after turning it off, you didn't call delay.

It should be:
Code:
on:
btfsc PORTA,0 ;check button pressed.
goto on
bsf PORTB,0 ;turn on led.
call delay5 ;call 5 second delay
bcf PORTB,0 ;turn off led.
call delay5;
goto on ;repeat
end

Hope this helps.
Tahmid.
 

Ya. The absence of routine for delay5 may also alter your code from working perfectly. Try with the change mentioned above cadvis & inform us what the outcome is.
Regards,
Jerin. ;-)
 

hi

Thanks for your feedback. I shall check it down. problem with my code is that while simulting led did not on for 5 sec and off for 5 sec. It took longer to get off.

Thanks once again
 

hi

Thanks for your feedback. I shall check it down. problem with my code is that while simulting led did not on for 5 sec and off for 5 sec. It took longer to get off.

Thanks once again

IF you have written the code for a delay of 5 sec then the compiler is also expected to turn on & off the LEDs at an interval of 5 seconds. If it works more than 5 secs then the code for delay must be wrong.Are you sure about the delay code of 5 seconds? Check that once more mate.....
Regards,
Jerin. ;-)
 

Hi,
If your delay routine is right, the reason for a prolonged delay may be that, your delay code was developed for say 10MHz crystal, but you're using 4MHz crystal, or something similar, ie wrong clock oscillator value.

Hope this helps.
Tahmid.
 

Ya may this can be the problem. As a beginner, i took this sample code from a Dr W. Smith's book ( all the code in his book is tested and verified). Now i am trying to debug it to find out thepossible error.
In programming using LP crystal 32768 hz. PicF84 timing is 1/4 of the crystal i.e. 32768/4 =8192hz. using presacler with value b '00000111' ( to divide it with 256) to have 32 cycle is second. Therefore to have 5 seconds 5*32 = 160 seconds.
problem occurs while simulating the code. That is why i attached actual asm and simulator file to specify where is the problem.

Thanks.
Regards,
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top