Other ports use for interrupt


Today 08:45
Forum: The Lounge
Starter: normnet
Views: 0
Replies: 2
Yesterday 15:38
Forum: Proton Plus Compiler v3
Starter: gdesantis
Views: 0
Replies: 4
+ Reply to Thread
Results 1 to 4 of 4

Thread: Other ports use for interrupt306 days old

  1. #1
    19roland70
    Guest 19roland70's Avatar

    0 Not allowed!

    Default Other ports use for interrupt

    I have an electronic circuit with 3 pushbuttons and a display.
    I would replace the pushbuttons for an Rotary encoder.
    My problem is that the ports B.0 and B.1 are already in use and I can't change the pcb
    below a part of the program.
    Code:
    Device = 16F628A   
    Config XT_OSC , WDT_OFF, PWRTE_ON, LVP_OFF, BODEN_OFF, MCLRE_OFF
      
    All_Digital TRUE              ;Alle ingangen digitaal  
    Xtal 4
    '---------------------------LCD--------------------------------  
    Declare  LCD_DTPin = PORTB.0
    Declare     LCD_RSPin = PORTB.4
    Declare  LCD_ENPin = PORTA.3
    Declare  LCD_Interface = 4  '4-bit Interface
    Declare  LCD_Lines = 2
    Declare  LCD_Type = ALPHA
    Symbol SDA = PORTA.1           'I2C op poort a1   
    Symbol SCL = PORTA.0           'I2C op poort a0
    Symbol LED = PORTA.2           'ledverl. op poort a2
    Symbol ToetsHoger = PORTB.7
    Symbol ToetsLager = PORTB.5 
    Symbol ToetsSet = PORTB.6 
    Dim FREQ_step As Word           'Frequency step
    Dim FREQ_khz As Word            'Frequency Khz
    Dim FREQ_mhz As Word            'Frequency Mhz
    Dim FREQ As Word
    Dim TSA_Uitlezen As Word
    Dim ADRESS As Byte              'TSA5511 i2c adres
    Dim LO As FREQ.LowByte
    Dim HI As FREQ.HighByte
    EData 2160,2160,2160
    PORTA = %00000000               ;PORTA uitgangen bij opstart een laag niveau
    TRISA = %11111011               ;PORTA.2 is een uitgang voor de LED
    PORTB = %00000000               ;PORTB uitgangen bij opstart een laag niveau
    TRISB = %11111111               ;PORTB. is een uitgang voor de LED    
     
    Cls
    lus:
    High LED
    Print At 1,1, "FM Test"
    Print At 2,1, "W 7 testset"
    DelayMS 1000
    ADRESS = $C2                    'TSA5511 in adres
    FREQ_step = ERead 02            'geheugen lezen voor frequentie in EData
    If FREQ_step > 0 Then TSA
    '-----------------------------------------------------
    Freq_set:
    FREQ = FREQ_step
    I2COut SDA,SCL,ADRESS,[HI,LO,$8F,$10]        '$8F varicap drive uit 
    FREQ_khz = (FREQ_step*10/2)//100
    FREQ_mhz = (FREQ_step*10/2)/100
     
    Print At 1,1, "Set FM"
    Print At 2,1,  Dec FREQ_mhz, ",", Dec FREQ_khz
    DelayMS 200
    If ToetsHoger = 1 Then Freq_up
    If ToetsLager = 1 Then Freq_down
    If ToetsSet = 1 Then Freq_save
    GoTo Freq_set
    
    '-----------------------------------------UP_freq----------------------------
    Freq_up:
    FREQ_step = FREQ_step + 1 'step 5
    If FREQ_step > 2160 Then FREQ_step = 1750
    GoTo Freq_set
    '----------------------------------------DOWN_freq--------------------------
    Freq_down:
    FREQ_step = FREQ_step - 1 'step 5
    If FREQ_step < 1750 Then FREQ_step = 2160
    GoTo Freq_set
    '--------------------------data opslaan---------------------------
    Freq_save:
    EWrite 02, [FREQ_step]
    DelayMS 50
    How can I change this ,so I can Use an Rotary encoder.

  2. #2
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    413
    Thumbs Up
    Received: 29
    Given: 5
    Total Downloaded
    2.11 GB

    0 Not allowed!

    Default Re: Other ports use for interrupt

    How about using a Timer interrupt to read the port pins say every 100mS?

    Within the interrupt do something like this...
    Code:
    Rotary_Data_Old = Rotary_Data_New   'Make previous new encoder data value read the new old value
    Rotary_Data_New = Portx & %00001110  'Read new rotary value masking off bits not used for the encode (Set bits required to 1, other bits to 0)
    
    Select Rotary_Data_New     'Assign (NOT convert) binary encoder values to sequential decimal values 1 to 6 as the encoder values will be in a grey scale sequence 
             Case = %00000010
                Rotary_Data_New = 1
             Case = %00000100 
                Rotary_Data_New = 2
       'Repeat for as many values as required
    EndSelect
    I presume this is your current button code...

    Code:
    If ToetsHoger = 1 Then Freq_up
    If ToetsLager = 1 Then Freq_down
    If ToetsSet = 1 Then Freq_save
    If so then change it to something like...
    Code:
    If Rotary_Data_Old = 6 & Rotary_Data_New = 1 then        'Up direction loop around
       Freq_up 
    ElseIF Rotary_Data_Old = 1 & Rotary_Data_New = 6 then    'Down direction loop around
       Freq_down 
    ElseIf Rotary_Data_New > Rotary_Data_Old                 'Up direction turn
       Freq_up
    ElseIf Rotary_Data_New < Rotary_Data_Old                 'Down direction turn
       Freq_down
    EndIf
    Hopefully that will do what you want.

  3. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,857
    Thumbs Up
    Received: 163
    Given: 162
    Total Downloaded
    3.24 GB

    0 Not allowed!

    Default Re: Other ports use for interrupt

    B7 is IOC. Personally I never use pins that are part of ICSP, but thats just me.

    I can't remember how I did this last time but its something like generate an interupt on one pin and read the other to sus the direction. Maybe this will help, it uses pin that you have here
    George

  4. #4
    Junior Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    49
    Thumbs Up
    Received: 10
    Given: 2
    Total Downloaded
    1.08 GB

    0 Not allowed!

    Post Re: Other ports use for interrupt

  5. You can use IOC to read pins 4 and 5 on portb. That won't interfere with ICSP. There is no setup apart from port settings. RBIE =1 starts the interrupt and the handler can be like this:

    Code:
    If RBIF = 1 Then                        ' On RBIF interrupt
        RBIF = 0
        Swapf PORTB,WREG
        bNew = WREG & 3
    EndIff
    Flosi Guđmundsson
    Reykjavík

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Incrementing ports
    By Richard in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 19th May 2009, 07:42
  2. Replies: 12
    Last Post: 18th January 2009, 22:59
  3. Ports
    By DanStory in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 4th September 2007, 08:01
  4. More serial ports
    By galeforce9 in forum The Lounge
    Replies: 7
    Last Post: 31st August 2007, 21:34

Members who have read this thread since 30th November 2018, 09:13 : 0

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts