ข้ามไปที่เนื้อหาหลัก

ส่งงานครั้งที่ 10

Digital Thermometer

อุปกรณ์

  • 8051 development board
  • ADC0804 board
  • 16*2 LCD display
  • LM35 sensor
  • Potentiometer
  • Jumper wires
Diagram


Code


/*this program is for displaying the temperature on 16*2 lcd display using 8051 microcontroller , LM35 sensor and ADC0804*/
#include<reg51.h>
sbit rs=P2^7; //Register Select(RS) pin of 16*2 lcd
sbit rw=P2^6; //Read/Write(RW) pin of 16*2 lcd
sbit en=P2^5; //Enable(E) pin of 16*2 lcd
sbit rd_adc=P3^0; //Read(RD) pin of ADC0804
sbit wr_adc=P3^1; //Write(WR) pin of ADC0804
sbit intr_adc=P3^2; //Interrupt(INTR) pin of ADC0804
void delay(unsigned int)  ; //function for creating delay
void cmdwrt(unsigned char); //function for sending commands to 16*2 lcd display
void datawrt(unsigned char); //function for sending data to 16*2 lcd display
void convert_display(unsigned char); //function for converting ADC value to temperature and display it on 16*2 lcd display
void main(void) //main function
{
   unsigned char i;
   unsigned char cmd[]={0x38,0x01,0x06,0x0c,0x82};//กำหนดจอ 16*2
   unsigned char data1[]="Temperature:";
   unsigned char value;
   P1=0xFF; //ให้port 1 เป็น input
   P0=0x00; //ให้port 0 เป็น output
   for(i=0;i<5;i++) //send commands to 16*2 lcd display one command at a time
   {
      cmdwrt(cmd[i]); //function call to send commands to 16*2 lcd display
  delay(1);
   }
   for(i=0;i<12;i++) //send data to 16*2 lcd display one character at a time
   {
      datawrt(data1[i]);  //function call to send data to 16*2 lcd display
  delay(1);
   }
   intr_adc=1; //make INTR pin as input
   rd_adc=1;    //set RD pin HIGH
   wr_adc=1; //set WR pin LOW
   while(1)    //repeat forever
   {
  wr_adc=0; //send LOW to HIGH pulse on WR pin
  delay(1);
  wr_adc=1;
  while(intr_adc==1); //wait for End of Conversion
  rd_adc=0; //make RD = 0 to read the data from ADC0804
  value=P1; //copy ADC data
  convert_display(value); //function call to convert ADC data into temperature and display it on     16*2 lcd display
  delay(1000);  //interval between every cycles
  rd_adc=1;   //make RD = 1 for the next cycle
   }
}
void cmdwrt (unsigned char x)
   P0=x;  //send the command to Port 0 on which 16*2 lcd is connected
   rs=0;  //make RS = 0 for command
   rw=0;  //make RW = 0 for write operation
   en=1;  //send a HIGH to LOW pulse on Enable(E) pin to start commandwrite operation 
   delay(1);
   en=0;
}
void datawrt (unsigned char y)
   P0=y; //send the data to Port 0 on which 16*2 lcd is connected
   rs=1; //make RS = 1 for command
   rw=0; //make RW = 0 for write operation
   en=1; //send a HIGH to LOW pulse on Enable(E) pin to start datawrite operation
   delay(1);
   en=0;
}
void convert_display(unsigned char value)
{
  unsigned char x1,x2,x3;
  cmdwrt(0xc6);  //command to set the cursor to 6th position of 2nd line on 16*2 lcd
  x1=(value/10); //divide the value by 10 and store quotient in variable x1
  x1=x1+(0x30); //convert variable x1 to ascii by adding 0x30
  x2=value%10; //divide the value by 10 and store remainder in variable x2
  x2=x2+(0x30); //convert variable x2 to ascii by adding 0x30
  x3=0xDF; //ascii value of degree(°) symbol
  datawrt(x1);  //display temperature on 16*2 lcd display
  datawrt(x2);
  datawrt(x3);
  datawrt('C'); 
}
void delay(unsigned int z)
{
  unsigned int p,q;
  for(p=0;p<z;p++)    //repeat for 'z' times
  {
    for(q=0;q<1375;q++);   //repeat for 1375 times
  }
}

