Rc int on 16f874


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jul 2006
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Thanks for your respond Mister_e.
    I have change the code, but no sucess.
    Are I'm thinking wrong. Shoudn't I jump into the interrupt rutine when I send a few letters with "Serial Communicator" (MicroCodeStudio +) to the PIC.
    Nothing hapends when I try.

  2. #2
    Join Date
    Jul 2006
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    I start over from the begining and now it's working.

    Thanks for all help!

    /Håkan

    Code:
    '   Pic Definition
        '   ==============
            ' Using PIC 16F874 @ 4MHZ and bootloader
            '
            DEFINE LOADER_USED 1
            DEFINE OSC 4        
            DEFINE LCD_DREG PORTB   ' Set LCD Data port        
            DEFINE LCD_DBIT 0       ' Set starting Data bit (0 or 4) if 4-bit bus        
            DEFINE LCD_RSREG PORTB  ' Set LCD Register Select port        
            DEFINE LCD_RSBIT 7      ' Set LCD Register Select bit         
            DEFINE LCD_RWREG PORTB  'LCD read/write port           
            DEFINE LCD_RWBIT 6      'LCD read/write bit          
            DEFINE LCD_EREG PORTB   ' Set LCD Enable port        
            DEFINE LCD_EBIT 5       ' Set LCD Enable bit        
            DEFINE LCD_BITS 4       ' Set LCD bus size (4 or 8 bits)        
            DEFINE LCD_LINES 2      ' Set number of lines on LCD        
            DEFINE LCD_COMMANDUS 2000' Set command delay time in us
            DEFINE LCD_DATAUS 50    ' Set data delay time in us
                    
        '   Hardware configuration
        '   ======================
            '
            '
            TRISC  = %10000000    ' PORTC.7 is the RX input
                                  ' PORTC.6 is the TX output
            On Interrupt Goto myint ' Define interrupt handler
            INTCON      =   %11000000            ' Enable INTE interrupt
            PIE1.5      =   1
            
            T2CON       =   %01111111
            PIE1.1      =   1
            
            ' LCD background
            LED             var     PORTD.3
            ' LCD
            LcdCls          CON     $01     ' clear the LCD
            LcdLine1        CON     $80     ' DDRAM address of line 1
            LcdLine2        CON     $C0     ' DDRAM address of line 2              
            ' Shaft Encoder
            clock           var     PORTD.0
            stat            var     PORTD.1
            ' ExecuteButton
            exec            var     PORTD.2
            
        '   Serial communication definition
        '   ===============================
            ' Using internal USART and MAX232 to interface to PC
            '
            'RCSTA = $90 
            DEFINE HSER_RCSTA 90h ' enable serial port, enable continuous receive
            'TXSTA = $20 
            define HSER_TXSTA 20h ' enable transmit, BRGH=1
            'SPBRG = 25                  
            define HSER_SPBRG 25 ' set baudrate to 2400   
            DEFINE HSER_CLOERR  1 ' automatic clear overrun error  
            
            T2400           CON     396
            Inverted        CON     $4000
            Baud            CON     T2400 '+ Inverted
            
            txPin           var     PORTC.6
            rxPin           Var     PORTC.7
        '   Alias definition
        '   ================
            '
            '
            RCIF VAR PIR1.5     ' Receive  interrupt flag (1=full , 0=empty)
            TXIF VAR PIR1.4     ' Transmit interrupt flag (1=empty, 0=full)
            OERR var RCSTA.1    ' Overrun error
            CREN var RCSTA.4    ' Continuous receive
            
            dump            var     byte 
            countPulses     VAR     Byte
            print           VAR     Bit
            a               VAR     Byte
            b               VAR     Byte
            c               var     byte
            idx             var     byte
            turnOff         VAR     Bit
            failSafe        VAR     Byte
            timer           var     word
                  
        '   Hardware initialisation
        '   =======================
            '
            '
            pause 10 ' safe start-up delay
            countpulses = 1
            turnOff = 0
            print = 0
            high    led
            
    Main:
            GOSUB   readpuls
            GOSUB   writeDisp
            GOSUB   readExec
            pause 10
        goto main
        
        '        '**************************
    
                '**************************
        writeDisp:
                IF (print) THEN
                  SELECT case countPulses
        
                  CASE 1
                     lcdout $FE,  LcdCls, "Start ALL Syst. "
                  CASE 2
                     lcdout $FE,  LcdCls, "Main Sound Syst."
                  CASE 3
                     lcdout $FE,  LcdCls, "Sub Sound Syst. "
                  CASE 4
                     lcdout $FE,  LcdCls, "Main Disp System"
                  CASE 5
                     lcdout $FE,  LcdCls, "Sub Disp System "
        
                  CASE ELSE
                     lcdout $FE,  LcdCls, " Illigal value  "
                  END SELECT
                 
                  Print = 0
                ENDIF
                RETURN
        
                '**************************
        
                '**************************
        readExec:
                IF (exec = 0) THEN
                      lcdout $FE,  LcdLine2, "  Starting Up   "
                        gosub set
                      GOSUB logOff
                      lcdout $FE,  LcdLine2, "  Shuting Down  "
                        gosub clr
                      lcdout $FE,  LcdLine2, "                "
            
                ENDIF
        
                RETURN
        
        '        '**************************
        
        '        '**************************
        readPuls:
                IF(clock = 0) THEN
                  IF (stat) THEN
                    countpulses = ((countpulses - 1)//5)+1'(countpulses - 1) MIN 1'((countpulses - 1)//5)
                  ELSE
                    countpulses = ((countpulses + 1)//5)+1'(countpulses + 1) MAX 5'((countpulses + 1)//5)
                  ENDIF
                  print = 1
                  high led
                  PIE1.0 = 1
                  again:  IF clock = 0 THEN GOTO again
                  
                  high led
                ENDIF
                RETURN
            
        '        '**************************
        
        '        '**************************
        set:
                    read countpulses*2, a
                    read countpulses*2+1, b
                    
                    for idx = a to b
                      read idx,c
                      'SEROUT2 txPin, baud,[13,(c dig 1),"S",(c dig 0)+48,((13 + (c dig 1) + "S" + 48+(c dig 0))^$FF)+1]
                      hserout [13,(c dig 1),"S",(c dig 0)+48,((13 + (c dig 1) + "S" + 48+(c dig 0))^$FF)+1]
                      pause 100 
                      'SEROUT2 txPin, baud,[13,(c dig 1),"S",(c dig 0)+48,((13 + (c dig 1) + "S" + 48+(c dig 0))^$FF)+1]
                      hserout [13,(c dig 1),"S",(c dig 0)+48,((13 + (c dig 1) + "S" + 48+(c dig 0))^$FF)+1]
                      pause 1000
                    next
                 RETURN
                 
        '        '**************************
        
        '        '**************************
        clr:
                    read countpulses*2, a
                    read countpulses*2+1, b
                    
                    for idx = b to a step -1
                      read idx,c
                      
                      if ((c dig 2)= 1) then
                        pause 5000
                      endif
                        
                      'SEROUT2 txPin, baud,[13,(c dig 1),"C",(c dig 0) + 48,((13 + (c dig 1) + "C" + 48 +(c dig 0))^$FF)+1]
                      hserout [13,(c dig 1),"C",(c dig 0) + 48,((13 + (c dig 1) + "C" + 48 +(c dig 0))^$FF)+1] 
                      pause 100
                      hserout [13,(c dig 1),"C",(c dig 0) + 48,((13 + (c dig 1) + "C" + 48 +(c dig 0))^$FF)+1]
                      'SEROUT2 txPin, baud,[13,(c dig 1),"C",(c dig 0) + 48,((13 + (c dig 1) + "C" + 48 +(c dig 0))^$FF)+1] 
                      pause 1000
                    next
                 RETURN
                
                '**************************
        
                '**************************
        
        logOff:
                lcdout $FE,  LcdLine2, " All systems GO "
                failsafe = 0
                turnOff = 0
        logOffloop:
                IF (exec = 0) THEN
                   PAUSE 10
           loop1:  IF (exec = 0) THEN loop1
                   IF turnOff THEN
                     RETURN
                   ELSE
                     lcdout $FE,  LcdLine2, "OK, to turn OFF?"
                     PAUSE 200
                     failsafe = 0
                     turnOff = 1
                   ENDIF
                ELSE
                   failSafe = failSafe + 1
                   IF failSafe > 10 THEN
                     turnOff = 0
                     lcdout $FE,  LcdLine2, " All systems GO "
                     PAUSE 10
                     failsafe = 0
                   ENDIF
        
                ENDIF
                PAUSE 100
                GOTO logOffLoop
            
        
        ' Interrupt handler
            Disable                 ' No interrupts past this point
    myint:  if RCIF = 1 then
                hserin[WAIT($01),a]
                b = 0
                while a = $02
                    hserin[a]
                    write b, a
                    b = b + 1
                wend
                
                While RCif         ' Code until I write the right rutine
                    Dump=RCREG
                WEND
                
                lcdout $FE, LcdLine2, " Connected "
            else
                timer = timer+1
                if timer > $FFFE then
                    low led
                    PIE1.1 = 0
                endif
                
            endif
            Resume                  ' Return to main program
            Enable

Similar Threads

  1. RC Servo decoding/encoding using 12F683
    By ScaleRobotics in forum Code Examples
    Replies: 13
    Last Post: - 14th September 2010, 00:49
  2. Instant Int and encoder (Elect. Gearing)
    By boroko in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th November 2009, 02:29
  3. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10
  4. strange int behaviour
    By tom in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th November 2005, 15:41
  5. RC measuring routine Radio PCM
    By jetpr in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th August 2005, 02:18

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