newbe wants to store in 16f887 eeprom help


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Sep 2008
    Posts
    15

    Default newbe wants to store in 16f887 eeprom help

    I am using a DTMF decoder with the 16f887 chip. The decoder circuit works great which and simply runs a program, and that works great. is there a statement that can tell the e prom in the 16f887 chip to run a goto routine r something like that. I want the e prom to hold this in memory forever and always run this new routine. then upon another DTMF command, it will go back to the normal routine that it started with. The DTMF part of this is solved. But cannot figure the e prom storage part of it. Thanks Leon

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,040


    Did you find this post helpful? Yes | No

    Default Re: newbe wants to store in 16f887 eeprom help

    What about GOSUB the special routine IF you get that DTMF command, ELSE GOSUB the regular routine?

    You can add more routines in the IF later for extra DTMF commands.

    Robert

  3. #3
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: newbe wants to store in 16f887 eeprom help

    I suspect you need SELECT CASE in the program not the eprom space which is used for DATA storage.

    I'm guessing you are using the tones as a control method. So you want a single tone or combination of tones to do something.

    You need to save the output of the tone decoder to a variable then use the variable result to Select Case . Each CASE can have the code you want to run.

    It's in the PBP manual.
    Last edited by tasmod; - 21st June 2012 at 15:11.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,040


    Did you find this post helpful? Yes | No

    Default Re: newbe wants to store in 16f887 eeprom help

    Eeprom is useful if your device powers down and up and you want continuity in your logic.

    Store your variable to eeprom before shutting down,then read it after power up and return it in a variable.

    Robert

  5. #5
    Join Date
    Sep 2008
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Re: newbe wants to store in 16f887 eeprom help

    Hi Demon, sounds like you are smart. What you are explaining makes sense. Yes, the DTMF decoder output goes to 4 ports of the 16f877. It is easy to do, If portx and portx and portx and portx=1 then decode or something like that. I do have the DTMF decoder and chip to work great. But I am trying to learn how to write the basic code to get the eprom to store this and turn on a port that will always
    upon 16f887 power up (once activated)will always turn on this port until a different(reset) DTMF code is received. Once the reset DTMF code is received, this port will not turn on up power up. I have tried with no success to get this to work. Any help on code to do this. Point me in the right direction. Thanks so much, Leon

  6. #6
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: newbe wants to store in 16f887 eeprom help

    I know I'm not smart enough but here's a small program i wrote to generate frequencies.

    Note that it reads and stores values both previous and new values to eeprom.

    Code:
    '****************************************************************
    '*  Name    : freqgen.BAS                                       *
    '*  Author  : Rob Lane                                          *
    '*  Notice  : Copyright (c) 2011                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 09/08/2011                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
        eeprom 4,[$10,$0e]   ' program in first run freq value 3600Hz (lowest)
        
        include "Modedefs.bas"      ' for lcd baud rate
        
        define OSC 10               ' for lcd baud rate 9600
    
    
    Duty        var byte         'duty cycle value (max 255)
    Freqval     var word         'frequency variable
    A2          var byte         'Button' variable
    Counter1    var byte
    PercVal     var word
    PercVal2    Var byte
            '      Control Buttons/Lines
            '      ----------------------
    
        TRISA=%00011111      ' button pins
        TRISB=%00000000      ' port b as outputs
       
        CMCON=7              ' comparator ports to digital
        
        Pause 500 ' lcd to settle
        
        read 4,Freqval.byte0    'read previously stored freq
        read 5,Freqval.byte1    'from eeprom at power up
        SERout PortB.7,N9600,[254,1]   'lcd CLS
        pause 10                ' needed after cls command
        Duty=64                 ' set HPWM duty cycle
        A2=0                    ' set button debounce
        hpwm 1,Duty,Freqval         'output freq to hardware pwm channel 1 
        PercVal=(Duty*1000)/256 
        PercVal2=PercVal dig 0
        PercVal=(Duty*100)/256
        
    mainloop:
        serout PortB.7,N9600,[254,128]   'lcd line 1 home
        SERout PortB.7,N9600,["Frequency: ",#Freqval ]
        serout PortB.7,N9600,[254,192]   'lcd line 1 home
        SERout PortB.7,N9600,["Duty cycle: ",#PercVal ,".",#PercVal2,"%" ]
        Button PortA.0,0,255,0,A2,1,upfaster    
        Button PortA.1,0,255,0,A2,1,downfaster
        Button PortA.3,0,255,0,A2,1,upslow
        Button PortA.4,0,255,0,A2,1,downslow
        high PortB.0       '==  LED on
        pause 500          '==  blink led to show in loop
        low PortB.0        '==  LED off
        pause 500          '==  for testing purposes
        goto mainloop          
      
         
    freqgenoff: 
        TRISB=%00001000    'turn off hpwm register
        goto mainloop
        
    freqsave:
        write 4,Freqval.byte0   'save freq to eeprom
        write 5,Freqval.byte1   'at button press end and
        goto mainloop           'return to main loop  
        
    'UP FAST ===============================    
    upfaster:
        read 4,Freqval.byte0
        read 5,Freqval.byte1     
           
    upfast:
        if PortA.0=1 then freqsave  ' 1st trap exit to 'save' loop
        hpwm 1,Duty,Freqval         'output freq to hardware pwm channel 1 
        serout PortB.7,N9600,[254,128]
        SERout PortB.7,N9600,["Frequency: ",#Freqval ]
        Freqval=Freqval+100       'increment freq
        if Freqval>=32000 then freqval=32000  'hold if at highest freq figure
        pause 5                          'slows looping
        if PortA.0=1 then freqsave          '2nd trap exit to 'save' loop 
        goto upfast
        
     'DOWN FAST ===============================    
    downfaster:
        read 4,Freqval.byte0
        read 5,Freqval.byte1     
           
    downfast:
        if PortA.1=1 then freqsave  ' 1st trap exit to 'save' loop
        hpwm 1,Duty,Freqval         'output freq to hardware pwm channel 1 
        serout PortB.7,N9600,[254,128]
        SERout PortB.7,N9600,["Frequency: ",#Freqval ]
        Freqval=Freqval-100       'decrement freq
        if Freqval<=700 then freqval=700  'hold if at highest freq figure
        pause 5                          'slows looping
        if PortA.1=1 then freqsave          '2nd trap exit to 'save' loop 
        goto downfast   
             
        
    'UP Routine ============================ 
       
    upslow:
        read 4,Freqval.byte0
        read 5,Freqval.byte1     
        counter1=1
           
    slowup:
        For counter1 = 1 to 5       ' if press longer than 5 then speedup
        if PortA.3=1 then freqsave  ' 1st trap exit to 'save' loop
        hpwm 1,Duty,Freqval         'output freq to hardware pwm channel 1 
        serout PortB.7,N9600,[254,128]
        SERout PortB.7,N9600,["Frequency: ",#Freqval ]
        Freqval=Freqval+1       'increment freq
        if Freqval>=32000 then freqval=32000  'hold if at highest freq figure
        pause 500                           'slows looping
        if PortA.3=1 then freqsave          '2nd trap exit to 'save' loop 
        next counter1
        goto frequp
       
    frequp:
        if PortA.3=1 then freqsave  ' 1st trap exit to 'save' loop   
        hpwm 1,Duty,Freqval       'output freq to hardware pwm channel 1 @ 25% duty cycle(64)
        serout PortB.7,N9600,[254,128]
        SERout PortB.7,N9600,["Frequency: ",#Freqval ]
        Freqval=Freqval+10       'increment freq
        if Freqval>=32000 then freqval=32000   'hold if at highest freq figure  
        pause 50                      'slows looping
        if PortA.3=1 then freqsave   '2nd trap exit to 'save' loop or
        if PortA.3=0 then frequp     'loop frequp 
        
    'DOWN Routine ==========================
        
    downslow:    
        read 4,Freqval.byte0
        read 5,Freqval.byte1 
        counter1=1
        
    slowdown:
        For counter1 = 1 to 5
        if PortA.4=1 then freqsave  ' 1st trap exit to 'save' loop
        hpwm 1,Duty,Freqval       'output freq to hardware pwm channel 1 @ 25% duty cycle(64)
        serout PortB.7,N9600,[254,128]
        SERout PortB.7,N9600,["Frequency: ",#Freqval ]
        Freqval=Freqval-1       'decrement freq
        if Freqval<=700 then freqval=700   'hold if at lowest freq figure
        pause 500                           'slows looping 
        if PortA.4=1 then freqsave   '2nd trap exit to 'save' loop              
        next counter1
        goto freqdown 
        
    freqdown:
        if PortA.4=1 then freqsave      
        hpwm 1,Duty,Freqval
        serout PortB.7,N9600,[254,128]
        SERout PortB.7,N9600,["Frequency: ",#Freqval ]
        Freqval=Freqval-10
        if Freqval<=700 then freqval=700  ' hold if at lowest freq figure
        pause 50
        if PortA.4=1 then freqsave
        if PortA.4=0 then freqdown     
     
    end

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts