Hserin with Instant Interrupts.


Results 1 to 18 of 18

Threaded View

  1. #2
    skimask's Avatar
    skimask Guest

    Default

    For grins, try this instead of TOGGLE...
    Code:
     '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
                         'Hserin with Darryl Taylor's Instant Interrupts
     '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
       '   Program to echo incoming serial data 
        '   Baudrate : 9600 Baud
           ' MCSP and MPASM, LabX-2, Microcodeloader, PBP2.50
             ' Using PIC 18F2525 @ 4MHZ and bootloader
               ' Using internal USART and MAX232 to interface to Hyperterminal on PC
    
            
            DEFINE LOADER_USED 1
            DEFINE OSC 4
            DEFINE HSER_RCSTA 90h ' enable serial port, 
            define HSER_TXSTA 24h ' enable transmit, 
            define HSER_SPBRG 25 ' set baudrate to 9600                   
            DEFINE HSER_CLOERR  1 ' automatic clear overrun error  
            
            TRISC  = %10000000    ' PORTC.7 is the RX input, PORTC.6 is the TX output
                                  
        
        '   Serial communication definition
        '   ===============================
            '
            
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    INCLUDE "MODEDEFS.BAS"       ' Include Shiftin/out modes
    INCLUDE "DT_INTS-18.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"  ' Include if using PBP interrupts
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        '   Variable definition
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
            
    RCIF       VAR     PIR1.5     ' Receive  interrupt flag (1=full , 0=empty)
    TXIF       VAR     PIR1.4     ' Transmit interrupt flag (1=empty, 0=full)
    led        var     PORTB.0
    led1count var byte
    led2count var byte
    led1       var     PORTB.1
    led2       var     PORTB.2
    holdoff    var     word
    SerialData var     byte
    
    clear
    
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   RX_INT,    _Getbytes,    PBP,  no
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE  RX_INT     ; enable RX_INT interrupts
    
    
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
                       ' Subroutine to slow loop down some and toggle heartbeat
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    Mainloop:
            for holdoff = 1 to 1000
            pause 1
            next holdoff
            led1count = led1count + 1
            led = led1count.0     'toggle led every loop for heartbeat  
            goto Mainloop
    
    
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
               'ISR for RX_int interrupt 
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    
    Getbytes:
            
           While RCIF = 1     ' clear the buffer
           HSERIN 100,error,[Serialdata] ' take it
           hserout [serialdata] ' send it
           Wend
           led2count = led2count + 1
           led2 = led2count.0     'led to confirm program went to RX ISR
    
    @ INT_RETURN
    
    
    error:
          Toggle led1
    @ INT_RETURN
     end
    Using that method to set the LEDs, you can dispense with the pause loop and select a higher bit in the ledxcount variable to slow down the blinking.
    Last edited by skimask; - 14th September 2008 at 00:50.

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 23:14
  2. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 22:43
  3. Instant Interrupts and HSERIN
    By Rob in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 31st January 2009, 06:13
  4. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 21:02
  5. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 21:48

Members who have read this thread : 1

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

Posting Permissions

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