pic18f887 event timer


Closed Thread
Results 1 to 19 of 19

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Just for giggles can you post your current code? Preferably in code tags...
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Aug 2005
    Location
    NC, USA
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    here is the entire front end...

    Code:
    @  __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    
    OSCCON = $70 'sets the oscillator speed
    DEFINE OSC 8 'Oscillator speed in MHz
    
    'http://www.picbasic.co.uk/forum/showthread.php?t=3251
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    PORTA = %00000000 ' output logic at power-up
    PORTB = %00000000 ' output logic at power-up
    PORTC = %00000000 ' output logic at power-up
    PORTD = %00000000 ' output logic at power-up
    PORTE = %00000000 ' output logic at power-up
    
    ' Set up serial UART
    define HSER_RCSTA 90H           ' Set Receive Status and control register
    DEFINE HSER_TXSTA 24H           ' set transmit status and control register
    DEFINE HSER_BAUD 19200          ' baud setting   19200  115200
    define HSER_CLROERR 1           ' reset on serial buffer overflow
    
    ' Define Analog parameters
    ADCON1 = %10000000          'Right Justify
    ANSEL = %11111111           'Analog on for AN0-AN7
    ANSELH = %00000000          'AN8-13 off
    
    Define	ADC_BITS 10 	    ' Set number of bits in result
    Define	ADC_CLOCK 3	        ' Set clock source (3=rc)
    Define	ADC_SAMPLEUS 10	    ' Set sampling time in uS
    
    ' Alias pins  (0=Output, 1=Input)
    L1      VAR PORTC.5 :TRISC.5 = 0
    L2      VAR PORTD.2 :TRISD.2 = 0
    L3      VAR PORTD.1 :TRISD.1 = 0
    L4      VAR PORTD.0 :TRISD.0 = 0
    L5      VAR PORTC.1 :TRISC.1 = 0
    
    Sp      var PORTC.2 :TRISC.2 = 0  'pulsed signal 
    
    S2      var PORTD.5 :TRISD.5 = 1 'mode switch - LCD Select Mode
    S3      var PORTD.4 :TRISD.4 = 1 'mode switch - LCD Light 
    S1      var PORTD.7 :TRISD.7 = 1 'mode switch - Plus 
    S5      var PORTD.6 :TRISD.6 = 1 'mode switch - Minus 
    
    S8      var PORTB.4 :TRISB.4 = 1 'Pelco-D board - Zoom
    S11     var PORTB.5 :TRISB.5 = 1 'Peclo-D board - Zoom
    
    S7      var PORTB.1 :TRISB.1 = 1 'RC board - Mast
    S10     var PORTB.3 :TRISB.3 = 1 'RC board - Mast
    
    S6      var PORTB.2 :TRISB.2 = 1 'Video Select
    
    'Define RAM
    i               var     byte
    j               var     byte
    RC_Mode         var     Bit  'Flag to switch back and forth from arm and drive funtions
    S2_Rel          var     BIT  'flag to see if switch is realsed
    S6_Rel          var     BIT  'flag to see if switch is realsed
    Mode_Debug      var     bit  'Flag for LCD Debug Mode
    Mode_Debug1     var     bit  'Flag for LCD Debug Mode
    LCD_msg         var     byte 'Counter to reset LCD message Display
    wsave           VAR     BYTE $70 SYSTEM 'value required for interupt
    PreLoad         VAR     WORD 'Preload value for timer interupt
    PreLoad =  21537 
    
    JOY1X           var     word    ' Analog Values
    JOY1Y           var     word
    JOY2X           var     word
    JOY2Y           var     word
    P1              var     word
    Battery         var     word    ' Battery voltage analog
    Battery_r       var     word    ' battery voltage remainder
    Batt_div        con     660     ' scaling value to get Volts
    Batt_Alarm      con     480     ' approx 7.2V
    Batt_Stop       con     430     ' approx 6.5V
    Batt_stop1      var     byte
    Batt_beep       var     byte
    Lights_Last     var     BIT
    Video_Mode      var     BYTE
    Video_Changed   VAR     BYTE
    
    JOY1X_Trim      var     Byte 'trim value 128 = neutral trim, 0=-128, 256=128
    JOY1Y_Trim      var     Byte 
    JOY2X_Trim      var     Byte 
    JOY2Y_Trim      var     Byte 
    Temp_Trim       var     BYTE
    
    JOY1X_GainH     con 6  'Gain for High end of stick 50-130% (5-13)
    JOY1X_GainL     con 6  'Gain for Low end of stick 50-130% (5-13)
    JOY1Y_GainH     con 6
    JOY1Y_GainL     con 6
    JOY2X_GainH     con 6
    JOY2X_GainL     con 6
    JOY2Y_GainH     con 6
    JOY2Y_GainL     con 6
    P1_GainH        con 10
    P1_GainL        con 10
    
    JOY1X_Max       con 1400  'pan
    JOY1X_Min       con 800   'pan
    JOY1Y_Max       con 1400  'tilt
    JOY1Y_Min       con 800   'tilt 
    JOY2X_Max       con 1400 
    JOY2X_Min       con 800
    JOY2Y_Max       con 1400
    JOY2Y_Min       con 800
    P1_Max          con 1850  'Aux Tilt
    P1_Min          con 450   'Aux Tilt
    
    Pulse_Start     con     400 '400us - fudge: Pulse Start (high) + chan pulse (low) = Total chan pulse
    chan_adj        con     9 'fudge factor for pulses (used a scope to come up with value)
    Chan_Ctr        con     1100
    Chan1           var     word 'Aile
    Chan2           var     word 'Elev
    Chan3           var     word 'Thro
    Chan4           var     word 'Rudd
    Chan5           var     word 'Gear
    Chan6           var     word 'Aux1
    Chan7           var     word 'Aux2
    Chan8           var     word 'Aux3
    Chan1f          var     word 'Aile
    Chan2f          var     word 'Elev
    Chan3f          var     word 'Thro
    Chan4f          var     word 'Rudd
    Chan5f          var     word 'Gear
    Chan6f          var     word 'Aux1
    Chan7f          var     word 'Aux2
    Chan8f          var     word 'Aux3
    
    'Reverse Bits, Channel , Mode 1 (0=Normal, 1=Reverse)
    Chan1_1R        con     0 'Drive Turn 
    Chan2_1R        con     1 'Drive Speed
    Chan3_1R        con     0 'Camera Tilt
    Chan4_1R        con     0 'Camera Pan
    Chan5_1R        con     1 'Aux Camera Tilt
    
    'LCD Constants
    LCD_CLR         con 88 'clear
    LCD_INSTR       CON 254 'instruction command
    LCD_L           con 71 'move curser to position 71 [column] [row]
    LCD_H           CON 72 'move curser home
    LCD_BL1         con 66 'backlight on, follow by minutes
    LCD_BL0         con 70 'backlight off
    
    ASM
    INT_LIST  macro    ; IntSource, Label, Type, ResetFlag?
            INT_Handler TMR1_INT, _RC_Pulse, PBP, yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = %00000001           ; Prescaler = 1:1, TMR1ON
    TMR1L = PreLoad.LowByte
    TMR1H = PreLoad.HighByte    ; preload to give 22mS interrupts (at 1:1)
    
    ' /////////////////////////////////////////////////////////////////////////////
    ' Begin
    ' /////////////////////////////////////////////////////////////////////////////
    
    high l1: pause 50: high l2: pause 50: high l3: pause 50: high l4: pause 50: high l5: pause 50 
    low l1: pause 50: low l2: pause 50: low l3: pause 50: low l4: pause 50: low l5: low 50
    
    'trim values retreived from eeprom
    gosub Sub_Read_EEprom
    
    if JOY1X_Trim = 255 and JOY1Y_Trim = 255 then   'means things are zeroed out (reprogrammed), so set defaults
        High L5: pause 250: low L5
        JOY1X_Trim = 128 
        JOY1Y_Trim = 128 
        JOY2X_Trim = 128 
        JOY2Y_Trim = 128 
        gosub Sub_Write_EEprom
    endif
    
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    ' /////////////////////////////////////////////////////////////////////////////
    ' Main Loop
    ' /////////////////////////////////////////////////////////////////////////////
    mainloop: ' Main program loop

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    PORTA = %00000000 ' output logic at power-up
    PORTB = %00000000 ' output logic at power-up
    PORTC = %00000000 ' output logic at power-up
    PORTD = %00000000 ' output logic at power-up
    PORTE = %00000000 ' output logic at power-up
    Try setting the TRIS registers here
    TRISA = xxx
    TRISB = xxx
    _ _ _ _ _ _
    Dave
    Always wear safety glasses while programming.

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