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 Simulator IDE problem?

Status
Not open for further replies.

zhaniko93

New Member
Hello
I am working on a project and need to use PIC Simulator IDE (Oshonsoft). In Proteus, Interrupt happens but then goes something wrong (I will correct it myself) but when testing code in Simulator, No interrupt takes place. can any one say why? whats wrong?
Code:
       LIST P=16F628A, R=DEC    ; Use the PIC16F628 and decimal system

        #include "P16F628A.INC"  ; Include header file

        __config  _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF
	errorlevel -302
        CBLOCK 0x20             ; Declare variable addresses starting at 0x20 
           TMP1
           TMP2
           TMP3
           TMP4
        ENDC
; -------------------------------- 
; SET ANALOG/DIGITAL INPUTS PORT A 
; -------------------------------- 
;      
       goto Start
       org 0x004  
     nop
     movwf TMP2
     movfw STATUS
     movwf TMP4
         movfw PORTB   
         movwf TMP3
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         movfw TMP3
         sublw 1
         btfsc STATUS, Z
         call Win_
         movfw TMP3
         sublw 2
         btfsc STATUS, Z
         call Ukan_
         
         movfw TMP4
         movwf STATUS
         movfw TMP2      
        bcf INTCON, RBIF
        retfie

      


Start        movlw 7 
        movwf CMCON             ; CMCON=7 set comperators off 

        bsf INTCON, RBIE
        bsf INTCON, GIE
        bcf INTCON, RBIF
; 
; ---------------- 
; INITIALIZE PORTS 
; ----------------
   BANKSEL   CCP1CON

   movlw b'00111100'
   movwf CCP1CON

   movlw b'00000101' ; TMR2 = on, prescale = 1:4
   movwf T2CON
movlw 0x10
movwf CCPR1L

        movlw b'00000100'       ; RB2(TX)=1 others are 0 
        movwf PORTB

        bsf STATUS,RP0          ; RAM PAGE 1


        movlw 0x00
        movwf TRISA             ; portA all pins input

        movlw b'11110010'       ; RB7-RB4 and RB1(RX)=input, others output 
        movwf TRISB


        bcf STATUS,RP0          ; RAM PAGE 0


   loop 
goto loop



   Ukan_ call Ukan
call Ukan
call Ukan
call Ukan
call Ukan

retlw 0


Win_ call Win
 call Win
 call Win
 call Win
 call Win
retlw 0

   Win 
movf CCPR1L, f
   movlw 1
   btfsc STATUS, Z
   call Mimart_Shecvla ; CCPR1L == 0
 call CritCheck  
   movwf TMP1
 btfss TMP1, 0
    call Winn ; 0-a

   retlw 0


   Ukan  movf CCPR1L, f
   movlw 0
   btfsc STATUS, Z
   call Mimart_Shecvla
 call CritCheck
   movwf TMP1
 btfss TMP1, 0
    call Ukann ; 0-a
   retlw 0



 CritCheck   movfw CCPR1L ;Maximalurs vzomavt jer
   sublw 0xFF
   movlw 0xFE   
   btfsc STATUS, Z
   movwf CCPR1L  ; CCPR1L == 255, CCPR1L = 254
   btfsc STATUS, Z
   retlw 1  ; CCPR1L == 255
   retlw 0
   


   Mimart_Shecvla sublw 0 ;W==1 = Win - - - - W==0 = Ukan
   btfsc STATUS, Z ; Winaa
   bsf PORTB, 0
   btfss STATUS, Z ; Ukanaa
   bcf PORTB, 0
   movlw 1
   movwf CCPR1L
   retlw 0
   
   
 Winn btfss PORTB, 0
 incf CCPR1L
 btfsc PORTB, 0
 decf CCPR1L

 retlw 0

 Ukann btfsc PORTB, 0
 incf CCPR1L
 btfss PORTB, 0
 decf CCPR1L
 retlw 0
  

        END
 
hi Z93
Interrupt On Change on PB7,6,5,4 works every time for me in Oshonsoft.
How are you trying to initiate an Interrupt when using the IDE.??

Tidied up your code.

Code:
    list    P=16F628A,R=DEC    ; Use the PIC16F628 and decimal system

    #include "P16F628A.INC"    ; Include header file

    errorlevel  -302  , -207 


    __config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF
    errorlevel -302
    cblock    0x20        ; Declare variable addresses starting at 0x20 
    TMP1
    TMP2
    TMP3
    TMP4
    endc
; --------------------------------   
; SET ANALOG/DIGITAL INPUTS PORT A   
; --------------------------------   
;      
    org 0x000
    goto    Start

    org    0x004  