Credit : https://circuitdigest.com/microcontroller-projects/digital-thermometer-using-lm35-8051

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

ส่งงานครั้งที่ 17

Air Pollution Monitoring อุปกรณ์ MQ135 Gas sensor Arduino Uno Wi-Fi module ESP8266 16X2 LCD Breadboard 10K potentiometer 1K ohm resistors 220 ohm resistor Buzzer Diagram Code #include "MQ135.h" #include <SoftwareSerial.h> #define DEBUG true SoftwareSerial esp8266(9,10); // กำหนดขา 9 ของ Arduino เป็น RX pin และ ขา 10 ของ Arduino เป็น the TX pin const int sensorPin= 0; int air_quality; #include <LiquidCrystal.h> LiquidCrystal lcd(12,11, 5, 4, 3, 2); void setup() { pinMode(8, OUTPUT); lcd.begin(16,2); lcd.setCursor (0,0); lcd.print ("circuitdigest "); lcd.setCursor (0,1); lcd.print ("Sensor Warming "); delay(1000); Serial.begin(115200); esp8266.begin(115200);   sendData("AT+RST\r\n",2000,DEBUG); // reset module   sendData("AT+CWMODE=2\r\n",1000,DEBUG); // กำหนดค่า  access point   sendData("AT+CIFSR\r\n",1000,DEBUG); // รับ ip address   sendData("AT+CIPMUair_quali

ส่งงานครั้งที่ 16

Smoke Detector Using MQ2 อุปกรณ์ Arduino UNO Smoke Detector Arduino Shield (Self Designed) Power Supply Smoke Sensor (MQ2) Resistors (10K and 1K) Buzzer 16x2 LCD 10k POT LED LM358 Burg strips Diagram Code #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define buzzer 9 #define sensor A0   #define load_Res 10   #define air_factor 9.83                                                   float SmokeCurve[3] ={2.3,0.53,-0.44};    // (x, y, slope) x,y พิกัดของจุดหนึ่งและความลาดชันระหว่างสองจุด                                                                                       float Res=0;                 void setup() {   lcd.begin(16,2);   lcd.print("Calibrating.....");                 Res = SensorCalibration();                                                                                           lcd.print("Calibration done.");   lcd.setCursor(0,1);   lcd.print("Res=");   lcd.print(

ส่งงานครั้งที่ 18

12 V Battery Charger อุปกรณ์ Transformer 12V 1Amp IC LM317 (2) Diode Bridge W005 Connector Terminal Block (2) Capacitor 1000uF, 1uF Capacitor 0.1uF (5) Variable resistor 100R Resistor 1k (5) Resistor 10k Diode- Nn007  (3) LM358 – Opamp 0.05R - Shunt Resistor/wire LCD-16*2 (optional) Arduino Nano (optional) Diagram Code #include <LiquidCrystal.h>// ประกาศเมื่อใช้LCD LiquidCrystal lcd(11, 12, 10, 9, 8, 7); float voltage,current;  void setup() {   Serial.begin(9600);   //ตั้งค่าLCD   lcd.begin(16, 2);   // Print a message to the LCD.   lcd.setCursor(0, 0);   lcd.print("12V Charger");   lcd.setCursor(0, 1);   lcd.print("-Circuit Digest");   delay(2000);   lcd.clear();   lcd.setCursor(0, 0);   lcd.print("Voltage = ");   lcd.setCursor(0, 1);   lcd.print("Current = "); } void loop() {   voltage = (analogRead(A0)) * 0.0140625;   current = (analogRead(A1)) * 0.35;           lcd.setCursor(1