Instant Interrupts - Revisited


Results 1 to 40 of 773

Threaded View

  1. #7
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Dt_ints-14

    Hello guys,

    I am a newbie to this forum and PIC/PBP.
    I am very glad to have Darrel Taylor's DT_INTS-14 compiled and work great for me.
    I tried to add small routine for receiving data from usart but something start to stop working.

    I posted my code below with all details remaked. Please someone find what have i done wrong.
    I am still in my learning process and am scrolling. Many thanks

    Cheers,
    ozion


    Code:
    '****************************************************************
    '*  Name    : BringTogether_with_RX-USart.BAS                   *
    '*  Notice  :  Using DT_INTS-14                                  *                                 
    '*  MCU     : PIC16F877A                                        *
    '*  Goal    : A string of data from PC via usart will interrupt *
    ''          : the PIC from what it was doing to receive the data,*
    '*          : filter and store received data for processing.    *
    '*          : After received the filtered data, an acknowledge  *
    '*          : will be send back to PC then return to what it was*
    '*          : left off (and processing the received data)       *
    '*          :                                                   *
    '*  Notes   : This program was working without adding Usart RX  *
    '*          : Now
    '*          : Clock works OK                                    *
    '*          : LED1 won't work                                   *
    '*          : LED2 won't work                                   *
    '*          : Usart won't work as expected.                     *
    '****************************************************************
    
    clear
    
    define LOADER_USED 1
    define  OSC 8
    
        ' Define LCD registers and bits
        Define	LCD_DREG	PORTB   ' LCD Data register on PORTB
        Define	LCD_DBIT	4       ' LCD data bits (4 bits)
        Define	LCD_RSREG	PORTB   ' LCD Reset register on PORTB
        Define	LCD_RSBIT	2       ' LCD Reset bit 2 (PORTB.2)
        Define	LCD_EREG	PORTB   ' LCD Enable register on PORTB
        Define	LCD_EBIT	3       ' LCD Enable bit 3 (PORTB.3)
    
    
    ADCON1 = 7						' Set portA outputs to Digital / No ADC
    'CMCON  = 7
    LCDOUT $FE,1                    ' Initialize LCD
    PAUSE  200
    
    dat_in  var byte[10]        ' Added for Usart receive data
    ack     var byte            ' Added for Usart receive acknowledge
    cntr    var byte            ' Added for Usart receive data storage
    LED1    VAR  PORTD.0
    LED2    VAR  PORTD.3
    
    INCLUDE "DT_INTS-14.bas"    ' Required
    INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"   ' Elapsed Timer Routines
    
    ' Initialize USART          ' Added for Usart receive process
    TRISC = %10111111           ' Set PortC.6 to output, rest to input
    DEFINE HSER_BAUD 9600       ' Hser baud rate 
    RCSTA = %10010000           ' Enable serial port and continuous receive
    TXSTA = %00100000           ' Enable transmit and asynchronous mode
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED2,   PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
            INT_Handler     RX_INT,  _Read_USART,   PBP,  yes       ; Added
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE   INT_INT     ; enable external (INT) interrupts
        INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
        INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts
        INT_ENABLE   RX_INT      ; enable RX_Usart interrupts       ; Added 
    ENDASM
    
    OPTION_REG = OPTION_REG & $80 | 1  ; Set TMR0 Prescaler to 256, leave RBPU alone
    Gosub ResetTime              ' Reset Time to  0d-00:00:00.00
    Gosub StartTimer             ' Start the Elapsed Timer
    
    Main:
        if SecondsChanged = 1 then  
           SecondsChanged = 0
           LCDout $FE,$C0, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
        endif
        if Ack=1 then              ' Added
           gosub Receive_Ack       ' Added
        endif                      ' Added
        
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         Toggle LED1
    @ INT_RETURN
    
    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    T0Count  Var WORD
    ToggleLED2:
        T0Count = T0Count + 1
        if T0Count = 512 then T0Count = 0 : Toggle LED2
    @ INT_RETURN
    '////////////////////////////////////////////////////////////////////////////////////
    'Added to read Usart
    Read_USART:                                              
        hserin[dat_in]
            '===========================================================================
            'The following 2 lines won't work
            'hserin[wait("X"),str dat_in\5]	' Wait for X ;receive a string of characters 
            'hserin[wait("X"),dat_in]	' Wait for X
            '=========================================================================== 
        'Following lines send back string includes first dectect char "$"
        'Example: PC sent:              "12345$6789"
        '         PIC send back to PC   "12345$"
        ack=0                               ' clear ack
        cntr=0                              ' reset counter
        while cntr<10                       ' looping
            if (dat_in[cntr]= "$") then     ' filter character "$"
                HSEROUT[str dat_in,cntr]    '
                ack=1                       ' Yes found "$"
                cntr=10                     ' get out of loop
            endif                           '
            cntr=cntr+1                     ' increment counter
        wend                                '
        HSEROUT[str dat_in]                 ' send to PC
        'gosub Receive_Ack                  ' This doesn't works it does not call Receive_Ack
    @ INT_RETURN
    
    Receive_Ack:
        if ack=1 then
            HSEROUT ["got it:"]
            HSEROUT[str dat_in]             ' Send dat_in received string           
        endif
        ack=0
    return
    '//////////////////////////////////////////////////////////////////////////////
    Last edited by Darrel Taylor; - 7th September 2006 at 05:20. Reason: added [code][/code] tags

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 : 8

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