my project Capacitive Sensing LED dimmer 12F1822 via PWM


Results 1 to 40 of 43

Threaded View

  1. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: my project Capacitive Sensing LED dimmer 12F1822 via PWM

    RWRIGHT
    If you put yourcode in code tags its then much easier for us to examine it properly

    this is the way i scan mutiple keys , not sure if your chip has a T1GATE_INT but if it has it makes life easy.

    isr's are best kept short and simple .

    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
    Last edited by richard; - 30th April 2016 at 13:35.

Similar Threads

  1. 16F726 Capacitive sensing module
    By Byte_Butcher in forum General
    Replies: 39
    Last Post: - 15th May 2014, 19:40
  2. Need help setting up Capacitive Sense 12F1822
    By Heckler in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th November 2013, 21:10
  3. Replies: 1
    Last Post: - 6th August 2012, 10:57
  4. Capacitive sensing module on 16f1936
    By grahamg in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 25th April 2010, 14:17
  5. mTouch capacitive sensing
    By jrprogrammer in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 1st November 2008, 22:54

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