On Interrupt Goto (for pic18f252 ) Help


Closed Thread
Results 1 to 5 of 5

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Here's what you need. i'm using the internal USART @2400 baud.
    Code:
        '    Pic define
        '    ==========
             ' Using PIC18F2320
             '
             define LOADER_USED 1
             DEFINE OSC 4
             
        '    Hardware definition
        '    ===================
             '
             '
             TRISB=0
             TRISC=%10000000
        
        '    Interrupt definition
        '    ====================
             '
             '
             INTCON = $a0       ' Enable TMR0 interrupts
             T0CON  = %11010101
             On Interrupt Goto  Gettime
             
        '    Serial Communication definition
        '    ===============================
             '
             '
             DEFINE HSER_TXSTA 24h
             DEFINE HSER_RCSTA 90h
             DEFINE HSER_BAUD 2400
             
        '    I/O alias definition
        '    ====================
             '
             '
             PowerLED  VAR PORTB.5 'Pin 26 Red
             StatusLED VAR PORTB.4 'Pin 27 Green
             
        '    Variable definition
        '    ===================
             '
             '
             hour   var byte ' Define hour variable
             minute var byte ' Define minute variable
             second var byte ' Define second variable
             ticks  var byte ' Define pieces of seconds variable
             Delay  var word
             CLEAR       
             
    RsetAll:
        toggle PowerLED 'RED LED
        
             '    Delay loop
             '    ==========
                  '
                  '
                  for delay =1 to 10000
                      pauseus 10
                      next
                      
        goto RsetAll
    
    
        '    Interrupt routine to handle each timer tick
        '    ===========================================
             '
             '
    disable  ' Disable interrupts during interrupt handler
    Gettime: 
        ticks = ticks + 1 ' Count pieces of seconds
        If ticks < 59 Then T1Exit ' 61 ticks per second (16.384ms per tick)
        
        '    One second elasped - update time & display
        '    ==========================================
             '
             '
             ticks = 0
             second = second + 1
             If second >= 60 Then
                second = 0
                minute = minute + 1
                If minute >= 60 Then
                   minute = 0
                   hour = hour + 1
                   Endif
                write 43,hour
                write 44,minute 
                write 45,second 
                Endif
             hSerOut [#hour,":",#minute,":",#second,13,10]    
        
        T1Exit:
               INTCON.2=0 ' clear interrupt flag
    Resume
    enable
    Forget about the INTCON stuff i said before..

    P.S. By writing to internal EEPROM as often as you do, you'll burn it soon, You should consider the use of external EEPROM like FRAM OR by saving your data only when the Voltage goes bellow a certain threshold. For cheapness i'll use the last option.
    Last edited by mister_e; - 13th May 2005 at 05:49.
    Steve

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

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. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 19:54
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  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