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


Results 1 to 17 of 17

Threaded View

  1. #1
    Join Date
    Mar 2009
    Posts
    653

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

    So I started out on this journey with the intention of kludging a little PIC program to simply count encoder pulses from a striped disc attached to a motor then traversing the copper wire feeding onto it viaa stepper motor ...alas, I knew nothing about stepper nor PICs! Well - thanks to a lot of help on here - my PIC program now works....as the main motor turns, the little stepper motor is 'synced' (via the encoder & pic 'counter'), meaning that copper wire is fed onto the coil's core in 'Good King Wenceslas' style (ie deep & crisp & even - geddit?!!). I'll post a video soon.

    but wait ...that's not good enough!

    Yep - it's bells & whistles time!! [crowd groans]

    At the minute, I have some simple push buttons hardwired into my circuit to stop & start the PIC program ..."it's good, but it's not quite right" (UK TV viewers might lock onto that phrase).

    I actually would like a few more button options...sure I could crank up the button count...but that's going to get , erhm buttony! Guess what...my PC has lots of buttons (though most people call them keys)

    in short I'd like to control my PIC from my PC over serial comms into the h/w USART using interupts....so that when for example I press an 'S' key on my PC, the PIC program stops, or a 'P' key...it pauses etc

    Now then, I used interupts with my little PIC program already (for every time there's a black stripe arrives from the encoder wheel, a little interupt is raised...much neater than polling)...but I learnt bo-diddley about interupts. I kludged & 'borrowed' from others' PIC programs...coupled with the help I got on my last thread ...i got there (ie "The worst programmer in the world" thread...which I still am!)

    So, I need to try & wrap my head around the mechanism behing DT's interupt routines (he's done a fantastic job, which places him above criticism...but I'd like to say that as a newbie...we could do with couple more examples coupled with more explanation aimed at an amoeba level!)

    Ok, so I went to my best friend...a bloke called Google (though Bing crosby might be my new best friend soon...I'm fickle that way). And this thread turns up...

    http://www.letbasic.com/forum/showthread.php?p=73546

    which had an uber simple example of just the type of code I need to get me started. So in the best tradition of plagiarism, I tried to use it - it didn't work for me.

    (Now the author did declare that he hadn't tested it...but I'm figuring if I can get this simple little interupt routine to work with my USART & HSERIN, then I'm laughing....)

    Can you help?

    my PIC is a 16f690 ...I reckon the switches/fuses are ok, as I've got HSERIN working with another (non interupt based) PIC program.

    when the 1 key is pressed, I should see something (either "got it" or "didn't get it" onscreen - I see neither)

    @MyConfig = _XT_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF
    @MyConfig = MyConfig & _MCLRE_ON & _BOR_OFF
    @ __config MyConfig

    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 UART RX interrupt


    loop:
    if mybyte="1" then
    hserout ["got it!"]
    mybyte=0
    endif
    if mybyte<>"1" then
    hserout ["didn't get it!"]
    mybyte=0
    endif
    goto loop


    '---[USART RX Interrupt handler]----------------------------------------------------
    Get_char:
    hserin 100,noreceived,[mybyte] 'Get byte
    noreceived: 'or if timeout return
    @ INT_RETURN



    Edit: If I strip all the interupt aspect out from above, and add in a simple

    start1:
    pause 999
    HSEROUT [13,10]
    HSEROUT ["Test, 13,10]
    goto start1


    in place of the original loop...I see the word "Test" on my screen...this proves the config/fuses to do with HSEROUT are correct at least!
    Last edited by HankMcSpank; - 16th June 2009 at 14:48.

Similar Threads

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

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