Serial and interrupt


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Well I have this code and still get underflow errors... I have a pritty good idea of what the code does, but I can't understand why it gives me this undeflow error as it is called from the main loop.
    Code:
    SERBUF var byte 
    TEMP var byte
    COUNTS var byte
    
    ASM
    ; ********************************************************************
    ; INCH ROUTINE
    ; THIS ROUTINE INPUTS RS232 DATA USING A 22K OHM RESISTOR, NO LEVEL-
    ; CHANGING INVERTER IS USED. GPIO,3 = RX (MARK = 0, SPACE = 1).
    ; THIS ROUTINE USES A 8-DATA BIT PER CHARACTER PROTOCOL.
    ; TO RECIEVE A CHARACTER, CALL inch. THE RECEIVED CHARACTER IS PLACED
    ; IN THE REG 'W' AND IN THE REG 'SERBUF'.
    ; CHARACTER WILL ECHO IF 'retlw 0' IS REM-ED OUT.
    ; VARIABLES USED: REG 'TEMP' AND REG 'SERBUF' BOTH VARIABLES ARE
    ; SHARED WITH THE 'outch' ROUTINE
    ; ROUTINES CALLED: 'half_baud' AND 'baud' FOR THE BAUD-RATE TIMING.
    ; ********************************************************************
    inch:
        btfss GPIO,3 ; SKIP ON START BIT = "SPACE" (+RS232)
        goto inch ; ELSE KEEP LOOKING FOR A START BIT
        movlw d'08' ; START SERIAL INPUT SEQUENCE
        movwf _TEMP ; COLLECT 8 DATA BITS
        clrf _SERBUF ; CLEAR SERIAL CHARACTER BUFFER
        call half_baud ; DELAY FOR ONE HALF BAUD TIME
        btfss GPIO,3 ; FALL THRU IF START BIT STILL = "SPACE"
        goto inch ; ELSE IT WAS JUST A NOISE SPIKE, LOOP
    inch1:
        call baud ; DELAY ONE BAUD-BIT TIME ( = 1/BAUD-RATE)
        bcf STATUS,0 ; CLEAR THE CARRY BIT
        rrf _SERBUF,F ; ROTATE CRY -> MSB, ROTATE MSB RIGHT
        btfss GPIO,3 ; IS INPUT = "SPACE" (+RS232) ?
        bsf _SERBUF,7 ; ...SKIP IF YES, ELSE SET BIT TO LOGIC '1'
        decfsz _TEMP,F ; EIGHT COUNTS YET?
        goto inch1 ; ...NO, GET ANOTHER BIT
        call baud ; DELAY FOR THE FIRST STOP BIT
        movf _SERBUF,W ; Put the character in reg 'W'
        retlw 0 ; NOTE: REM THIS OUT IF YOU NEED AN "ECHO"
        ; ...AND FALL THROUGH TO THE 'OUTCH' ROUTINE
        
    ; ********************************************************************
    ; BAUD ROUTINE @ 4 MHz
    ; BAUD RATE: CONSTANT:
    ; 1200 Baud D'137'
    ; 2400 Baud D'68'
    ; 4800 Baud D'34'
    ; 9600 Baud D'16'
    ; 19200 Baud D'8'
    ; 38400 Baud and up - use 'NOP' delays
    ; VARIABLES USED: REG 'COUNT'
    ; ROUTINES CALLED: NONE
    ; ********************************************************************
    baud:            ; AT 2400 BAUD THE PERIOD IS 416.6 US
                    ; CLK = 4MHz
        movlw D'68' ; 1 US (BAUD RATE CONSTANT)
        movwf _COUNTS ; 1 US
    baud1:
        decfsz _COUNTS,F ; 1 US (+ 1 US MORE IF SKIP)
        goto baud1 ; 2 US
        ; FALL THRU...AFTER 1+1+3x68+1 = 207 US
    half_baud:
        movlw D'68' ; 1 US
        movwf _COUNTS ; 1 US
    hbaud1:
        decfsz _COUNTS,F ; 1 US (+ 1 US MORE IF SKIP)
        goto hbaud1 ; 2 US
        retlw 0 ; ...AFTER 1+1+3x68+1 = 207 US (X2=414 US)
    ENDASM
    
    high porta.0
    loop:
    @   goto inch
    if SERBUF = 49 then low porta.0
    goto loop
    END

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Code:
    @   goto inch
    Try ...

    Code:
    @   L?CALL  inch
    DT

  3. #3
    Join Date
    Feb 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Some how I changed the line "@ call inch" to goto before posting. Using "@ L?CALL inch" didn't do anything...

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    If that's your whole program, then you need to add a
    Code:
    GOTO  loop
    before the ASM block.

    As it's shown, it will fall into the inch routine on power-up.
    Then it has nowhere to return to.

    hth,
    DT

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. 18F2480 asm interrupt
    By Richard Storie in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th March 2009, 19:40
  3. Serial and Port B interrupt
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th November 2008, 16:22
  4. timer and serial interrupt
    By yourmomOS in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th July 2006, 18:02
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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