RichardT1GATE

Code:
'****************************************************************
'*  Name    : CAPSENSE.BAS                                      *
'*  Author  : RICHARD                                           *
'*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 10/20/2011                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :      12f1822                                      *
 '                                                              *
'****************************************************************

'#DEFINE DBUG 1                            
#CONFIG
   __config _CONFIG1, _WDTE_ON    & _FOSC_INTOSC   &_MCLRE_ON    &_PWRTE_ON 
   __config _CONFIG2,              _LVP_OFF 
#ENDCONFIG

include "dt_ints-14.bas"
include "REENTERPBP.bas"
Include "modedefs.bas" 
asm

INT_LIST macro
      INT_HANDLER T1GATE_INT, _TB1, PBP,YES
      endm
      INT_CREATE
ENDASM

@Timer1=TMR1L 
 THRESH CON 4000   'mult by 4 for 4mhz clk
 CNT VAR WORD   'TIMER1 OUTPUT
 FLG VAR BYTE    'GOT A KEY 
 KP VAR BYTE     'WHICH KEY
 Timer1 VAR WORD EXT 
 PW  VAR WORD   ; PULSEWIDTH

DEFINE OSC 16
DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 0
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0             


   OSCCON=$7a       '16mhz int osc
   CPSCON0 = %10001100      'high range
   CPSCON1 = 2 'cps ch 2
   WPUA   = %00000000 
   ANSELA=  $14    'an4 ans an2 activated
   TRISA =   %011110      'gpio.0 output
   OPTION_REG=$C7      'edge int. prescale 1:256
   PIE1.7=1   'timer1 gate interrupt
   T1GCON=$E1    ' single shot timer0 overflow as input
   T1CON=%11000101   'capsense as input no prescale no sync
   INTCON= $C0       'peripheral interrupts
   PW=512
   APFCON.0=1
   LATA.0=1
   t2con=7 



#IFDEF  DBUG 
    LED VAR LATA.5
    LED=1 
    pause 2000
    Debug "Start",13 ,10
    LED=0
    pause 500 
#ENDIF 
   ccp1con=12
   CCPR1L=128

 FLG=0 



MAIN:
    IF FLG.1=1 THEN 
        IF KP = 2 THEN
           PW= (PW+64)  MIN 1023
        ELSE     'MUST BE THE OTHER ONE    
           PW = PW-64
           IF PW.15 THEN PW=0 
        ENDIF
        CCPR1L = PW>>2;
        ccp1con=12|((PW&3)<<4);
        #IFDEF  DBUG 
            debug #CNT,9,"KEY ",#KP,13,10 
            debug #PW,13,10 
        #ENDIF
        PAUSE 300
        PIR1.7=0 'clr   int flag
        FLG=0       'clr    key pressed flags
    ENDIF
GOTO MAIN 


TB1:
 T1CON.1=0 'DISABLE TILL REQ
 ;LED=!LED
 CNT=TIMER1

 IF CNT <  THRESH  THEN    '   KEY DETECTED  
  FLG.1=1
  KP=CPSCON1 
 ENDIF 
 CPSCON1  =CPSCON1  ^ 1    ;check next key  CPS2 OR CPS3
 TIMER1=0

 T1CON.1=1       'CLEAR ALL AND START AGAIN
@ INT_RETURN
Page last modified on April 01, 2018, at 11:44 PM