USART interrupt in PIC16F877A


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Iran
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Hi,
    as you saw my program.
    after define oscillator and lcd i enabled USART interrupt and then start to turn on and off led that connected to PORTC.3
    so when interrupt occures the program goes to interrupt routine and shows the recieved data on lcd.
    but in my program if i connect the output of the RF reciever to micro or if i don't connect it,after turning on micro it goes to interrupt routine and it comes back to mian program and befor execute the mian program it goes to interrupt routine again.
    so it's just execute the interrupt routine.
    maby i hve a problem to enable the USART interrupt
    but i have try it many times and i don't know what should i do.
    please help me


    this is my simple program:
    define OSC 20
    'include"modedefs.bas"
    ADCON1=7 ' convert porta from analoge to digital
    TRISA = %00000000 ' set porta as an output
    TRISB = %00001111 'set first 4 bit of portb as an input and last 4 bit as putput
    TRISC = %00000000 ' set portc as output
    '----------------------------------------------------
    ' Define LCD parameters
    ' Set LCD Data port
    DEFINE LCD_DREG PORTD
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTD
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 1
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTD
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 0
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    pause 100
    lcdout $fe,1
    i var word
    y1 var byte
    y2 var byte
    y3 var byte
    'PIR1=%00000000
    on interrupt goto USART_int
    INTCON = %11000000 'Initializing the INTCON register
    PIE1= %00100000 'Initializing the PIE1 register
    RCSTA= %11011001 'Initializing the RCSTA register
    start:

    for i=1 to 1000
    PORTC.3=0
    pause 1
    next i
    for i=1 to 1000
    PORTC.3=1
    pause 1
    next i
    goto start
    disable
    USART_int:
    include"modedefs.bas"
    serin PORTB.0,N1200,["A"],y1
    serin PORTB.0,N1200,["A"],y2
    serin PORTB.0,N1200,["A"],y3
    '
    if (y2=y3) then
    lcdout $fe,1,#y2
    pause 4000
    lcdout $fe,1,"salam"
    pause 4000
    PORTC.4=1
    pause 4000
    PORTC.4=0
    endif
    PIR1=%00000000
    INTCON = %11000000 'Initializing the INTCON register
    PIE1= %00100000 'Initializing the PIE1 register
    RCSTA= %11011001 'Initializing the RCSTA register
    resume
    enable
    end
    'delay:
    'for i=1 to 2000
    'pause 1
    'next i
    'return

  2. #2
    Join Date
    Aug 2006
    Location
    Iran
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Hi,
    i can solve my problem. it works but i have another problem.when i use this interrupt with a simple program it works but when i use this in a big one(my program is about 1000 lines) it doesn't work.
    i also use 20M crystal but it doesn't work too.
    what's the reason?

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 03:35
  2. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 19:14
  3. USART interrpt in PIC16F877A
    By amindzo in forum Serial
    Replies: 3
    Last Post: - 28th August 2006, 17:07
  4. PIC Basic PRO 16F877 USART Interrupt TX
    By BigH in forum Serial
    Replies: 8
    Last Post: - 10th January 2006, 00:26
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02: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