Cooking Timer Project


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Nov 2010
    Posts
    5

    Default Cooking Timer Project

    Hello Im trying to make a cooking timer following the information
    in this instructables site i have program the pic and power it up ever time
    i do so i just get a blank screen on my lCD any help will be great Thank You.
    I also did a flip the switch to test mode to test the lcd and it works just fine
    im not sure what switch go what way i have try all the off and ons it showed me.
    Thank you,

    http://www.instructables.com/id/Cooking-Timer/


    Code:
    '****************************************************************
    '*  Name    : Time Countdown                                    *
    '*  Author  : Arava                                             *
    '*  Date    : 4/24/2007                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : PIC16F819                                         *
    '****************************************************************
    'BUZZER CONNECTED TO PortB.4
    'START BUTTON CONNECTED TO PortB.5
    'RESET BUTTON CONNECTED TO PortB.0
    'FOOD BUTTONS CONNECTED TO Ports B.1/ B.2 / B.3
    'TIMER BUTTON CONNECTED TO PortA.2
    'LCD CONNECTED TO PortB.6
    'POTENTIOMETER CONNECTED TO PortA.0
    
    OSCCON = %01100100    'set the internal oscillator to 4MHz
    TRISA = %11111111     'make portA all input 
    ADCON1 = %10001110    'make portA.0 analog , all others Digital
    
    output portB.6      ' output to lcd
    OUTPUT portB.4      ' output to buzzer
    input portB.5       ' input start button
    input portB.0       ' input reset button
    input portB.1       ' chicken button input
    input portB.2       ' meat button input
    input portB.3       ' egg button input
    
    include "modedefs.bas"
    DEFINE ADC_BITS 10          ' 10 bit adc conversion
    DEFINE ADC_CLOCK 3          'These difine ADCIN parameters 
    DEFINE ADC_SAMPLEUS 20
    
    '******************** variables***********************
    
    counting var bit      ' 0=not counting. 1=counting in progress.
    secCount var word     ' counting the seconds wile cooking
    secLoop60 var word
    secRemain var word   ' the time for the countdown
    minRemain var word
    TimeLoop var byte
    cookingTime  var word  ' the time that takes for the food to cook
    
    DeBounce con 10
    start_buttonState var bit         'start button
    reset_buttonState var bit
    c_buttonstate var bit
    m_buttonstate var bit
    e_buttonstate var bit
    timer_buttonstate var bit
    
    weight var byte                  ' between 1-8 pounds
    
    PotNoise con 2                    'potentiometer noise
    PotSignal var word                   'potentiometer signal (0-1012)
    PotSignala var word
    
    LCD var PortB.6
    BUZZER var PortB.4
    chic_button var portB.1
    meat_button var portB.2
    egg_button var portB.3
    start_button var portB.5
    reset_button var portB.0
    timer_button Var portA.2
    
    '***************************setup*************************************
    Setup:
        PAUSE 100
        serout2 LCD,396,[12]            'clear LCD screen
        pause 10
        serout2 LCD,396,[17]                  'turn on the LCD backlight
        pause 10
        serout2 LCD,396,["select food type"]  ' prints first instruction
        PAUSE 500                             ' wait for LCD to initiate
        
        counting = 0
        cookingTime  = 0
        secCount = 0
        secRemain = 0
        minRemain = 0
        TimeLoop = 0 
        low BUZZER 
    Goto main
    
    '***************************main*************************************
    ' if counting - keep counting. 
    ' if not - feel for food buttons, if it's not pressed don't do anything.
    ' any other button pressed now - nothing happens
    
    Main:
            
        if counting = 1 then       ' if cooking
            Goto Timer             ' keep counting
        endif
    
        c_buttonstate = chic_button  ' feelFoodButton - feel 4 buttons 
        m_buttonstate = meat_button
        e_buttonstate = egg_button
        timer_buttonstate = timer_button
    
        if c_buttonstate = 1 then                      'if chick button changes ****
                pause 10                               'debounce time
                c_buttonstate = chic_button            'feel the button           
                if c_buttonstate = 1 then              'if the input is real
                        serout2 LCD,396,[12]           'clear LCD screen for countdown
                        pause 5
                        serout2 LCD,396,["chicken", 13, "weight:"]
                        pause 5
                        Goto CalculateChicken
                endif
        endif
            
        if m_buttonstate = 1 then                      'if meat button changes ****
                pause 10                               'debounce time
                m_buttonstate = meat_button            'feel the button           
                if m_buttonstate = 1 then              'if the input is real
                        serout2 LCD,396,[12]           'clear LCD screen for countdown
                        pause 5
                        serout2 LCD,396,["meat", 13, "weight:"]
                        pause 5
                        Goto CalculateMeat
                endif
        endif
        
        if e_buttonstate = 1 then                      'if egg button changes ****
                pause 10                               'debounce time
                e_buttonstate = egg_button            'feel the button           
                if e_buttonstate = 1 then              'if the input is real
                        serout2 LCD,396,[12]           'clear LCD screen for countdown
                        pause 5
                        serout2 LCD,396,["egg", 13, "level:  "]
                        pause 5
                        Goto CalculateEgg
                endif
        endif
        
        if timer_buttonstate = 1 then                  'if timer button changes ****
                pause 10                               'debounce time
                timer_buttonstate = timer_button       'feel the button           
                if timer_buttonstate = 1 then          'if the input is real
                        serout2 LCD,396,[12]           'clear LCD screen for countdown
                        pause 5
                        serout2 LCD,396,["timer"]
                        pause 5
                        Goto CalculateTimer
                endif
        endif 
    
        gosub FeelResetButton
    Goto main
    
    '***************************CalculateTimer cooking time*************************************
    CalculateTimer:
        'feel potentiometer + calculate var weight
        adcin 0,PotSignal                       'take two readings and compare them
        pause 10                                'with Noise as a measure
        adcin 0,PotSignala                      'a simple way to clean up your singnal
        if PotSignala < PotSignal - PotNoise then
            cookingTime = (PotSignala/4)*60
            serout2 LCD,396,[148,"Time: ", dec cookingTime /60 ,"min"]  'courser to second line pos 0 print weight.
        endif
        if PotSignala > PotSignal + PotNoise then
            cookingTime = (PotSignala/4)*60
            serout2 LCD,396,[148,"Time: ", dec cookingTime /60 ,"min"]
        endif
        
        '***special Feel Start Button timer time   
        start_buttonState =  start_button
        if start_buttonState = 1 then                      'if egg button changes ****
                pause 10                                   'debounce time
                start_buttonState = start_button           'feel the button           
                if start_buttonState = 1 then              'if the input is real
                   pause 5
                   serout2 LCD,396,[148, "Time          "]     'courser to line1 position 0
                   pause 5
                   counting = 1                     'change to counting state
                   goto Timer                       'and start counting
                endif
        endif   
    
        gosub FeelResetButton    
        
    Goto CalculateTimer
    
    '***************************CalculateMeat cooking time*************************************
    CalculateMeat:
        'feel potentiometer + calculate var weight
        adcin 0,PotSignal                       'take two readings and compare them
        pause 10                                'with Noise as a measure
        adcin 0,PotSignala                      'a simple way to clean up your singnal
        if PotSignala < PotSignal - PotNoise then
            weight = PotSignala/126
            serout2 LCD,396,[156, dec weight , "p  "]  'courser to second line pos 8 print weight.
        endif
        if PotSignala > PotSignal + PotNoise then
            weight = PotSignala/126
            serout2 LCD,396,[156, dec weight , "p  "]  'courser to second line pos 8 print weight.
        endif
            
        if weight < 2 then
            cookingTime = 35*60
        else
            cookingTime = (45+((weight-2)*10))*60
        endif              
        
        gosub FeelStartButton                         'go to FeelStartButton
        gosub FeelResetButton    
     
    Goto CalculateMeat
    
    '***************************CalculateChicken cooking time*************************************
    CalculateChicken:
        'feel potentiometer + calculate var weight
        adcin 0,PotSignal                       'take two readings and compare them
        pause 10                                'with Noise as a measure
        adcin 0,PotSignala                      'a simple way to clean up your singnal
        if PotSignala < PotSignal - PotNoise then
            weight = PotSignala/126
            serout2 LCD,396,[156, dec weight , "p  "]  'courser to second line pos 8 print weight.
        endif
        if PotSignala > PotSignal + PotNoise then
            weight = PotSignala/126
            serout2 LCD,396,[156, dec weight , "p  "]  'courser to second line pos 8 print weight.
        endif
        
        if weight < 2 then
            cookingTime = 40*60
        else
            cookingTime = (60+((weight-2)*10))*60
        endif  
        
        gosub FeelStartButton                         'go to FeelStartButton
        gosub FeelResetButton    
     
    Goto CalculateChicken
    
    '***************************CalculateEgg cooking time*************************************
    CalculateEgg:
        'feel potentiometer + calculate var weight
        adcin 0,PotSignal                       'take two readings and compare them
        pause 10                                'with Noise as a measure
        adcin 0,PotSignala                      'a simple way to clean up your singnal
        if PotSignala < PotSignal - PotNoise then
            weight = PotSignala/126
            if weight <=4 then
                serout2 LCD,396,[156, "soft"]  'courser to second line pos 8 print weight.
            else
                serout2 LCD,396,[156, "hard"]
            endif    
        endif
        if PotSignala > PotSignal + PotNoise then
            weight = PotSignala/126
            if weight <=4 then
                serout2 LCD,396,[156, "soft"]  'courser to second line pos 8 print weight.
            else
                serout2 LCD,396,[156, "hard"]
            endif 
        endif
        
        if weight <=4 then
           cookingTime  = 5*60
        else
           cookingTime = 11*60
        endif
    
        'special FeelStartButton for egg state
        start_buttonState =  start_button
        if start_buttonState = 1 then                      'if egg button changes ****
                pause 10                                   'debounce time
                start_buttonState = start_button           'feel the button           
                if start_buttonState = 1 then              'if the input is real
                   pause 5
                   if weight <=4 then
                        serout2 LCD,396,[134, "soft"]  ' courser to line0 position 6
                    else
                        serout2 LCD,396,[134, "hard"]
                    endif 
                    serout2 LCD,396,[148, "Time          "]     'courser to line1 position 0
                    pause 5
                    counting = 1                     'change to counting state
                    goto Timer                       'and start counting
                endif
        endif   
    
        gosub FeelResetButton    
        
    Goto CalculateEgg
    
    '***************************Feel Start Button*************************************    
    FeelStartButton:
        start_buttonState =  start_button
        if start_buttonState = 1 then                      'if egg button changes ****
                pause 10                                   'debounce time
                start_buttonState = start_button           'feel the button           
                if start_buttonState = 1 then              'if the input is real
                   pause 5
                   serout2 LCD,396,[137, dec weight, "p  "] 'courser to line0 position 9
                   serout2 LCD,396,[148, "Time          "]     'courser to line1 position 0
                   pause 5
                   counting = 1                     'change to counting state
                   goto Timer                       'and start counting
                endif
        endif   
    return
    
    '***************************Feel Reset Button*************************************
     'feel reset button
    FeelResetButton:
        'reset_buttonState =  reset_button
       ' if reset_buttonState = 1 then                      'if egg button changes ****
             '   pause 5                                   'debounce time
                reset_buttonState = reset_button           'feel the button           
                if reset_buttonState = 1 then              'if the input is real
                   low BUZZER 
                 '  pause 5
                   goto setup                       'and start counting
                endif
        'endif   
    return
    '**********************************timer********************************************   
    Timer:
        secLoop60 = 0
        while secLoop60 <= 59
            TimeLoop = 0
            
            while TimeLoop <= 99                'counts 100 times  
                TimeLoop = TimeLoop +1          ' 1 miliSec
                gosub FeelResetButton
                pause 10                  
            wend
      
            secCount = secCount +1                        ' add one sec to count
            secRemain = cookingTime - secCount            ' calculates the time remains to cook
            minRemain = secRemain/60
            if secLoop60 = 0 then
                serout2 LCD,396,[155,dec minRemain,":00"]
            else 
                if  secLoop60 > 50 then
                    serout2 LCD,396,[155,dec minRemain,":0", dec 60-secLoop60]
                else
                    serout2 LCD,396,[155,dec minRemain,":", dec 60-secLoop60]
                endif
            endif
            secLoop60 = secLoop60 + 1
            if secCount = 900 then               ' after 15 min
                high buzzer                      ' buzz 5 sec
                pause 5000                      
                secCount = secCount - 5         ' reduce 5 sec from count
                low buzzer 
            endif
            if secCount = cookingTime  then     ' if the food is ready
                while 1=1
                    HIGH BUZZER                      ' make noise with BUZZER
                    pause 5000
                    low BUZZER
                wend
                counting = 0                    ' change counting to off
                goto Setup                      ' go back to start
            endif
        wend      
       
    goto Timer

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default What type of LCD

    Are you sure your LCD is a serial verion and not a standard parallel version ?

    This code seems to use a serial LCD sending data on RB6. If you have a standard LCD it is expecting data on min 4 lines (when in 4-bit mode).

    Code:
    ;----[LCD definitions]------------------------------------------------------
    DEFINE LCD_DREG  PORTB          ' LCD Data port
    DEFINE LCD_DBIT  0              ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB          ' LCD Enable port
    DEFINE LCD_EBIT  5              '     Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB          ' LCD Register Select port
    DEFINE LCD_RSBIT 4              '     Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4              ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2              ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000       ' Command delay time in us 
    DEFINE LCD_DATAUS 50            ' Data delay time in us

  3. #3
    Join Date
    Nov 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Thank you for replying back. This is the LCD that I have

    http://www.parallax.com/Store/Access...0/Default.aspx

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Try a baud mode number of 16780, I think this things are inverted.
    SW1 = ON
    SW2 = OFF
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Nov 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Try a baud mode number of 16780, I think this things are inverted.
    SW1 = ON
    SW2 = OFF

    I will try that. And also this is my first time dealing with pics I have a question also about my set up does it need power to run to the pic? if so what leg its a pic16F819

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by esmore View Post
    I will try that. And also this is my first time dealing with pics I have a question also about my set up does it need power to run to the pic? if so what leg its a pic16F819
    Err yes you need to supply power to the PIC to run it !

    5vdc required

    Have a read of the data sheet http://oap.sourceforge.net/datasheets/PIC16F819.pdf

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