Cooking Timer Project


Closed Thread
Results 1 to 14 of 14
  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

  7. #7
    Join Date
    Nov 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    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
    I look at the diagram pin 14 VDD is my 5volts so does that make pin 5 VSS the ground?

    Thank you for the data sheet

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by esmore View Post
    I look at the diagram pin 14 VDD is my 5volts so does that make pin 5 VSS the ground?

    Thank you for the data sheet
    Yes - Vss should go to GND and Vdd to +5v Without these connections your PIC won't run !

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


    Did you find this post helpful? Yes | No

    Default

    Also look in the manual, section "2.4. It=s Alive".

    This shows the basic/generic setup required. VDD, VSS, MCLR, OSC...
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Nov 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    I was looking over my schematics

    on the lcd display it says its only one wire and it hooks up to the
    RB6/T1OSO/T1CKI/PGC pin is that right?



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


    Did you find this post helpful? Yes | No

    Default

    That's a crap schematic if you don't mind me saying so...

    1) MCLR is left floating - should be pulled high via a resistor between 1K and 10K.
    2) No supply lines to the PIC - as stated Vdd to +5 with Vss to GND
    3) No decoupling capacitor - Place a 0.1uf Capacitor across the supply lines as close to the PIC as possible
    4) IGNORE
    5) IGNORE
    6) No values for the pull down resistors - You need to state what value components are being used - again 1K - 10 K pull up / down resistors are the norm.
    7)IGNORE

    OK ignore some of those comments - I've juts worked out which way the tracks are running --- I'll wake up in a moment !!!


    Can you also state where the 5v is coming from and have you measured it to make sure it is 5v and not 6v or 3v or 8v dc. If you are not sure then use a 7805 regulator to ensure the voltage is as close to 5v dc.
    Last edited by malc-c; - 7th November 2010 at 09:42. Reason: spotted mistake

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


    Did you find this post helpful? Yes | No

    Default

    A big problem I see is the drawing only shows 16 pins on the MCU. the 16F819 has 18 pins at a minimum (PDIP). SSOP and QFN have a few more.

    MCLR... Like Malc said, it needs to be pulled HIGH. Unless it is set as an input then it can be connected as a regular switch. Assuming the switch on the drawing labeled RESET goes to MCLR then it is good as an input but it will not work as a reset. Being it is not in the code as an input I will guess it is intended as a chip reset.

    The LED can be connected as you have it if the configs have the OSC as internal. But we do not see the config settings.

    Being this is your first project I will recommend doing the "Hello World" for MCUs. Make an LED blink. That way you will know how to set everything up. Then build on that. Every time I start a new project I will do a "BLINKY" just to be sure I have the chip working.

    I suggest you read these
    http://www.picbasic.co.uk/forum/cont...o-your-Program
    http://www.picbasic.co.uk/forum/showthread.php?t=561

    See if you can make an LED blink on PORTB.4 at ~1/2 second intervals. Then we can work on getting your project sorted out. But it will not be a copy/paste from the site you linked to.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    As Dave has mentioned, the "blinky" LED test is really the starting point... I too use the same basic test to ensure the PIC is running and that the program has been uploaded to the PIC successfully. Once I know I have a working circuit I then move on a step at a time (connect a switch and see if it's function does what I intended for example).

    16 Pin... How did I miss that - shows I was still half asleep

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


    Did you find this post helpful? Yes | No

    Default

    esmore, were you able to download the code from that site, compile it and upload it to the PIC ?

    The only reason is that the link provided on that site "C:\MyDocuments\Parsons\Spring_07\PComp\code_final \cookingimer_final.txt" would point to a local folder on HIS computer !!!

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