Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2016, 04:39:27 16:39


Login with username, password and session length


Pages: [1]
Print
Author Topic: strange problem with proton Basic [need help]  (Read 3416 times)
0 Members and 1 Guest are viewing this topic.
falcon _bd
V.I.P
Active Member
*****
Offline Offline

Posts: 139

Thank You
-Given: 66
-Receive: 117


falconbd.com


WWW
« on: October 26, 2010, 01:27:51 13:27 »

I cant clear the INTCON.0 (RBIF) bit in interrupt routine .
I am trying to creat the portB change interrupt.
But after the first interrupt program cant  go out from the interrupt routine, because of RBIF bit cant clear.
I have attach the ISIS and Proton file
Logged

bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2403

Thank You
-Given: 405
-Receive: 544


Uhm? where did pickit put my mute button


« Reply #1 on: October 26, 2010, 06:05:41 18:05 »

try this
 
Code:
Device = 16F877A
    Xtal  = 4
LCD_DTPin = PORTD.4        '4 line lcd
LCD_RSPin = PORTD.2        ' RS - RD2
LCD_ENPin = PORTD.3        ' EN - RD3
                           ' D4 - RD4
LCD_Interface = 4        ' D5 - RD5
LCD_Lines = 2              ' D6 - RD6
LCD_Type = 0               ' D7 - RD7
LCD_CommandUs = 2000
LCD_DataUs = 50

    TRISA.0 = 0
    TRISB = 255

    Symbol RBIF = INTCON.0   ' RB Port Interrupt Flag
    Symbol RBIE = INTCON.3   ' RB Port Change Interrupt Enable
    Symbol GIE = INTCON.7    ' Global Interrupt Enable
    Symbol LCD_LIT = PORTD.1
    RBIE = 1   ' Enable interrupt on pins b.4 - b.7
    GIE = 1    ' Enable the Global interrupt ' It is necesary ! ! !
   
    Dim i As Word

On_Hardware_Interrupt GoTo Interrupt_Routine
'On Interrupt GoTo Interrupt_Routine

 PORTD.1= 0   
 
     
 Print At 1,1, "ready to go"   
Main:
    ' Remember if you have a delayms 5000 and press the interrupt button on 2sec then the interrupt
    ' routine will be proceed only when you pass the 5 sec, thats why i use the loop For ... Next with
    ' a small delay.
   
    ' Make a 1 Sec delay         
    For i = 0 To 10
        DelayMS 100
    Next i
 

GoTo Main

Disable
Interrupt_Routine:
    Context Save
    If RBIF = 1 Then
        If PORTB.4 = 1 Then
            Toggle LCD_LIT
            Print At 2,1, "Button up      "
              DelayMS 1000
            Toggle LCD_LIT
        EndIf
   
        If PORTB.5 = 1 Then
            Toggle LCD_LIT
            Print At 2,1, "Button down    "
              DelayMS 1000
            Toggle LCD_LIT
        EndIf
   
        If PORTB.6 = 1 Then
             Toggle LCD_LIT
             Print At 2,1, "Button left    "
               DelayMS 1000
             Toggle LCD_LIT
        EndIf
   
        If PORTB.7 = 1 Then
            Toggle LCD_LIT
            Print At 2,1, "Button right"
              DelayMS 1000
            Toggle LCD_LIT
        EndIf
        RBIF = 0 ' reset the flag
    EndIf
Context Restore   
Return
'Enable
'Resume
Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
oldvan
V.I.P
Senior Member
*****
Offline Offline

Posts: 375

Thank You
-Given: 152
-Receive: 106


If the van is a Rockin'...


WWW
« Reply #2 on: October 27, 2010, 04:15:02 04:15 »

I remember I had a problem that was similar a while ago.  I was working
in C so code won't be helpful, but I needed to first read PORTB then reset
the change interrupt.
Logged

Give a man a fish and you feed him for a day.
Teach a man to fish and he will sit around in a boat drinking beer all day.
Parmin
Hero Member
*****
Offline Offline

Posts: 544

Thank You
-Given: 357
-Receive: 126


Very Wise (and grouchy) Old Man


« Reply #3 on: October 27, 2010, 08:57:28 08:57 »

You got to disable PIE or GIE before you clear RBIF.

Otherwise the interrupt will still be on the last setting, thus RBIF cannot be cleared.
Logged

If I have said something that offends you, please let me know, so I can say it again later.
falcon _bd
V.I.P
Active Member
*****
Offline Offline

Posts: 139

Thank You
-Given: 66
-Receive: 117


falconbd.com


WWW
« Reply #4 on: October 27, 2010, 12:27:18 12:27 »

