Microwave oven control system with single chip microcomputer

Publisher:huanranLatest update time:2020-12-22 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The microcontroller source program is as follows:

Wendu.h (header file)

#define jump_ROM 0xCC //ds18B20 definition

#define start 0x44

#define read_EEROM 0xBE

void delay(unsigned int N);

void delay_1();

unsigned char Reset(void); //Reset DS18B20

unsigned char read_bit(void); //Read a bit value from DS18B20

void write_bit(unsigned char bitval); //Write one bit to DS18B20

unsigned char read_byte(void); //Read a byte from DS18B20

void write_byte(unsigned char val); // Write a byte to DS18B20


Wendu.c (implementation of Wendu.h)

#include

#include"wendu.h"

sbit DQ = P2^3; //DS18B20 data port


/********************************************************************

* Name: delay()

* Function: Delay, the delay time is about 140US.

* Input: None

* Output: None

***********************************************************************/

void delay_1()

{

        int i,j;

        for(i=0; i<=10; i++)

        for(j=0; j<=2; j++);

}

/********************************************************************

* Name: delay()

* Function: Delay function

* Input: None

* Output: None

***********************************************************************/

void delay(unsigned int N)

{

        int i;

        for(i=0; i}

/********************************************************************

* Name: Reset()

* Function: Reset DS18B20

* Input: None

* Output: None

***********************************************************************/

unsigned char Reset(void)

{

        unsigned char deceive_ready;

        DQ = 0;

        delay(29);

        DQ = 1;

        delay(3);

        deceive_ready = DQ;

        delay(25);

        return(deceive_ready);

}

/********************************************************************

* Name: read_byte()

* Function: Read a byte from DS18B20

* Input: None

* Output: The value read from DS18B20

***********************************************************************/

/********************************************************************

* Name: read_bit()

* Function: Read a bit value from DS18B20

* Input: None

* Output: A bit value read from DS18B20

***********************************************************************/

unsigned char read_bit(void)

{

        unsigned char i;

        DQ = 0;

        DQ = 1;

        for(i=0; i<3; i++);

        return(DQ);

}

/********************************************************************

* Name: write_bit()

* Function: Write a bit to DS18B20

* Input: bitval (the bit value to be written to DS18B20)

* Output: None

***********************************************************************/

void write_bit(unsigned char bitval)

{

DQ=0;if(bitval==1)

DQ=1;

delay(5);

DQ=1;

}

/********************************************************************

* Name: read_byte()

* Function: Read a byte from DS18B20

* Input: None

* Output: The value read from DS18B20

***********************************************************************/

unsigned char read_byte(void)

{

        unsigned char i,m,receive_data;

        m = 1;

        receive_data = 0;

        for(i=0; i<8; i++)

        {

                if(read_bit())

                {

                        receive_data = receive_data + (m << i);

                }

                delay(6);

        }

        return(receive_data);

}


/********************************************************************

* Name: write_byte()

* Function: Write a byte to DS18B20

* Input: val (command value to be written to DS18B20)

* Output: None

***********************************************************************/

void write_byte(unsigned char val)

{

        unsigned char i,temp;

        for(i=0; i<8; i++)

        {

                temp = val >> i;

                temp = temp & 0x01;

                write_bit(temp);

                delay(5);

        }

}


Implementation of the main function

#include

#include"wendu.h"

sbit key1=P1^4; //Matrix keyboard definition

sbit key2=P1^5;

sbit key3=P1^6;

sbit key4=P1^7;

sbit S1=P3^2; //button definition

sbit S2=P3^3;

sbit S3=P3^4;

sbit RS=P2^5; //12864 definition

sbit RW=P2^6;

sbit E=P2^7;

sbit BEEP = P2^0; //Buzzer definition

sbit Hot=P2^1;

unsigned char TMPH,TMPL,key41=1,Temp,T; //temperature constant

unsigned int count1,count2,count3; //time constant

unsigned int countor,m,s; //timing constant

unsigned char button,sound; //other constants

unsigned char code table[]={"0123456789"};


/******************Subroutine Description********************/

void delay_1ms(unsigned int i);      //1ms延时

void delay(); //delay subroutine

void beep(); //bell program

void set(char n); //12864 write instruction subroutine

void weizhi(int hang,int lie); //12864 character display position

void wdata(unsigned char d); //Write data to 12864, single character

void wsdata(char tab[]); //Write data to 12864, string

void scan(); //Scan the first column of the matrix keyboard to determine the input time

void setTemp(); //Temperature setting, using scanning independent keyboard to determine input

void setTime(); //Time setting

void showTime(); //Display time

void chu12864(); //initialize 12864

void chuDS(); //Initialize DS18B20


/************************Main program****************************/

void main() //Main function

{  

        chu12864(); //12864 initialization

        setTemp();

        setTime();  

        while(1)

        {

        chuDS();

                if(Temp==T)                  

                   TR0=1;

                showTemp();                 

            showTime();               

                if(sound==1)

              beep();   

          }  

}

/******************************************/


void time0(void) interrupt 1 using 1 //Timer interrupt program

{

        countor++;

        if(countor==20)

        {

              if(m==0&&s==0) ​​//Countdown

            {

              m=0;

              s=0;

              sound=1;

              Hot=0;

              TR0=0;

             }

                else

                if(s==0)

            { m--;s=59;}

            else

                s--;

     countor=0;

   }

  TH0=(65536-50000)/256;

  TL0=(65536-50000)%256;

}



/************************************************/

void delay_1ms(unsigned int i)      //1ms延时

{

        unsigned char x,j;

        for(j=0;j        for(x=0;x<=148;x++);        

}

/************************************************/

void delay() //delay subroutine

{

  int a,b;

   for(a=0;a<100;a++)

    for(b=0;b<10;b++);

}/************************************************/

void beep() //bell program

{

  unsigned char i;

  for (i=0;i<100;i++)

   {

   delay_1ms(1);

   BEEP=!BEEP;                 //BEEP取反

   }

  BEEP=1; //Turn off the buzzer

}

/************************************************/

void set(char n) //12864 write instruction subroutine

{

  P0=n;

  RS=0;

  RW=0;

  E=0;

  delay();

  E=1;

  delay();

}

/******************************************/

void weizhi(int hang,int lie) //12864 character display position

{

  char a;

  if(hang==1) a=0x80;

  if(hang==2) a=0xc0;

  a=a+lie-1;

  set(a);

}

/******************************************/

void wdata(unsigned char d) //Write data to 12864, single character

{

  RS=1;

  RW=0;

  P0=d;

  E=0;

  delay();

  E=1;

  delay();

}

/******************************************/

void wsdata(char tab[]) //Write data to 12864, string

{

  int i=0;

  RS=1;

  RW=0;

  while(tab[i]!='') //Execute when it is not the end character

   {

     P0=tab[i];

     E=0;

     delay();

     E=1;

     delay();

         i++;

  }

}

/******************************************/

void scan() //Scan the first column of the matrix keyboard to determine the input time

{

P1=0xfe;

  if(key1==0)

   { delay();

     if(key1==1)

    { count1++;        

           beep();

    }

   }

  if(key2==0)

  { delay();

    if(key2==1)

        {

      count2++;

      beep();

        }

  }

  if(key3==0)

  {  delay();

    if(key3==1)

        {

      count3++;

          beep();

          }

  }

  if (key4==0)

   {

     key41=0;        

         beep();

   }

}

/******************************************/

void setTemp() //Temperature setting, using scanning independent keyboard to determine input

{

        while(1)

        {

                P3=0xff;

                if(S1==0) button=1; //20 degrees

                if(S2==0) button=2; //30 degrees

                if(S3==0) button=3; //50 degrees

                if(button==1)

        {

                T=20;

                weizhi(2,5);

                wdata(table[2]);

                delay_1ms(1);

                weizhi(2,6);

                wdata(table[0]);

        }

        if(button==2)

        {

                T=30;

                weizhi(2,5);

                wdata(table[3]);

                delay_1ms(1);

                weizhi(2,6);

                wdata(table[0]);

        }

        if(button==3)

        {

                T=50;

                weizhi(2,5);

                wdata(table[5]);

                delay_1ms(1);

                weizhi(2,6);

                wdata(table[0]);

        }

        if(button==1||button==2||button==3)

                break;

        }

}

/****************************************/

void setTime() //Time setting

{

  while(1)

    {

      scan();

      if(key41==0)

        break;

    }  

m=(1*count1)+(2*count2)+(5*count3); //Calculate the set time

Hot=1;

}

void showTime() //Display time

{

  weizhi(2,11);

  wdata(table[m/10]); //Display points

  delay_1ms(1);

  weizhi(2,12);

  wdata(table[m%10]);

  delay_1ms(1);

  weizhi(2,13);

  wdata(':');

  delay_1ms(1);

  weizhi(2,14);

  wdata(table[s/10]); //Display seconds

  delay_1ms(1);

  weizhi(2,15);

  wdata(table[s%10]);

  delay_1ms(1);

}

/****************************************/

void showTemp() //Display temperature

{

  delay_1ms(1);

  weizhi(1,13);

  wdata(table[Temp/10]);

  delay_1ms(1);

  weizhi(1,14);

  wdata(table[Temp%10]);

  delay_1ms(1);

}

/****************************************/

void chu12864() // Initialize 12864

{

        set(0x01); //Clearing

        set(0x38); //display mode

        set(0x0c); //display on

        set(0x06); //Cursor setting

        weizhi(1,4); //Define the character display position first row, fourth column

        wsdata("Welcome"); //Display the startup welcome message

        weizhi(2,3);

        wsdata("T=");

        weizhi(2,7);

        wsdata("oC");

        IE=0x82; //Set the timer working mode

        TMOD=0X01;

        TH0=(65536-50000)/256; //Set the timer duration to 50MS

[1] [2]
Reference address:Microwave oven control system with single chip microcomputer

Previous article:Four-way buzzer based on Puzhong Technology 51 single-chip microcomputer
Next article:Single chip microcomputer 1602 Chinese characters and time display program (year, month, day 3 Chinese characters)

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号