Hserin with Instant Interrupts.


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Looks like this needs re-named? If PORTS A through Z do not work
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91

    Default Never crossed my mind!

    I never thought I'd need to set ADCON1 since I'm not using any of PortA.
    Learning something new every day. As always, thanks for the help.

    I'm going to try your method of toggling the LED's Skimask, never seen it done like that, Thanks.

    New working code with one minor change. (Thanks Bruce.)

    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
        '   ===============================
            '
      ADCON1 = %00001111      'Set up ADCON1 register no matter what you're doing!!!!!!
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    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
    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
            toggle led           '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
           toggle led2       'led to confirm program went to RX ISR
    
    @ INT_RETURN
    
    
    error:
          Toggle led1
    @ INT_RETURN
     end
    "It will never happen here!" just happened here.
    My thoughts and prayers for Sandy Hook victims and families.

  3. #3
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by ronjodu View Post
    I'm going to try your method of toggling the LED's Skimask, never seen it done like that, Thanks.
    I like that method of using the heartbeat because it allows for an easy change of blink frequency. The LED 'attached' to a timer works also, but it only tells you that the timer is running and an interrupt is working. Generally, I use 2 heartbeats, one for a mainloop, and one for a timer. Mainloop says the program is looping, timer says the PIC is actually running.

  4. #4

    Default

    From what I see it's mostly a matter of setting up the defines and running getbytes?

    Is this the barebones of what I need to get data in/out of serialdata?

    As long as data is at portc.7 it continuously runs in the background as an input, loading serialdata while any other code is executing?

    I can then sample serialdata when I need to in my code?


    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


    Getbytes:

    While RCIF = 1 ' clear the buffer
    HSERIN 100,error,[Serialdata] ' take it
    hserout [serialdata] ' send it
    Wend

Similar Threads

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