HSERIN & Interupts (aka controlling PIC programs from a remote PC)


Results 1 to 17 of 17

Threaded View

  1. #12
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Sorry, I was just stripping out the interupt bits (since they are compiling fine now), but yes, I can see how that's confused you all!

    Anyway, to show off my new found "box" skills, here you go...

    Code:
    @MyConfig = _XT_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF 
    @MyConfig = MyConfig & _BOR_OFF 
    @ __config MyConfig 
    
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts 
    
    DEFINE OSC 4
    DEFINE HSER_SPBRG 25
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_CLROERR 1
    ANSELH=0
    ANSEL=0
    CM1CON0 =0
    CM2CON0 =0
    CM2CON1 =0
    adcon1=0
    TRISB.6 = 1
    TRISB.7 = 0
    TRISC=%00000000 ; set all Port C pins as outputs
    rcsta.7=1 'SPEN serial port enable bit
    low portc.0
    low portc.1
    low portc.2
    low portc.3
    
    mybyte var byte
    '::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    RX_INT,  _Get_char,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    '::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::
    @   INT_ENABLE   RX_INT     ; enable external (INT) interrupts
    
    
    loop:
    if mybyte="1" then
    hserout ["got it!"]
    endif
    
    if mybyte=!"1" then
    hserout ["DIDN'T GET IT!",13,10]
    hserout [mybyte,13,10]    ' (tried to add in this line to see onscreen what the content of mybyte is - nothing output!)
    PAUSE 499
    mybyte=0
    endif
    goto loop
    
    
    
    '---[USART RX - interrupt handler]---------------------------------------------------
    Get_char:
         hserin 100,noreceived,[mybyte] 'Get byte
         noreceived: 'or if timeout return
    @ INT_RETURN
    My (noob) take here is that, when a key is pressed, the interrupt routine jumps to the Get_char - this keyboard 'keyed' "data" is then stored in the variable mybyte - but what will the actual contents of mbyte be ? For example if I press a "1" key on the keyboard will it be 00000001 (unlikely!), or 00110001 (binary for 49 - the ASCII code for the number "1"). Once I can figure out this bit, then I can make sure my "if" takes account of it. (that'll be my next question!) Also, the line I bolded...I was trying to see onscreen what the content of the variable mybyte was - but nothing was output?

    BTW The low portc.0 low portc.1 are in there because I have a Microchip low pin count demo board & my (eventual) target for today is to get some LEDs to light up when certain keys on my PC keyboard are pressed - I'm a simple kind of easy to please chap, who marvels at this kind of thing & insists all around me marvel too! (though it irks my two year old something rotten when I interrupt his Thomas The Tank Engine viewing)
    Last edited by HankMcSpank; - 17th June 2009 at 14:38.

Similar Threads

  1. Replies: 24
    Last Post: - 2nd October 2017, 12:35
  2. Direct PIC to PC without MAX232
    By acjacques in forum Serial
    Replies: 14
    Last Post: - 23rd October 2014, 22:32
  3. Send data PIC to PC
    By konter in forum Off Topic
    Replies: 6
    Last Post: - 25th December 2009, 23:04
  4. Replies: 67
    Last Post: - 8th December 2009, 03:27
  5. Controlling power to a PIC with another PIC
    By jswayze in forum Off Topic
    Replies: 3
    Last Post: - 28th May 2005, 20:44

Members who have read this thread : 0

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