No announcement yet.

Not Getting ASM Interrupt for 16F1829, need some help.

  • Filter
  • Time
  • Show
Clear All
new posts

  • Not Getting ASM Interrupt for 16F1829, need some help.

    Hello again,

    I have been trying to figure out an Interrupt using ASM. It’s hard trying to find good information and what the commands actually mean? When I look at examples, it seems that every one is just copying examples with out really understanding what is going on. At least from what I see!
    movwf wsave – is the variable “w”, so it could be written as… movCharf Charsave ?
    I can’t find any information on this type of information?

    Well any way this is what I am trying to do:
    I am using MicroCode Plus V5.0.0.3, with compiler PBPX, with Windows XP

    Using 16F1829, I am receiving on HSERIN, PORTC.5.
    I receive a Character and Four Digits – HSEROUT [“S”,DEC4 TXS] coming into this chip.
    QUESTION: I assume that you can only have the first Digit or Character saved with an interrupt, what about the next 4 inputs?

    NOTE: It does work as "ON INTERRUPT RxInt" but, missing inputs due to also receiving serial every 50ms on another pin. So, I need ASM. I realize during the Interrupt the serial on the other input will be lost and this is acceptable.

    This is what I have written which is not working…

    DEFINE INTHAND RxInt ' Interrupt Handler for Assembly Language

    INTCON = %01000000 ' Enable FEIE Interrupts PDF-8.1
    PIE1.5 = 1 ' Enable the 5=USART RX Interrupt

    wsave VAR BYTE $20 system ' Making variable Charater for Interrupt
    wsave1 VAR BYTE $A0 system ' Save in RAM in Bank1
    wsave2 VAR BYTE $120 system ' Save in RAM in Bank2
    wsave3 VAR BYTE $1A0 system ' Save in RAM in Bank3
    wsave4 VAR BYTE $220 system ' Save in RAM in Bank4
    wsave5 VAR BYTE $2A0 system ' Save in RAM in Bank5
    wsave6 VAR BYTE $320 system ' Save in RAM in Bank6
    wsave7 VAR BYTE $3A0 system ' Save in RAM in Bank7
    wsave8 VAR BYTE $420 system ' Save in RAM in Bank8
    wsave9 VAR BYTE $4A0 system ' Save in RAM in Bank9
    wsave10 VAR BYTE $520 system ' Save in RAM in Bank10
    wsave11 VAR BYTE $5A0 system ' Save in RAM in Bank11
    wsave12 VAR BYTE $620 system ' Save in RAM in Bank12
    ssave VAR BYTE bank0 system
    psave VAR BYTE bank0 system

    '********** EUARST RX INTERRUPT ***********
    RxInt: ; RX Interrupt - from Mother Board
    movwf wsave
    swapf STATUS, W
    clrf STATUS
    movwf ssave
    movf PCLATH, W
    movwf psave
    ; Input character and 4 digit #
    HSERIN 20,Delay1,[W, Num4, Num3, Num2, Num1]
    TRISC.5 = 1 ; Set HSERIN back to input
    IF (W = $53) THEN ; If Charactor is a "S" then continue
    LATC.7 = 1 ;TEST
    RX1 = 0 ; Start RX1 at null value
    ; Convert input to 4 dig Number
    RX1 = (((Num4-48)*1000)+((Num3-48)*100)+((Num2-48)*10)+(Num1-48))
    RX2 = (Num4-48) ; Convert RX2 to Sensor number
    IF (RX2 = SensorNo) OR (RX2 = 9) THEN ; If # is this Sensor or 9 (all sensors) then
    Inter = 5 ; Set interrupt as active (received data)
    LTD = 0 ; Set Last Three Digits received to null
    ; LTD - Last Three Digits of input
    LTD = (((RX1 DIG 2)*100)+((RX1 DIG 1)*10)+(RX1 DIG 0))
    ENDIF ; End if statement
    PAUSE 15 ;Pause to see test Led
    ENDIF ; End if statement
    Delay1: ; Label for HSERIN command
    LATC.7 = 0 ;Test Led
    bcf INTCON, 1
    movf psave, W
    movwf PCLATH
    swapf ssave, W
    movwf STATUS
    swapf wsave, F
    swapf wsave, W
    GOTO SonChk ' Always return to SonChk

  • #2

    The enhance core devices like the 16F1829 do automatic context saving in hardware.
    So you don't need any of those wsave variables, or the asm part of your interrupt routine.

    But the biggest problem is that you have Basic Language statements in your Assembly Language Interrupts.
    Assembly Language interrupts (DEFINE INTHAND xxx) can only have assembly language in them.

    And, you cannot leave the interrupt by using a GOTO. You have to use RETFIE.
    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
    Never download a PIC datasheet from anywhere but


    • #3
      Hi Darrel,

      OK, if I understand you correctly. If using “DEFINE INTHAND RxInt”; then EVERYTHING in the “RxInt:” has to be in assembly language (omitting all the ASM, wsave, etc. due to this chip).

      If this is true then where would I find good instruction and explanation in writing Assembly Language, for some one who hasn’t worked with ASM before?

      I have tried to find something on line but pretty much what I found is; as if you already new the basics of the commands, which I couldn’t find a list of commands with an explanation.

      Have any good resources I could try.
      I would like to learn it, instead of relying on others designing it for me.

      Thanks Darrel,


      • #4
        Hey Darrel,

        I have been checking the internet for basic Assembly Language books and found myself quickly confused… Which architecture or system should I be looking for that is best for Microcode programming. Any recommendations in books and internet resources.



        • #5
          I've never found any books capable of teaching how to program in assembly language.
          Typically, they have a few projects that have nothing to do with what you want to accomplish. They list the code and give breif explanations of what it does, but like you say, you have to understand what those assembly language statements do to be able to figure out what the program does.

          In every datasheet for PIC's, there is a section called "Instruction Set Summary", which lists all the possible opcodes for that device and what they do.
          Within each of the PIC families (12-bit, 14-bit and 18F), those opcodes are always the same. Learn one, and you know the whole family.

          I've talked about it before, and I still feel that PBP itself is the best teacher of assembly language because it's interactive.
          You can't ask a book a question when you don't understand, but you can ask PBP by compiling statements differently.

          You know how PBP statements work, and PBP converts everything to assembly.
          So you can compile PicBasic code different ways and see how PBP converts it to assembly.

          After compiling a program, look at the .ASM file.
          There you will see a bunch of macro calls. Find those macros in the PBPPIC14.mac file if using a 16F, or the PBPPIC18.mac file for 18F's.
          The macro's then call the library routines in the corresponding .LIB files.

          This is actually how I learned assembly language. No books can provide the same wealth of information.

          With that said, to get your ASM interrupts working without the ASM, you may want to skip learning ASM and try this ...
          PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
          Never download a PIC datasheet from anywhere but


          • #6
            Darrel, your system you created is great and I am trying to incorporate it into my program now.
            I wanted to thank you for the info.

            I did have one problem compiling it into MicroCode Plus.
            [ASM ERROR] Symbol not previously defined {RxInt) (0) : Error[113]
            How do I define it? It won’t take it as a VAR…

            This is what I entered into my program.
            Note: I copied the INCLUDE files into my C:/PBP3 (PBPx3.0.6.4) files. I assume that is were it belongs.

            Entered these just blow my Config:

            INCLUDE "DT_INTS-14.bas"
            INCLUDE "ReEnterPBP.bas"

            Entered these just above my VAR BYTE sections

            INTCON = %01000000
            PIE1.5 = 1

            Entered the ASM just after my Boot Up section

            INT_LIST macro
            INT_Handler INT_INT, RxInt, PBP, yes
            @ INT_ENABLE INT_INT

            GOTO SonarCheck

            Interrupt Routine follows the ASM

            HSERIN 20,Delay1,[Char, Num4, Num3, Num2, Num1]
            TRISC.5 = 1
            IF (Char = $53) THEN
            LATC.7 = 1 ;TEST
            RX1 = 0
            RX1 = (((Num4-48)*1000)+((Num3-48)*100)+((Num2-48)*10)+(Num1-48))
            RX2 = (Num4-48)
            IF (RX2 = SensorNo) OR (RX2 = 9) THEN
            Inter = 5
            LTD = 0
            LTD = (((RX1 DIG 2)*100)+((RX1 DIG 1)*10)+(RX1 DIG 0))
            PAUSE 15
            LATC.7 = 0

            SonarCheck: program continues


            • #7
              The available interrupt sources are listed on the right side of the page I linked to in the last post.
              "RxInt" is not one of them.

              You don't need ENABLE or DISABLE, and DO NOT use resume, use @ INT_RETURN.
              Don't set INTCON, don't set PIE1.5.

              And instead of all the crazy math, just do this ...

              HSERIN 20,Delay1,[WAIT($53), DEC1 RX2, DEC3 LTD]
              PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
              Never download a PIC datasheet from anywhere but


              • #8
                Thanks Darrel, it's appreciated.


                • #9
                  Everything is working as it's suppose to, using the DT Interrupt on HSERIN and using the DataValid statements after the Serin2.
                  But, I find I am loosing too many Serin2 data due to a large volume of interrupts from the HSERIN.

                  I have redesigned my PCB and to resolve all my issues, I need to use a High Priority Interrupt on just PortA.4 of 16F1825 (or any port other than the HSERIN & HSEROUT). I tried using the DT Interrupt using:
                  INT_Handler RAC_INT, _RxInt, PBP, yes
                  But I do not see how to specify just one port of RA. Is there a way to specify this in your system?

                  Thanks Lyle


                  • #10

                    The 16F1825 does not have RAC_INT.
                    It does have IOC_INT though.

                    Edges are selected with the IOCAN/IOCBN and IOCAP/IOCBP registers.
                    The flags are in IOCAF/IOCBF, and you must clear them manually.

                    But I know what you're doing, and it won't work.
                    Trying to receive software serial (SERIN(2)) from an interrupt causes it to loose the START bit from the first byte because that's what triggers the interrupt.

                    The first byte received will be garbage, and depending on how fast the data is comming in, it will most likely not be able to sync up on the rest of the bytes either.

                    I think I've said it before ... but, Trying to receive Software and hardware serial on the same chip is extremely difficult.
                    You will need a timer driven baud rate generator running a custom software UART (SERIN(2) won't cut it).
                    You will need Buffers, you can't just sit in a loop waiting for four or five bytes to come in, even though it was started by an interrupt. That amount of time blocks the other serial input, either software or hardware. You can only grab 1 byte at a time, and store it in a buffer.
                    And all of that has to be done in the ISR as fast as possible so that they don't interfere with each others timing.

                    Currently, you are trying to find an acceptable level of errors that can be ignored ...
                    I beleive that is the wrong way to go.
                    Proper reception should be able to collect ALL data without error.
                    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
                    Never download a PIC datasheet from anywhere but


                    • #11
                      Hi Darrel,
                      Thanks for the information and I did remember what you were talking about earlier.
                      Right now I am NOT trying to use any Serial or High Speed Serial as an Interrupt. I had to Re-design my process to achieve what I wanted.
                      Presently, I am just looking at trying to get a High Priority Interrupt on a port of the 16F1825 as an incoming "HIGH" (doesn't matter which pin I use, I can work around it; presently trying for PORTA.4).

                      I have not been able to find any Manual for the DT_INTS for the 16F1xxx. So, I was taking what your available Interrupt Source sheet said, using RAC for the "RA Port Change" Thinking that is what I needed... As usual, I was wrong again
                      I have not been able to find any manual to explain more in depth of your commands (but, I think I am getting a good idea of how things work on your Interrupts now).

                      So, if understand you right, using the "IOC_INT";
                      then using the (IOCAP.4 = 1 / IOCAP.4 = 0) it should work for the port "High / Low" interrupt...
                      I'll give it a try.
                      Thanks Darrel.


                      • #12
                        Originally posted by Lyle Bain View Post
                        So, if understand you right, using the "IOC_INT";
                        then using the (IOCAP.4 = 1 / IOCAP.4 = 0) it should work for the port "High / Low" interrupt...
                        If you want interrupts on both Rising and Falling edges, IOCAP.4 = 1 and IOCAN.4 = 1.
                        IOCAP selects the Rising edge, IOCAN selects the falling edge.

                        For falling edge only ... IOCAP.4 = 0, IOCAN.4 = 1.
                        PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
                        Never download a PIC datasheet from anywhere but