confused problem with interrupt in a working program


Closed Thread
Results 1 to 6 of 6
  1. #1

    Default confused problem with interrupt in a working program

    Although i have made a lot of simple programs in my first big program i am in a dead end! i have made a controller-joystick for a wirelless car

    i have this program that works ok:

    INCLUDE "Modedefs.bas"
    TRISA=255
    TRISC=%1000000
    TRISB=0
    ADCON1.0=1 'all porta digital for switches
    ADCON1.1=1
    ADCON1.2=1
    ADCON1.3=0
    DEFINE OSC 4
    DEFINE LCD_DREG PORTB 'LCD Configuration in portb
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 3
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_DATAUS 50
    CO VAR WORD
    B0 VAR BYTE
    B1 VAR BYTE
    B2 VAR BYTE
    A VAR BIT
    B VAR BYTE
    C VAR BIT
    FLAG VAR BIT
    A=0
    C=0
    B=0
    FLAG=0
    Pause 1000
    main:
    IF (PORTA.0==0 && A==1) then ' decision (up-down switches) about velocity of a robot
    B=B+1
    FLAG=1 'flag to know if a button was pressed
    EndIF
    IF (PORTA.1==0 && C==1) Then
    B=B-1
    FLAG=1
    EndIF
    IF (B>4 && B<250) Then '5 levels for velocity
    B=4
    EndIF
    IF B>250 Then
    B=0
    EndIF
    A=PORTA.0 'old situation of ports to compare in order to understand when the buttons were pressed
    C=PORTA.1
    IF b==0 Then ' flashing leds dependable to the velocity
    Low PORTD.7
    Low PORTD.6
    Low PORTD.5
    Low PORTD.4
    High PORTC.5
    EndIF
    IF b==1 Then
    Low PORTD.7
    Low PORTD.6
    Low PORTD.5
    high PORTD.4
    High PORTC.5
    EndIF
    IF b==2 Then
    Low PORTD.7
    Low PORTD.6
    high PORTD.5
    high PORTD.4
    High PORTC.5
    EndIF
    IF b==3 Then
    Low PORTD.7
    high PORTD.6
    high PORTD.5
    high PORTD.4
    High PORTC.5
    EndIF
    IF b==4 Then
    high PORTD.7
    high PORTD.6
    high PORTD.5
    high PORTD.4
    High PORTC.5
    EndIF
    PAUSE 12
    gosub LPD
    IF FLAG=1 THEN
    SerOut2 PORTC.6, 84, ["v: ",DEC B,13,10]
    ENDIF
    IF FLAG=0 THEN
    GOTO MAIN
    ENDIF
    FLAG=0
    GoTo main
    LPD:
    LCDOUT $FE,1,"V: ",DEC B
    RETURN


    The problem is that i want to know something about the car. so i want an interrupt in serial port (rx -portc.6) and that is where the problems started
    i made the following program. but even my joystick becomes dead (not to metion that i can't see anything in terminal!).with underlines the changes of the above program.Any ideas are welcome....

    INCLUDE "Modedefs.bas"
    TRISA=255
    TRISC=%1000000
    TRISB=0
    ADCON1.0=1 'all porta digital for switches
    ADCON1.1=1
    ADCON1.2=1
    ADCON1.3=0
    DEFINE HSER_RCSTA 90h ' enable serial port,
    ' enable continuous receive
    '
    DEFINE HSER_TXSTA 24h ' enable transmit,
    ' BRGH=1
    '
    DEFINE HSER_BAUD 9600


    DEFINE OSC 4
    DEFINE LCD_DREG PORTB 'LCD Configuration in portb
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 3
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_DATAUS 50
    CO VAR WORD
    RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
    OERR var RCSTA.1
    CREN VAR RCSTA.4
    INTCON = %11000000
    ON INTERRUPT GOTO serial
    PIE1.5 = 1
    TXIF VAR PIR1.4

    B0 VAR BYTE
    B1 VAR BYTE
    B2 VAR BYTE
    A VAR BIT
    B VAR BYTE
    C VAR BIT
    FLAG VAR BIT
    A=0
    C=0
    B=0
    FLAG=0
    Pause 1000
    main:
    IF (PORTA.0==0 && A==1) then ' decision (up-down switches) about velocity of a robot
    B=B+1
    FLAG=1 'flag to know if a button was pressed
    EndIF
    IF (PORTA.1==0 && C==1) Then
    B=B-1
    FLAG=1
    EndIF
    IF (B>4 && B<250) Then '5 levels for velocity
    B=4
    EndIF
    IF B>250 Then
    B=0
    EndIF
    A=PORTA.0 'old situation of ports to compare in order to understand when the buttons were pressed
    C=PORTA.1
    IF b==0 Then ' flashing leds dependable to the velocity
    Low PORTD.7
    Low PORTD.6
    Low PORTD.5
    Low PORTD.4
    High PORTC.5
    EndIF
    IF b==1 Then
    Low PORTD.7
    Low PORTD.6
    Low PORTD.5
    high PORTD.4
    High PORTC.5
    EndIF
    IF b==2 Then
    Low PORTD.7
    Low PORTD.6
    high PORTD.5
    high PORTD.4
    High PORTC.5
    EndIF
    IF b==3 Then
    Low PORTD.7
    high PORTD.6
    high PORTD.5
    high PORTD.4
    High PORTC.5
    EndIF
    IF b==4 Then
    high PORTD.7
    high PORTD.6
    high PORTD.5
    high PORTD.4
    High PORTC.5
    EndIF
    PAUSE 12
    gosub LPD
    IF FLAG=1 THEN
    SerOut2 PORTC.6, 84, ["v: ",DEC B,13,10]
    ENDIF
    IF FLAG=0 THEN
    GOTO MAIN
    ENDIF
    FLAG=0
    GoTo main
    LPD:
    LCDOUT $FE,1,"V: ",DEC B
    RETURN


    disable
    serial:
    HSerin [WAIT ("d"),DEC serial_in]
    if rcif then serial
    HSerOut ["hit on wall",13,10]
    high PORTE.0
    RESUME
    ENABLE
    Last edited by illuminator4; - 13th November 2008 at 20:54. Reason: will anyone reply? (snif snif)

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Which chip are you using?
    Under what conditions do you want feedback from the device?

    You have a SEROUT2 working in one place in your code on the hardware serial pin. Why both?

    will anyone reply? (snif snif)
    no need for that... my first post is still unanswered
    Last edited by mackrackit; - 13th November 2008 at 23:12.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Talking

    thanx for replying. my pic is pic16f877a @ 4Mhz. about Serout2 in the first program i used it. in the second i tried both serout2 and hserout but with no result!
    the snif snif was beacuse i had seen hundreds of views in questions asked later than me. sorry!
    About the conditions i want to know when my car that i control with the aboe code hits the wall (with the help of the switch). when it hits the wall i want to receive one number. that is all i ask!

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Betcha it is something to do with wait, also You are aware that hser.* is sent true not inverted. Howz about the other end of the equation (what the car sends), and does it send more than once ? Big also, put a pullup resistor on the herserin line.
    Last edited by Archangel; - 14th November 2008 at 02:19.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    9600 might be a bit fast for 4MHz. So an adjustment there could be in order.

    Let work on the interrupt problem first.
    The below code has a push button on PORTB.0. PORTB.0 is pulled LOW with an external 10K.
    I have an LED on PORTD.2 for testing with a 470 to the zero rail.
    Using SEROUT2 so a level converter (MAX232) is not needed at this time.

    See if you can make this work and then we can play with the hardware serial and level converters.

    Code:
    '#####################
    '16F877A
    DEFINE OSC 20
    '####################
    @ __config _HS_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF &_BODEN_OFF
    I	VAR	BYTE
    ON INTERRUPT GOTO MACINT
    INTCON = %10010000
    
    LOOP:
    HIGH PORTD.2
    SEROUT2 PORTC.6,16468,["PUSH ME !!!",10,13]
    PAUSE 100
    GOTO LOOP
    
    '############################################
    DISABLE
    MACINT:
    IF PORTB.0 = 1 THEN
    FOR I = 1 TO 10
    HIGH PORTD.2
    PAUSE 150
    LOW PORTD.2
    PAUSE 150
    SEROUT2 PORTC.6,16468,["MACKRACKIT",10,13]
    NEXT I
    ENDIF
    INTCON.1 = 0
    RESUME
    ENABLE
     'THE ABOVE WILL ALSO DEBOUNCE THE SWITCH
    '#############################################
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    9600 baud run perfect @4MHz with the hardware USART (0.16% error), however may suffer with SEROUT, SEROUT2, in this case DEBUG is recommended if you don't want to use the Hardware USART.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. urgent: interrupt problem please help
    By cwmaddy in forum General
    Replies: 4
    Last Post: - 21st July 2009, 19:14
  2. USART interrupt in PIC16F877A
    By amindzo in forum General
    Replies: 7
    Last Post: - 26th August 2006, 18:51
  3. Simple Interrupt Program
    By eoasap in forum General
    Replies: 5
    Last Post: - 28th October 2005, 16:22
  4. Interrupt Problem
    By FrankM in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 20th June 2004, 15:53
  5. interrupt problem....need help urgently
    By johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2004, 17:34

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