Problems with 12F675


Closed Thread
Results 1 to 40 of 67

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    The value for long press button it's a little to big. I want to reduce him. So,
    Please, help :
    Timer1 = 3037 ' 1 second
    Timer1 = ? ' for 0.5 sec
    ' for 0.6 sec
    ' for 0.7 sec
    ' for 0,8 sec
    Thanks !

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    3037 with a prescaler of 1:8, sets Timer1 to 500mS periods.
    2 of those periods are counted to reach 1 second.

    To calculate the number for any other time period, download mister-e's calculator ...

    PicMultiCalc v1.3.1
    http://www.picbasic.co.uk/forum/atta...achmentid=2957

    In the "Timer Helper" app, set the time to 300ms and it shows the reload value as 28037. Two 300ms periods would give you a total time of 600ms.

    Set it to 500mS and you'll see where I got the original number.

    Any other period can be calculated easily.
    <br>
    DT

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    Thank You !

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    As a supplement measure of safety I try to re-define the "check procedure" : if vs > 270 OR "time elapsed from but(1 or 2) = 1, no matter if long/short press" > 10 seconds then low rel . But, of course , the code not react as I wish...What I do -again- wrong ?! Thanks in advance for reply !
    Code:
    '****************************************************************
    '*  Name    : THE_BUTON_sleep.BAS                         *
    '****************************************************************
    '
    '
    '
    @ DEVICE PIC12F675, intrc_osc_noclkout, wdt_off, pwrt_on, mclr_off, bod_off
    
    INCLUDE "Elapsed.bas"
    
    DEFINE OSC  4
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    
    CMCON = 7
    OPTION_REG  = %10000110
    TRISIO  = %00011110
    ANSEL = %00011000
    ADCON0 = %10001101
    
    GIE var intcon.7 ' global interrupt enable 1=on ; 0=off
    gpie var intcon.3 'port change interrupt enable 1=0n ; 0=off
    gpif var intcon.0 'port change interrupt flag bit
    
    adval var Word
    vt var word
    u  var byte
    cnt var byte
    but1 var gpio.3
    but2 var gpio.2
    rel1  var gpio.5
    rel2  var gpio.0
    
    Timer1    VAR WORD EXT :@Timer1 = TMR1L
    TMR1ON    VAR T1CON.0
    TMR1IF    VAR PIR1.0
    T1Count   VAR BYTE
    LongPress VAR BIT
    T1CON = %00110100
    
    timpulUP    var byte
    
    
    u=0
    cnt=0
    GIE=0
    GPIE=1
    IOC.2=1   ' int-on-change for GPIO.2 enabled
    IOC.3=1   ' int-on-change for GPIO.3 enabled
    
    but1=0
    but2=0
    rel1=0
    rel2=0
    
    timpulUP=0
    Gosub ResetTime    ' Reset Time to  0d-00:00:00.00
    
    pause 100
    
    main:
      rel1=0
      rel2=0
    @ sleep
      pause 100
      Timer1    = 3037
      T1Count   = 0
      LongPress = 0
      
      btn1:                   'actionare buton up
      
      if but1=1 and rel2=0  then
      
      'this lines added ----------------
        Gosub StartTimer   ' Start the Elapsed Timer
          IF SecondsChanged THEN
            SecondsChanged = 0
            IF Seconds = 10 THEN  
               TimpulUP=1
               
                Gosub ResetTime    ' Reset Time to  0d-00:00:00.00    
            ENDIF
          ENDIF
      '----------------------------------  
               high rel1
               TMR1ON = 1 
               pause 20
                                
               while but1=1
               call check
               wend
               IF LongPress THEN Stop_UP
               T1Count = 0        
               pause 20
                                             
               while but1 = 0 and but2 = 0
               call check
               if rel1=0 then
                  GOTO Btn1PressDone
               endif
               wend
        Stop_UP:
               LOW rel1
      
               while but1=1  OR but2 = 1
               wend
               pause 100
      endif
      GPIF=0  'Clear ort change interrupt flag
      
      Btn1PressDone:
      
      
      btn2:               ' actionare buton down
      'this lines added ----------------
        Gosub StartTimer   ' Start the Elapsed Timer
          IF SecondsChanged THEN
            SecondsChanged = 0
            IF Seconds = 10 THEN  
               TimpulUP=1
               
                Gosub ResetTime    ' Reset Time to  0d-00:00:00.00    
            ENDIF
          ENDIF
      '----------------------------------  
      if but2=1 and rel1=0  then
               high rel2 
               TMR1ON = 1 
               pause 20
                       
               while but2=1
               call check
               wend
               IF LongPress THEN Stop_Down        
               pause 20                          
              
               while but2 = 0  and but1 = 0
               call check
               if rel2 = 0 then
                 GOTO Btn2PressDone
               endif
               wend
        Stop_Down:
               low rel2  
      
               while but2=1 or but1=1
               wend
               pause 100
      endif
      GPIF=0  'Clear ort change interrupt flag
      Btn2PressDone:
       
    GOTO MAIN
    
    check:          ' verificare pentru supracurent
      adcin 3, adval
       vt=adval * 5000
       vt=div32 1023
      
      for cnt = 1 to 5
              if vt > 270 or timpulUP=1 then      
                  u=u+1
                          if u > 5 then
      	                  gpio.0=0
                          gpio.5=0
                          endif
                  pause 50
                  goto check            
              else
                  u=0
      Gosub ResetTime
              endif
      next cnt
      
      IF TMR1IF then
          TMR1IF  = 0
          Timer1  = 3037
          T1Count = T1Count + 1
          if T1Count = 2 then 
            TMR1ON = 0
            T1Count = 0
            LongPress = 1
          endif
      ENDIF
    
    return
    
    
    end             ' of program
    Last edited by fratello; - 22nd April 2010 at 18:13. Reason: Hope I explain meaning...

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    I discover some errors in the code I posted yesterday.
    Code:
      btn1:                   'actionare buton up
      
      if but1=1 and rel2=0  then
      
      'this lines added ----------------
        Gosub StartTimer   ' Start the Elapsed Timer
          IF SecondsChanged THEN
            SecondsChanged = 0
            IF Seconds = 10 THEN  
               TimpulUP=1 
            ENDIF
          ENDIF
      '----------------------------------  
               high rel1
               TMR1ON = 1 
               pause 20
                                
    '----------------------- // ---------------------------------------
    '----------------------- // ---------------------------------------  
      
      btn2:               ' actionare buton down
      
      if but2=1 and rel1=0  then
      
      'this lines added ----------------
        Gosub StartTimer   ' Start the Elapsed Timer
          IF SecondsChanged THEN
            SecondsChanged = 0
            IF Seconds = 10 THEN  
               TimpulUP=1
            ENDIF
          ENDIF
      '----------------------------------  
               high rel2 
               TMR1ON = 1 
               pause 20
                       
    '----------------------- // ---------------------------------------
    '----------------------- // ---------------------------------------  
    
    check:          ' verificare pentru supracurent
      adcin 3, adval
       vt=adval * 5000
       vt=div32 1023
      
      for cnt = 1 to 5
              if vt > 270 or timpulUP=1 then      
                  u=u+1
                          if u > 5 or timpulUP = 1 then
      	              gpio.0=0
                          gpio.5=0
    				Gosub ResetTime
                          endif
                  pause 50
                  goto check            
              else
                  u=0
      Gosub ResetTime
              endif
      next cnt
      
    '----------------------- // ---------------------------------------
    '----------------------- // ---------------------------------------

    Still not work fine...

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    My previous posts are wrong !
    This is what work good for me ( about 10 seconds) :
    Code:
    btn1:                   			'actionare buton up
      
      if but1=1 and rel2=0  then
               high rel1
               TMR1ON = 1
               pause 20
                                
               while but1=1
               t1Count=T1Count+1
               call check
               wend
               IF LongPress THEN Stop_UP
               T1Count = 0        
               pause 20
                                             
               while but1 = 0 and but2 = 0
               t1Count=T1Count+1
               call check
               if rel1=0 then
                  GOTO Btn1PressDone
               endif
               wend
        Stop_UP:
    idem for btn2
    and :
    Code:
              if vt > 270 o then      
                          u=u+1
                          if u > 5 or T1Count > 100 then
      	              gpio.0=0
                          gpio.5=0				
                          endif
                  pause 50
                  goto check            
              else
                  u=0
    It's correct what I do ? Thanks !
    Last edited by fratello; - 23rd April 2010 at 18:00.

Similar Threads

  1. 12F683 vs 12F675.
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th July 2009, 04:58
  2. LANC code 12F675
    By MikeDD in forum General
    Replies: 4
    Last Post: - 9th May 2008, 05:44
  3. 12F675 cant serout to PC
    By ruijc in forum General
    Replies: 9
    Last Post: - 3rd December 2007, 00:11
  4. USART problems
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 47
    Last Post: - 6th March 2005, 21:45
  5. Serial LCD on 12F675
    By anj in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 31st March 2004, 23:11

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