Use ds18b20 to detect the current temperature. The temperature alarm program function of the isd1420 voice chip
: Use ds18b20 to detect the current temperature, and send an alarm to ISD1420 by comparing it with the set parameters.
The alarm pulse drives the speaker to alarm through the power amplifier LM386.
Note: The alarm of isd1420 adopts the delay mode (the delay alarm of isd1420 depends on the length of recording time)
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define PLAYE_ADDR XBYTE[0XBFFF] //Voice alarm address
#define BUSY 0x80 // LCD busy detection flag
#define DATAPORT P0
sbit P1_0=P1^4; //Clock adjustment
sbit P1_1=P1^5; //Clock plus
sbit P1_2=P1^6; //Clock minus
sbit RED_ALARM=P1^0; //Red indicator light
sbit WRITE_ALARM=P1^1; //White indicator light
sbit GREEN_ALARM=P1^2; //Green indicator light
sbit DQ = P3^7; //Define ds18b20 communication port
sbit LCM_RS=P2^0; //Data/command end
sbit LCM_RW=P2^1; //Read/write selection terminal
sbit LCM_EN=P2^2; //LCD enable signal
sbit REC LED _EOC=P3^5; //ISD1420 playback end query flag
unsigned char seconde=0; //Define and initialize clock variables
unsigned char minite=0;
unsigned char hour=12;
unsigned char mstcnt=0;
unsigned char temp1,temp2,te MP3 ;
unsigned char runtime; //Total system running time
unsigned char t;
unsigned int temp;
uchar code str0[]={"--- : : ---of"};
uchar code str1[]={"temp: . C------"};
void delay_LCM(uint); //LCD delay subroutine
void initLCM( void); //LCD initialization subroutine
void lcd_wait(void); //LCD detection busy subroutine
void WriteCommandLCM(uchar WCLCM,uchar BusyC); //Write instruction to IC M sub-function
void Writ EDA taLCM(uchar WDLCM); //Write data to LCM sub-function
void DisplayOneChar(uchar X,uchar Y,uchar DData); //Display a character sub-function of the specified coordinate
void DisplayListChar(uchar X,uchar Y,uchar code *DData); //Display a string of characters sub-function of the specified coordinate
void init_timer0(void); //Timer initialization
void displayfun1(void); void
delay_18B20(unsigned int i);
void Init_DS18B20(void);
uchar ReadOneChar(void)
; void WriteOneChar(unsigned char dat);
void ReadTemperature(void);
void playalarm(void);
/*********Delay K*1ms,12.000m Hz **********/
void delay_LCM(uint k)
{
uint i,j;
for(i=0;i
for(j=0;j<60;j++)
{;}
}
}
/**********Write instructions to ICM sub-function************/
void WriteCommandLCM(uchar WCLCM,uchar BusyC)
{
if(BusyC)lcd_wait();
DATAPORT=WCLCM;
LCM_RS=0; // Select instruction register
LCM_RW=0; // Write mode
LCM_EN=1;
_nop_();
_nop_();
_nop_();
LCM_EN=0;
}
/**********Write data to LCM sub-function************/
void WriteDataLCM(uchar WDLCM)
{
lcd_wait() ); //Detect busy signal
DATAPORT=WDLCM;
LCM_RS=1; // Select data register
LCM_RW=0; // Write mode
LCM_EN=1;
_nop_();
_nop_();
_nop_();
LCM_EN=0;
}
/***********lcm internal waiting function****************/
void lcd_wait(void)
{
DATAPORT=0xff;
LCM_EN=1;
LCM_RS=0;
LCM_RW=1;
_nop_();
_nop_();
_nop_();
while(DATAPORT&BUSY)
{
LCM_EN=0;
_nop_();
_nop_();
LCM_EN=1;
_nop_();
_nop_();
}
LCM_EN=0;
}
/**********LCM initialization subfunction***********/
void initLCM()
{
DATAPORT=0;
delay_LCM(15);
WriteCommandLCM(0x38,0); //Three display mode settings, do not detect busy signal
delay_LCM(5);
WriteCommandLCM(0x38,0);
delay_LCM(5);
WriteCommandLCM(0x38,0);
delay_LCM(5);
WriteCommandLCM(0x38,1); //8bit data transmission, 2 lines display, 5*7 font, detect busy signal
WriteCommandLCM(0x08,1); //Turn off the display, detect busy signal
WriteCommandLCM(0x01,1); //Clear the screen, detect busy signal
WriteCommandLCM(0x06,1); //Display cursor right shift setting, detect busy signal
WriteCommandLCM(0x0c,1); //Display screen is turned on, cursor is not displayed, does not flash, detect busy signal
}
/****************Display a character at the specified coordinates subfunction **************/
void DisplayOneChar(uchar X,uchar Y,uchar DData)
{
Y&=1;
X&=15;
if(Y)X|=0x40; //If y is 1 (display the second line), address code + 0X40
X|=0x80; //The instruction code is address code + 0X80
WriteCommandLCM(X,0);
WriteDataLCM(DData);
}
/***********Sub-function to display a string of characters at the specified coordinates***********/
void DisplayListChar(uchar X,uchar Y,uchar code *DData)
{
uchar ListLength=0;
Y&=0x01;
X&=0x0f;
while(X<16)
{
DisplayOneChar(X,Y,DData[ListLength]);
ListLength++;
X++;
}
}
/***********ds18b20 delay sub-function ( crystal oscillator 12MHz)*******/
void delay_18B20(unsigned int i)
{
while(i--);
}
/**********ds18b20 initialization function**************************/
void Init_DS18B20(void)
{
unsigned char x=0;
DQ = 1; //DQ reset
delay_18B20(8); //Slight delay
DQ = 0; // MCU pulls DQ low
delay_18B20(80); //Precise delay greater than 480us
DQ = 1; //Pull the bus high
delay_18B20(14);
x=DQ; //After a slight delay, if x=0, initialization is successful, if x=1, initialization fails
delay_18B20(20);
}
/***********ds18b20 reads a byte**************/
unsigned char ReadOneChar(void)
{
uchar i=0;
uchar dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // give pulse signal
dat>>=1;
DQ = 1; // give pulse signal
if(DQ)
dat|=0x80;
delay_18B20(4);
}
return(dat);
}
/*************ds18b20 write a byte****************/
void WriteOneChar(uchar dat)
{
unsigned char i=0;
for (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0x01;
delay_18B20(5);
DQ = 1;
dat>>=1;
}
}
/*************ds18b20 write a byte****************/
void ReadTemperature(void)
{
unsigned char a=0;
unsigned char b=0;
unsigned int t=0;
Init_DS18B20();
WriteOneChar(0xCC); // Skip reading serial number and column
numberWriteOneChar(0x44); // Start temperature conversion
delay_18B20(100); // this message is wery important
Init_DS18B20();
WriteOneChar(0xCC); // Skip reading serial number and column
numberWriteOneChar(0xBE); // Read temperature registers, etc. (9 registers can be read in total) The first two are temperature
delay_18B20(100);
a=ReadOneChar(); // Read the lower 8 bits of temperature valueb
=ReadOneChar(); // Read the higher 8 bits of temperature valuetemp1
=b<<4;
temp1+=(a&0xf0)>>4; // Data before the decimal
pointtemp2=a&0x0f; // Data after the decimal
pointtemp=temp1;
// temp=((b*256+a)>>4);//Currently collected temperature value divided by 16 to get the actual temperature value
// temp1 = t/100%10; //Temperature value tens digit
// temp2 = t/10%10; //Temperature value ones digit
// temp3 = t%10; //Temperature value tenth digit
}
/***************LCD display sub-function 1 normal display********************/
void displayfun1(void)
{
WriteCommandLCM(0x0c,1); //Display screen is turned on, cursor is not displayed, not blinking, busy signal is detected
DisplayListChar(0,0,str0);
DisplayListChar(0,1,str1);
DisplayOneChar(3,0,hour/10+0x30);
DisplayOneChar(4,0,hour%10+0x30);
DisplayOneChar(6,0,minite/10+0x30);
DisplayOneChar(7,0,minite%10+0x30);
DisplayOneChar(9,0, seconde/10+0x30);
DisplayOneChar(10,0,seconde%10+0x30);
DisplayOneChar(5,1,temp1/10+0x30);
DisplayOneChar(6,1,temp1%10+0x30);
DisplayOneChar(8,1,temp2/10+0x30);
}
/***************Timer t0 initialization*******************/
void init_timer0(void)
{
TMOD=0x01; //time0 is timer, mode 1
TH0=0x3c; //preset initial count value
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
}
/***********Timer t0 interrupt subfunction**************/
void timer0(void) interrupt 1 using 0 //Timer 0 mode 1, 50ms interrupt once
{
TH0=0x3c;
TL0=0xb0;
mstcnt++;
if(mstcnt>=20 ) {seconde++; mstcnt=0; }
if(seconde>=60) {minite++; seconde=0;}
if(minite>=60 ) {hour++; minite=0; }
if(hour>=24 ) {hour=0;}
}
/*****************System alarm subfunction***************************/
void playalarm(void) //Voice prompt that the temperature rises too fast
{
if(temp>20&&temp<25)
{
RED_ALARM=0;
PLAYE_ADDR=0x11;
_nop_();
PLAYE_ADDR=0x10;
delay_LCM(2000); //Wait for the end of
playbackRED_ALARM=1;
}
if(temp>25&&temp<30) //Voice prompt that the temperature rises too slowly
{
GREEN_ALARM=0;
PLAYE_ADDR=0x21;
_nop_();
PLAYE_ADDR=0x20;
delay_LCM(2000);
GREEN_ALARM=1;
}
if(temp>30) //Voice prompt that the temperature is controlled
{
WRITE_ALARM=0;
PLAYE_ADDR=0x31;
_nop_();
PLAYE_ADDR=0x30;
delay_LCM(1000);
WRITE_ALARM=1;
}
}
/***************the main function****************/
void main(void)
{
P1=0xff; //Initialize port p1, set all to 1
P3=0xff;
delay_LCM(500);
initLCM( ); //LCD initializationinit_timer0
( ); //Clock timer 0 initializationDisplayListChar
(0,0,str0);
DisplayListChar(0,1,str1);
Init_DS18B20( ); //DS18B20 initializationwhile
(1)
{
delay_LCM(10);
ReadTemperature( );
playalarm( );
displayfun1( );
delay_LCM(10);
}
}
Previous article:LCD12864 display remote control key value reading program
Next article:AT93C46/56/57/66 EEPROM chip universal read and write program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Application of Aigtek power amplifier in electrolysis device of sludge electric remediation technology
- How to compile the image for SINA33 development board
- CalcToolBox 2 based on micropython
- DIY handheld computer with ESP32 and Raspberry Pi
- How is the 64-bit MAC address of the CC2530 device selected?
- Check and compare the specified current limit with the actual current limit. Have you used counterfeit LM257x and LM259x?
- I'm soldering a board recently, but I saw that the circuit requires 500k ohm and 5meg resistors. Do you have something similar that I can use? ?
- MSP430 Learning Experience
- Understanding and Utilizing Solar Loads for Augmented Reality Head-Up Displays
- For example, for a 24-bit ADC, we only know the accuracy. How is the sampling speed/sampling rate of the microcontroller calculated?