Thanks bbarney. Your code is working fine. But I should know , whats wrong with my code.

I remember I had a problem that was similar a while ago.  I was working
in C so code won't be helpful, but I needed to first read PORTB then reset
the change interrupt.
oldvan may be right, we should read PORTB first.
Logged

bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2403

Thank You
-Given: 405
-Receive: 544


Uhm? where did pickit put my mute button


« Reply #5 on: October 27, 2010, 06:21:28 18:21 »

Thanks bbarney. Your code is working fine. But I should know , whats wrong with my code.
oldvan may be right, we should read PORTB first.

Code:
If RBIF = 1 Then 
  checks to see if RB Port Interrupt Flag has been set (button press )
do your code in interrupt
Code:
RBIF = 0
  Clear the PortB[4..7] interrupt flag


you just keep turning everything on & off
Code:
INT_R:
   'GIE = 0
 
      LCD_LIT = 1
      btfss RBIE
      RBIF = 0
      While RBIF = 0    ' Make sure they are off
        RBIF = 1         ' Continue to clear GIE
      Wend   
      INTCON = %11001000
      LCD_LIT = 0
      Inc BTN
     'EndIf 

   GIE = 1
Context Restore
« Last Edit: October 27, 2010, 06:41:43 18:41 by bbarney » Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
zuisti
Senior Member
****
Offline Offline

Posts: 371

Thank You
-Given: 219
-Receive: 567


« Reply #6 on: October 28, 2010, 11:14:41 11:14 »

A little explanation for the interrupt-on-change function:
(an extract from the datasheet, see below)

The input pins (of RB7:RB4) are compared with the old value latched on the last read of PORTB
(the bottom latch on the attached figure).
The “mismatch” outputs of RB7:RB4 are OR’ed together to generate the RB Port Change Interrupt
with flag bit RBIF (INTCON<0>).

The user, in the Interrupt Service Routine, can clear the interrupt in the following manner:

a) Any read or write of PORTB. This will end the mismatch condition.
b) Clear flag bit RBIF.

A mismatch condition will continue to set flag bit RBIF. Reading PORTB will end the mismatch
condition and allow flag bit RBIF to be cleared.

Attached the figure 3-4 from this datasheet (PIC16F87X):
http://ww1.microchip.com/downloads/en/devicedoc/30292c.pdf
View chapter 3.2.

A remark:
You don't needed to handle (enable-disable) the global IE bit (GIE).
It's automatic by the HW: at begin of the IT routine it's disabled, and the return (instr. retfie)
enables it.

Hope this helps, too.
zuisti

Logged
bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2403

Thank You
-Given: 405
-Receive: 544


Uhm? where did pickit put my mute button


« Reply #7 on: October 28, 2010, 05:33:18 17:33 »

zuisti
I assumed he read the datasheet and the manual but hey who RTFM  Grin
falcon if you were planning on using wake from sleep using the keys then you would need to add just a couple of things more things to what is already there but it's in the manual so try it first look up the SLEEP command

Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
Parmin
Hero Member
*****
Offline Offline

Posts: 544

Thank You
-Given: 357
-Receive: 126


Very Wise (and grouchy) Old Man


« Reply #8 on: October 29, 2010, 12:14:10 00:14 »

I must have been asleep,
I did not even realise that the GIE switching is automatically performed!!

Oh well, live and learn..
Logged

If I have said something that offends you, please let me know, so I can say it again later.
bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2403

Thank You
-Given: 405
-Receive: 544


Uhm? where did pickit put my mute button


« Reply #9 on: October 29, 2010, 08:24:57 08:24 »

I must have been asleep,
I did not even realise that the GIE switching is automatically performed!!

Oh well, live and learn..
yes it switches but only if you enable it in the first place ( very important Smiley )
but to be safe you can always disable/enable it in software no harm done because you never know what another chip might do and a lot of the examples in the proton manual do it that way , the code I posted above works with it or with out it the same
Put   GIE = 0  at the top of the interrupt routine
and  GIE = 1  at the bottom of it and the code and proteus file run exactly the same as it does without those lines but with it in you know you have made sure it should what it is supposed to do call it insurance  Cheesy

Quote
When an interrupt is responded to, the GIE bit is
cleared to disable any further interrupt, the return
address is pushed onto the stack and the PC is loaded
with 0004h. Once in the Interrupt Service Routine, the
source(s) of the interrupt can be determined by polling
the interrupt flag bits. The interrupt flag bit(s) must be
cleared in software before re-enabling interrupts to
avoid recursive interrupts.
« Last Edit: October 29, 2010, 08:44:31 08:44 by bbarney » Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC