;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
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.
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.
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
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
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**
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
list p=16f84
#include <P16F84.INC>
org 0x00
goto start
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
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
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
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?