Beginner in need of help !!


Results 1 to 40 of 72

Threaded View

  1. #31
    Join Date
    Jan 2015
    Posts
    45


    Did you find this post helpful? Yes | No

    Default Re: Beginner in need of help !!

    Hi guys, okay I've been having a mess today & I am quite happy with myself. I managed to use the comparator successfully, now I have added a button into the routine.

    It is all doing what I want it to but I am having this big issue with de-bouncing how do I sort this out, what is the best way? Do I need to read the button in a different way?

    Here is the code -

    Code:
    'PIC 12F683
    
    #CONFIG 
       __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 4 '4mhz ocsillator
    ANSEL = %00000001 'pin 7 analog
    CMCON0 = %00011110 'comparator mode
    VRCON = %10100000 'voltage reference
    TRISIO = %00101111 'pin 2,4,5,6,7 input
    
    PAUSE 50 'wait for hardware to settle
    
    ON INTERRUPT GOTO int1 'interrupt handler is int1
    INTCON = %11001000 'enable GIE and GPIE; clear GPIF
    PIE1 = %00001000 'enable comparator interrupt
    IOC = %00001000 'pin 3 ioc
    
    RTPOT VAR CMCON0.6 'right trigger pot
    RTBITTEST var bit 'trigger debug test bit. Set/Clear in ISR and Check in main
    
    BUT VAR GPIO.3 'tactile button
    BUTBITTEST VAR BIT 'button test bit
    
    
    RTBITTEST = RTPOT 'initial reading
    
    BUTBITTEST = 0 'read 0 to start
    
    
    ENABLE
    main:
    
    IF RTBITTEST = 1 THEN
    GOTO RAPID
    ENDIF
    
    IF RTBITTEST = 0 THEN
    GOTO SLEEPY
    ENDIF
    
    GOTO main
    
    
    ENABLE
    RAPID:
    
    LOW GPIO.0 
    PAUSE 70
    TRISIO.0 = 1 
    PAUSE 70
    
    IF RTBITTEST = 0 THEN
    GOTO SLEEPY
    ENDIF
    
    IF BUTBITTEST = 1 THEN
    GOTO FLASH
    ENDIF
    
    GOTO RAPID
    
    
    ENABLE
    SLEEPY:
    
    HIGH GPIO.5
    PAUSE 1000
    TRISIO.5 = 1
    PAUSE 1000
    
    IF RTBITTEST = 1 THEN
    GOTO main
    ENDIF
    
    GOTO SLEEPY
    
    
    ENABLE
    FLASH:
    
    HIGH GPIO.5
    PAUSE 300
    TRISIO.5 = 1
    PAUSE 300
    
    IF BUTBITTEST = 1 THEN
    GOTO RAPID
    ENDIF
    
    GOTO FLASH
    
      
        
    DISABLE 'disable interrupts in handler
    int1:
        
    if PIR1.3 = 1 then  'Comparator Interrupt fired (must be cleared before resume)
    RTBITTEST = RTPOT
    ENDIF
    
    IF IOC.3 = 1 THEN
    BUTBITTEST = BUT
    ENDIF 
    
    INTCON =%11001000 
    PIR1 = %00000000 'reset CMIF
    IOC = %00000000 'reset IOC.3
    RESUME 'resume to where left off
    ENABLE 'enable interrupts
    Last edited by robbo78; - 31st January 2015 at 18:41.

Similar Threads

  1. Beginner help!
    By Recognize in forum General
    Replies: 14
    Last Post: - 26th April 2012, 14:55
  2. pic24 beginner
    By robertpeach in forum General
    Replies: 23
    Last Post: - 13th August 2009, 11:57
  3. need help! to beginner
    By emilhs in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 6th May 2009, 18:44
  4. Beginner at PB
    By alphahr in forum Off Topic
    Replies: 1
    Last Post: - 21st April 2008, 17:43
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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