Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default What I´m doing bad???

    ' PROGRAMA QUE USA INTERRUPCIONES INSTANTÁNEAS '
    ' INT_INT -- INT External Interrupt
    ' RBC_INT -- RB Port Change Interrupt
    ' TMR0_INT -- TMR0 Overflow Interrupt 16F
    ' TMR1_INT -- TMR1 Overflow Interrupt
    ' TMR2_INT -- TMR2 to PR2 Match Interrupt
    ' TX_INT -- USART Transmit Interrupt
    ' RX_INT -- USART Receive Interrupt
    ' CMP_INT -- Comparator Interrupt
    ' EE_INT -- EEPROM/FLASH Write Operation Interrupt
    ' BUS_INT -- Bus Collision Interrupt
    ' PSP_INT -- Parallel Slave Port Read/Write Interrupt
    ' AD_INT -- A/D Converter Interrupt
    ' SSP_INT -- Master Synchronous Serial Port Interrupt
    ' CCP1_INT -- CCP1 Interrupt
    ' CCP2_INT -- CCP2 Interrupt

    clear

    define OSC 16

    ' Define LCD connections
    DEFINE LCD_DREG PORTD ' LCD Data Port
    DEFINE LCD_DBIT 4 ' Starting Data Bit
    DEFINE LCD_RSREG PORTD ' Register Select Port
    DEFINE LCD_RSBIT 2 ' Register Select Bit
    DEFINE LCD_EREG PORTD ' Enable Port
    DEFINE LCD_EBIT 3 ' Enable Bit
    DEFINE LCD_BITS 4 ' Data Bus Size
    DEFINE LCD_LINES 2 ' Number of Lines on LCD

    ' Define RS232 line
    DEFINE HSER_BAUD 19200 'Hser baud rate
    DEFINE HSER_CLROERR 1 'Hser clear overflow automatically
    DEFINE HSER_SPBRG 51 'Hser spbrg init
    DEFINE HSER_RCSTA 90h 'Hser receive status init
    DEFINE HSER_TXSTA 24h 'Hser transmit status init

    ADCON1 = 7 'Set portA outputs to Digital / No ADC
    LCDOUT $FE,1 ' Initialize LCD
    PAUSE 200

    fase_a var portb.0
    subir var portb.1
    bajar var portb.2
    prog var portb.3

    salida var porta.0
    'sentido var porta.1
    'prueba var porta.2

    aux_subir var ppp.0
    aux_bajar var ppp.1
    aux var ppp.2
    escribir_inicio var ppp.3
    escribir_pulso var ppp.4

    ppp var byte
    cuenta var word
    pulso var word
    inicio var word
    que_escribir var word
    aux_aux var byte
    tmp var byte
    direccion var byte
    char var byte
    cadena var byte[20]
    i var byte

    INCLUDE "DT_INTS-14.bas" ' Required
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines

    TRISA = 0
    PORTA = 0
    TRISB = $FF
    TRISC = %10000000
    TRISD = 0
    PORTD = 0
    PORTC = 0

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler INT_INT, _Int_RB0, PBP, yes
    INT_Handler RX_INT, _Int_RX, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor

    INT_ENABLE INT_INT ; enable external (INT) interrupts
    INT_ENABLE RX_INT ;

    ENDASM

    OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone

    Main:
    i = 0
    cuenta = 0
    aux_aux = 0
    inicio = 300
    pulso = 300
    'Reinicializar variables
    if subir and bajar then
    escribir_inicio = 1
    gosub escribir
    escribir_inicio = 0
    escribir_pulso = 1
    gosub escribir
    escribir_pulso = 0
    endif

    'Si no hay nada en eeprom graba variables
    read $0,tmp
    if tmp = $FF then
    escribir_inicio = 1
    gosub escribir
    escribir_inicio = 0
    escribir_pulso = 1
    gosub escribir
    escribir_pulso = 0
    endif

    'Se releen las variables
    gosub leer

    prog_: 'lazo principal

    if subir and prog and not aux_subir then
    gosub mod_inicio_subir
    endif

    if bajar and prog and not aux_bajar then
    gosub mod_inicio_bajar
    endif

    if subir and not prog and not aux_subir then
    gosub mod_pulso_subir
    endif

    if bajar and not prog and not aux_bajar then
    gosub mod_pulso_bajar
    endif

    if not subir then
    aux_subir = 0
    endif

    if not bajar then
    aux_bajar = 0
    endif
    'salida por LCD
    lcdout $fe,2
    lcdout "Posicion ",dec4(cuenta)
    lcdout $fe,$C0
    lcdout "Inicio ",dec4(inicio)
    lcdout $fe,$94
    lcdout "Pulso ",dec4(pulso)
    lcdout $fe,$d4
    cadena[I] = char
    LCDOUT STR cadena,20 'no aparece nada (nothing appears in lcd
    ' lcdout "Salida ",bin salida
    goto prog_

    'Subrutinas
    leer:
    INTCON = $00
    read $0,inicio.byte1
    Read $1,inicio.byte0
    read $2,pulso.byte1
    Read $3,pulso.byte0
    INTCON = $90
    RETURN

    escribir:
    if escribir_inicio = 1 then
    que_escribir = inicio
    direccion = $0
    endif

    if escribir_pulso = 1 then
    que_escribir = pulso
    direccion = $2
    endif

    ' porta.2 = 1 'chequeo para saber que ha escrito en eeprom
    Write direccion,(que_escribir.byte1)
    write direccion+1,(que_escribir.byte0)
    porta.2 = 0
    return

    mod_inicio_subir:
    inicio = inicio + 15
    aux_subir = 1
    if inicio >= 3000 then
    inicio = 3000
    endif
    escribir_inicio = 1
    gosub escribir
    escribir_inicio = 0
    return

    mod_inicio_bajar:
    inicio = inicio - 15
    aux_bajar = 1
    if inicio <= 50 then
    inicio = 50
    endif
    escribir_inicio = 1
    gosub escribir
    escribir_inicio = 0
    return

    mod_pulso_subir:
    pulso = pulso + 15
    aux_subir = 1
    if pulso >= 3000 then
    pulso = 3000
    endif
    escribir_pulso = 1
    gosub escribir
    escribir_pulso = 0
    return

    mod_pulso_bajar:
    pulso = pulso - 15
    aux_bajar = 1
    if pulso <= 50 then
    pulso = 50
    endif
    escribir_pulso = 1
    gosub escribir
    escribir_pulso = 0
    return

    '---[INT - interrupt handler]---------------------------------------------------
    Int_RB0:
    cuenta = cuenta + 1

    if cuenta >= inicio then
    salida = 1
    endif

    if cuenta >= (pulso + inicio) then
    salida = 0
    cuenta = 0
    endif
    @ INT_RETURN

    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)-----
    'T0Count Var WORD
    'ToggleLED2: 'aprox 1 segundo
    ' T0Count = T0Count + 1
    ' if T0Count = 512 then T0Count = 0 : Toggle LED2
    '@ INT_RETURN

    '---[RX - inmterrupt handler]--------------------------------------------------
    Int_RX:
    PORTA.1 = 1 'to check RX int has come
    i = i +1
    hserin [char]
    @ INT_RETURN

    ------------------------
    questions:

    Why LCD doesn´t display cadena?
    Why when i entry many chars by rs232 (fast) variables inicio and pulso corrupts and display an abnormal value?? This check was made without int_int interrupts (fase_a it´s an output from a incremental encoder, and this one was stopped).

    Thanx, and sorry if i´m 'heavy'.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I don't understand your language, so it's hard to tell what's going on.
    But here's a couple problems I can see...

    LCDOUT STR cadena,20 'no aparece nada (nothing appears in lcd

    should be...

    LCDOUT STR cadena\20

    And the reason you're missing characters, is probably because the data is received by the interrupt handler, but it's being put into the "buffer" array in the main loop. That should be done in the handler too.
    <br>
    DT

  3. #3
    Join Date
    Jun 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Thanx for your answer.

    I understand you about the understanding the code.... me too sometimes....

    OK lcdout cadena\20

    >And the reason you're missing characters, is probably because the data is >received by the interrupt handler, but it's being put into the "buffer" array in >the main loop. That should be done in the handler too.
    ¿? Something like this?:

    '---[RX - inmterrupt handler]----------------------------------------------
    Int_RX:
    PORTA.1 = 1 'to check RX int has come
    hserin [char]
    cadena[i] )= char
    i = i +1
    @ INT_RETURN

    but lcd displays rare....

    Don´t worry i´ll figth with it.

    Thanx for all.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Better, but it still needs a way to limit it to the "bounds" of the array. Or, it will overwrite all your other variables. Maybe like this.
    Code:
    '---[RX - inmterrupt handler]----------------------------------------------
    Int_RX:
        PORTA.1 = 1 'to check RX int has come 
        hserin [cadena(i)] 
        i = i +1
        if i >= 20 then i = 0
    @ INT_RETURN
    Of course this still has the problems of not knowing how many bytes were received, if the buffer overflows, if USART errored etc.

    You might want to take a look at this program from Joe S.

    LCD serial backpacks
    http://www.picbasic.co.uk/forum/showthread.php?p=28336

    It has a complete "Circular Buffer" using DT_INTS.
    <br>
    DT

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 06:32
  5. Replies: 1
    Last Post: - 1st November 2006, 03:11

Members who have read this thread : 6

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