ISR:
    nop
    movwf    TMP2
    movfw    STATUS
    movwf    TMP4
    movfw    PORTB   
    movwf    TMP3
    bcf    STATUS, C
    rrf    TMP3, f
    bcf    STATUS, C
    rrf    TMP3, f
    bcf    STATUS, C
    rrf    TMP3, f
    bcf    STATUS, C
    rrf    TMP3, f
    movfw    TMP3
    sublw    1
    btfsc    STATUS, Z
    call    Win_
    movfw    TMP3
    sublw    2
    btfsc    STATUS, Z
    call    Ukan_
         
    movfw    TMP4
    movwf    STATUS
    movfw    TMP2      
    bcf    INTCON, RBIF
    retfie

         
Start:
    movlw    7 
    movwf    CMCON        ; CMCON=7 set comperators off 

    bsf    INTCON, RBIE
    bsf    INTCON, GIE
    bcf    INTCON, RBIF
; 
; ----------------   
; INITIALIZE PORTS   
; ----------------  
    banksel    CCP1CON

    movlw    b'00111100'
    movwf    CCP1CON

    movlw    b'00000101'    ; TMR2 = on, prescale = 1:4
    movwf    T2CON
    movlw    0x10
    movwf    CCPR1L

    movlw    b'00000100'    ; RB2(TX)=1 others are 0 
    movwf    PORTB

    bsf    STATUS,RP0    ; RAM PAGE 1


    movlw    0x00
    movwf    TRISA        ; portA all pins input

    movlw    b'11110010'    ; RB7-RB4 and RB1(RX)=input, others output 
    movwf    TRISB


    bcf    STATUS,RP0    ; RAM PAGE 0


loop:     
    goto    loop



Ukan_:
    call Ukan
    call    Ukan
    call    Ukan
    call    Ukan
    call    Ukan

    retlw    0


Win_:
    call    Win
    call    Win
    call    Win
    call    Win
    call    Win
    retlw    0

Win:     
    movf    CCPR1L, f
    movlw    1
    btfsc    STATUS, Z
    call    Mimart_Shecvla    ; CCPR1L == 0
    call    CritCheck  
    movwf    TMP1
    btfss    TMP1, 0
    call    Winn        ; 0-a

    retlw    0


Ukan:
    movf CCPR1L, f
    movlw    0
    btfsc    STATUS, Z
    call    Mimart_Shecvla
    call    CritCheck
    movwf    TMP1
    btfss    TMP1, 0
    call    Ukann        ; 0-a
    retlw    0



CritCheck:
     movfwCCPR1L    ;Maximalurs vzomavt jer
    sublw    0xFF
    movlw    0xFE   
    btfsc    STATUS, Z
    movwf    CCPR1L        ; CCPR1L == 255, CCPR1L = 254
    btfsc    STATUS, Z
    retlw    1        ; CCPR1L == 255
    retlw    0
         


Mimart_Shecvla:
    sublw0    ;W==1 = Win - - - - W==0 = Ukan
    btfsc    STATUS,Z    ; Winaa
    bsf    PORTB, 0
    btfss    STATUS,Z    ; Ukanaa
    bcf    PORTB, 0
    movlw    1
    movwf    CCPR1L
    retlw    0
         
         
Winn:
    btfss PORTB, 0
    incf    CCPR1L,F
    btfsc    PORTB, 0
    decf    CCPR1L,F

    retlw    0

Ukann:
    btfsc PORTB, 0
    incf    CCPR1L,F
    btfss    PORTB, 0
    decf    CCPR1L,F
    retlw    0
         

    end
 
Last edited:
From tools -> microcontroller view and than turn on one of the RB 7-4 ports. no interrupt happens in your code too. why? try please and you will also see.
and thanks for corrections in code, I'm newbie and am just learning how to write
 
From tools -> microcontroller view and than turn on one of the RB 7-4 ports. no interrupt happens in your code too. why? try please and you will also see.
and thanks for corrections in code, I'm newbie and am just learning how to write

hi,
Use F9 to assemble the code.
Use FILE/LOAD PROGRAM and load the programs hex file.
TOOLS/BREAKPOINT MANAGER , place a breakpoint at the ISR location, see image.

TOOLS/MICRO VIEW to show the PIC layout.

Run the program in Simulation, when you click either PB.7.6.5.4 the program will stop at the Breakpoint and switch to STEP MODE.
Select ULTIMATE and the program will execute the ISR and the goto the LOOP awaiting the next interrupt.
Just keep pressing a PB7 thru 4 pin to stop at the Breakpoint.

You will see it goes to the ISR every time you press a PB7 to 4 pin.

When you have finished testing, clear the breakpoint.

EDIT:
The second image shows the program halted at the breakpoint [ the YELLOW arrow] and the IDE shows an INTERRUPT message.
 

Attachments

  • 000esp02.gif
    000esp02.gif
    21.1 KB · Views: 471
  • 000esp04.gif
    000esp04.gif
    64.4 KB · Views: 482
Last edited:
I did everything you wrote, but when I click RB pins from Micro view, no interrupt happens! I thing that something is wrong with my licence? how can I check it? before that, I had one project which also used interrupts and in IDE, everything was OK, interrupt happened correctly but now it doesnt.... what's wrong?
 
I have v6.65 licenced
 
Take a look a INTCON and other registers... are they set correctly? P.S. I am really very thankful for help, especially to ericgibbs and be80be, thank you very much for your help and happy new year!
 

Attachments

  • untitled1.JPG
    untitled1.JPG
    218 KB · Views: 491
  • untitled2.JPG
    untitled2.JPG
    319.6 KB · Views: 439
Last edited:
hi z93,
That looks OK.
Can you post the dzrava.hex file so that I can run it in Oshonsoft
 
Last edited:
Code:
       LIST P=16F628A, R=DEC    ; Use the PIC16F628 and decimal system

        #include "P16F628A.INC"  ; Include header file

        __config  _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF
	errorlevel -302
        CBLOCK 0x20             ; Declare variable addresses starting at 0x20 
           TMP1
           TMP2
           TMP3
           TMP4
        ENDC
; -------------------------------- 
; SET ANALOG/DIGITAL INPUTS PORT A 
; -------------------------------- 
;      
       goto Start
       org 0x004  
     nop
     movwf TMP2
     movfw STATUS
     movwf TMP4
         movfw PORTB   
         movwf TMP3
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         movfw TMP3
         sublw 1
         btfsc STATUS, Z
         call Win_
         movfw TMP3
         sublw 2
         btfsc STATUS, Z
         call Ukan_
         
         movfw TMP4
         movwf STATUS
         movfw TMP2      
        bcf INTCON, RBIF
        retfie

      


Start        movlw 7 
        movwf CMCON             ; CMCON=7 set comperators off 

        bsf INTCON, RBIE
        bsf INTCON, GIE
        bcf INTCON, RBIF
; 
; ---------------- 
; INITIALIZE PORTS 
; ----------------
   BANKSEL   CCP1CON

   movlw b'00111100'
   movwf CCP1CON

   movlw b'00000101' ; TMR2 = on, prescale = 1:4
   movwf T2CON
movlw 0x10
movwf CCPR1L

        movlw b'00000100'       ; RB2(TX)=1 others are 0 
        movwf PORTB

        bsf STATUS,RP0          ; RAM PAGE 1


        movlw 0x00
        movwf TRISA             ; portA all pins input

        movlw b'11110010'       ; RB7-RB4 and RB1(RX)=input, others output 
        movwf TRISB


        bcf STATUS,RP0          ; RAM PAGE 0


   loop 
goto loop



   Ukan_ call Ukan
call Ukan
call Ukan
call Ukan
call Ukan

retlw 0


Win_ call Win
 call Win
 call Win
 call Win
 call Win
retlw 0

   Win 
movf CCPR1L, f
   movlw 1
   btfsc STATUS, Z
   call Mimart_Shecvla ; CCPR1L == 0
 call CritCheck  
   movwf TMP1
 btfss TMP1, 0
    call Winn ; 0-a

   retlw 0


   Ukan  movf CCPR1L, f
   movlw 0
   btfsc STATUS, Z
   call Mimart_Shecvla
 call CritCheck
   movwf TMP1
 btfss TMP1, 0
    call Ukann ; 0-a
   retlw 0



 CritCheck   movfw CCPR1L ;Maximalurs vzomavt jer
   sublw 0xFF
   movlw 0xFE   
   btfsc STATUS, Z
   movwf CCPR1L  ; CCPR1L == 255, CCPR1L = 254
   btfsc STATUS, Z
   retlw 1  ; CCPR1L == 255
   retlw 0
   


   Mimart_Shecvla sublw 0 ;W==1 = Win - - - - W==0 = Ukan
   btfsc STATUS, Z ; Winaa
   bsf PORTB, 0
   btfss STATUS, Z ; Ukanaa
   bcf PORTB, 0
   movlw 1
   movwf CCPR1L
   retlw 0
   
   
 Winn btfss PORTB, 0
 incf CCPR1L
 btfsc PORTB, 0
 decf CCPR1L

 retlw 0

 Ukann btfsc PORTB, 0
 incf CCPR1L
 btfss PORTB, 0
 decf CCPR1L
 retlw 0
  

        END

Code:
:020000040000FA
:020000001F28B7
:080008000000A1000308A300A1
:100010000608A2000310A20C0310A20C0310A20CED
:100020000310A20C2208013C03193B202208023CC9
:10003000031935202308830021080B10090007301D
:100040009F008B158B170B10831203133C30970006
:100050000530920010309500043086008316003081
:100060008500F2308600831234284A204A204A2034
:100070004A204A2000344120412041204120412093
:1000800000349508013003195A205320A000201C89
:10009000612000349508003003195A205320A00035
:1000A000201C66200034FF3CFE3003199500031924
:1000B0000134003403190614031D061001309500A5
:1000C0000034061C950A0618950300340618950A94
:0600D000061C950300343C
:02400E00503F21
:00000001FF
 
hi,
The program works every time in my PC, there must be a problem in your Oshonsoft installation.???
Copy and paste this into your Oshonsoft, assemble and run.

Code:
  LIST P=16F628A, R=DEC    ; Use the PIC16F628 and decimal system

        #include "P16F628A.INC"  ; Include header file

    errorlevel  -302  , -207 


        __config  _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF
    errorlevel -302
        CBLOCK 0x20             ; Declare variable addresses starting at 0x20 
           TMP1
           TMP2
           TMP3
           TMP4
        ENDC
; -------------------------------- 
; SET ANALOG/DIGITAL INPUTS PORT A 
; -------------------------------- 
;      
       goto Start
       org 0x004  
     nop
     movwf TMP2
     movfw STATUS
     movwf TMP4
         movfw PORTB   
         movwf TMP3
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         bcf STATUS, C
        rrf TMP3, f
         movfw TMP3
         sublw 1
         btfsc STATUS, Z
         call Win_
         movfw TMP3
         sublw 2
         btfsc STATUS, Z
         call Ukan_
         
         movfw TMP4
         movwf STATUS
         movfw TMP2      
        bcf INTCON, RBIF
        retfie

      


Start        movlw 7 
        movwf CMCON             ; CMCON=7 set comperators off 

        bsf INTCON, RBIE
        bsf INTCON, GIE
        bcf INTCON, RBIF
; 
; ---------------- 
; INITIALIZE PORTS 
; ----------------
   BANKSEL   CCP1CON

   movlw b'00111100'
   movwf CCP1CON

   movlw b'00000101' ; TMR2 = on, prescale = 1:4
   movwf T2CON
    movlw 0x10
    movwf CCPR1L

        movlw b'00000100'       ; RB2(TX)=1 others are 0 
        movwf PORTB

        bsf STATUS,RP0          ; RAM PAGE 1


        movlw 0x00
        movwf TRISA             ; portA all pins input

        movlw b'11110010'       ; RB7-RB4 and RB1(RX)=input, others output 
        movwf TRISB


        bcf STATUS,RP0          ; RAM PAGE 0


   loop 
    goto loop



   Ukan_ call Ukan
    call Ukan
    call Ukan
    call Ukan
    call Ukan

    retlw 0


Win_ call Win
 call Win
 call Win
 call Win
 call Win
    retlw 0

   Win 
    movf CCPR1L, f
   movlw 1
   btfsc STATUS, Z
   call Mimart_Shecvla ; CCPR1L == 0
 call CritCheck  
   movwf TMP1
 btfss TMP1, 0
    call Winn ; 0-a

   retlw 0


   Ukan  movf CCPR1L, f
   movlw 0
   btfsc STATUS, Z
   call Mimart_Shecvla
 call CritCheck
   movwf TMP1
 btfss TMP1, 0
    call Ukann ; 0-a
   retlw 0



 CritCheck   movfw CCPR1L ;Maximalurs vzomavt jer
   sublw 0xFF
   movlw 0xFE   
   btfsc STATUS, Z
   movwf CCPR1L  ; CCPR1L == 255, CCPR1L = 254
   btfsc STATUS, Z
   retlw 1  ; CCPR1L == 255
   retlw 0
   


   Mimart_Shecvla sublw 0 ;W==1 = Win - - - - W==0 = Ukan
   btfsc STATUS, Z ; Winaa
   bsf PORTB, 0
   btfss STATUS, Z ; Ukanaa
   bcf PORTB, 0
   movlw 1
   movwf CCPR1L
   retlw 0
   
   
 Winn btfss PORTB, 0
 incf CCPR1L,F
 btfsc PORTB, 0
 decf CCPR1L,F

 retlw 0

 Ukann btfsc PORTB, 0
 incf CCPR1L,F
 btfss PORTB, 0
 decf CCPR1L,F
 retlw 0
  

        END
 
I reinstalled and works fine! seems like the problem was my licence!
 
Thanks eric, you too, happy new year!
 
pls help me am having an issue on my pic simulator ide if i try open it, it will write RUN TIME OUT 339 how do I solve the problem please I need help
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top