Menu

Interrupt from i/o pin

Help
viscomjim
2015-03-12
2015-03-12
  • viscomjim

    viscomjim - 2015-03-12

    I am using a pic 12f1840 and trying to figure out how the interrupts are handled. I checked the help file and cannot see how you can call an interrupt sub from a specific pin. There is an example but it only shows how to use the timer overflow to generate an interrupt. I scoured the help forum and can't find any examples of being able to just define a pin as an interrupt pin. I am using porta.3 which from the data sheet shows IOC under the interrupt column along with all the other i/o pins. I am assuming this stands for interrupt on change? I tried (from what I can gather from the help forum)

    set IOCA3 on - expects "IOCA.3" - doesn't work
    on interrupt portabchange call sub - there is no port b on this chip
    on interrupt portachange call sub - won't compile

    What my head is trying to do is...

    "set porta.3 as an interrupt pin (either high or low or change)"
    "on interrupt porta.3 call sub"

    or something of this nature.

    I cannot for the life of me figure out how to make this work. Any and all help in the interrupt area would be so greatly appreciated.

    P.S. I am just reading a switch to ground. porta.3 is tied high with 10k.

    Here is my simple test code...

    #chip 12f1840,32
    
    #define SWITCH PORTA.3
    #DEFINE LED PORTA.2
    
    DIR LED out
    Dir SWITCH In
    
    SET IOCA3 ON                            'this is not working or making sense to me
    ON Interrupt PORTBCHANGE CALL LEDSUBX    'this is not working or making sense to me
    
    
    DO
    WAIT 1 MS
    LOOP
    
    SUB LEDSUBX
    SET LED ON
    WAIT 1 S
    SET LED OFF
    END SUB
    
     
  • kent_twt4

    kent_twt4 - 2015-03-12

    The "PortBChange" is unfortunate, but it does the job. So the 12f18xx chips have a IOCAN negative edge and an IOCAP positive edge register, along with the IOCAF flags register.

    So the code will work by initializing (Set IOCAN3 ON), and clearing the flag (Set IOCAF3 OFF) in the LEDSUBX sub.

     
  • viscomjim

    viscomjim - 2015-03-12

    Hi Kent_tw14, I can't thank you enough for that and I need to buy you a beer or two. This worked splendidly.

    How in the world do you find these GCB commands? I searched the help file and can't find any information on IOCAN, IOCAP and IOCAF in the interrupt details or in the help forum. I am trying to become efficient in GCB but finding this type of information is difficult. Any suggestions for a noob?

    Thanks again!!!!!!!!

     
  • kent_twt4

    kent_twt4 - 2015-03-12

    Your welcome viscomjim. Really the credit and the beer goes to Hugh and all the other great contributors of this forum for how well GCB works.

    It took me a longish while to become somewhat proficient with the inner workings of PICs and GCB, lots of info to digest. Sometimes with different families of PICs the information gets moved around a bit in the data sheet. Interrupts used to be all in the Special Features chapter. Then they got moved to their own Interrupts chapter. Now they have split out the Interrupt On Change to its own chapter, from the Interrupts.

    GCB lets you set the register bits individually, like IOCAN3. There could be some possible exceptions. This usually involves having the data sheet handy, and a look at the GreatCowBasic/ChipData/Device.dat file, and the [Bits] column if need be. Lots of great info in the .dat files. Those two documents will resolve most questions or problems. Next up would be to look at the .asm file to see if things are compiling correctly or to your way of thinking :). I find my way of thinking is consistently wrong haha.

    EDIT: To be more correct, the sequence of troubleshooting would be to start with the (Online)Help http://gcbasic.sourceforge.net/help/ and demonstration files https://sourceforge.net/projects/gcbasic/files/Demonstration%20Files/ Search the forum. Then consult the data sheet, device.dat, and .asm files.

     

    Last edit: kent_twt4 2015-03-12
  • viscomjim

    viscomjim - 2015-03-12

    Well thank you for that info. I will start going over the .dat files and datasheet more now.

    You are correct, Hugh has created a great program here and I am very very thankful to him for that. Also, a big thanks to the great users and members that have contributed to GCB and continue to help others here in the forum. What a great community!

    Just as a conclusion for this problem, here is the updated code that works perfectly.

    Thanks again!!!!!!!

    #chip 12f1840,32
    
    #define SWITCH PORTA.3
    #DEFINE LED PORTA.2
    
    DIR LED out
    Dir SWITCH In
    
    SET IOCAN3 ON 'int. on neg. edge (use iocap for pos. edge) porta.3
    
    ON Interrupt PORTBCHANGE CALL LEDSUBX
    
    DO  'loop forever
    WAIT 1 MS
    LOOP
    
    
    
    SUB LEDSUBX
    SET LED ON
    WAIT 1 S
    SET LED OFF
    SET IOCAF3 OFF  'clear interrupt flag
    END SUB
    
     

    Last edit: viscomjim 2015-03-12

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.