A new challenge (I'm in trouble again)


Results 1 to 6 of 6

Threaded View

  1. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default Re: A new challenge (I'm in trouble again)

    Was about end 2007 to 2008 ...

    not sure it has been lost ...

    Wow !!! got it in my archives ( 04/2008 )

    Code:
    '@ device pic12f675,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_off, bod_on
    @    __config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _WDT_OFF &_BODEN_ON & _MCLRE_OFF & _CP_OFF
     
    '*****************************************************************************
    'Config
    '*****************************************************************************
     
    'OSCCON  = %01100110
    CMCON  = %00000111     ' Disable comparator
    VRCON   = %00000000     ' disable
    ADCON0  = %11100000
    ANSEL   = %10000000
    '*****************************************************************************
    '       I/Os
    '*****************************************************************************
    GPIO    = %00000000   ' All outputs low
    TRISIO  = %00000000      ' no inputs 
    '*****************************************************************************
    'Aliases
    '*****************************************************************************
    BODbit   var GPIO.0
    PORbit   var GPIO.1
    BOD   var GPIO.2
    LED   var GPIO.4
    '*****************************************************************************
    ' Init vars
    '*****************************************************************************
    Selection var Byte
    Ton   var Word
    Toff  var Word
    '*****************************************************************************
    Coldstart:
    '*****************************************************************************
       
    IF PCON.1 = 0 and PCON.0 = 0 THEN BODbit = 1 'BROWN OUT RESET BIT
    IF PCON.1 = 0      THEN
      PORbit = 1         'POWER ON RESET BIT
                 ' For debugging purpose only !!!
                 
      Selection = 1        'Lights LED @ 25%
    ENDIF
    PAUSE 1000
    GPIO = 0
    IF PCON.1 = 1 AND PCON.0 = 0 THEN    'PCON.0 = BOD ;PCON.1 = POR
              
        BOD  = 1              'GPIO.1 red led PIN6 shows a BOD state
        PAUSE 1000        ' For debugging purpose only !!!
        GPIO  = 0
        
        Selection =  ( Selection + 1 )// 5
        
        
    ENDIF
    PCON.1 = 1
    PCON.0 = 1
    '*****************************************************************************
    'Program choice
    '*****************************************************************************
    SELECT CASE Selection
     CASE 0
       Ton = 0   ' Stop
     
     CASE 1 
      Ton = 500  ' 25%
     
     CASE 2 
      Ton = 700  ' 50%
     
     CASE 3 
      Ton = 870  ' 75%
     
     CASE 4 
      Ton = 1000  '100%
     
    END SELECT
    
     
    '*****************************************************************************
    'Power Drive
    '*****************************************************************************
    Toff  = 2000 - Ton
    IF Ton = 0  THEN       ' LED OFF
     LED = 0
     @ SLEEP       ' IF Power = 0 then snore !!!
     @ NOP        ' and wait for a Power off ...
             ' That ALSO saves the batt ...
    ENDIF
          
    'NOTE : WAKE UP is achieved by Powering OFF the device ... not the classical way !
    '  !!! WDT MUST be OFF !!!
             
    IF Ton = 1000  THEN      ' LED @ 100%
     LED = 1 
      
     WHILE 1       ' Endless loop until power Off !!!     
        WEND
        
    ENDIF
    WHILE 1        ' Soft PWM @ 500Hz until power OFF
     LED  = 1
     PAUSEUS Ton
     LED  = 0
     PAUSEUS Toff
     
    WEND
    END
    have fun ...

    Alain
    Last edited by Acetronics2; - 19th February 2012 at 14:18.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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