/**********************************************************************
Temperature alarm function based on isd1420 voice chip
: Use ds18b20 to detect the current temperature, and send a signal 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)
Question: 1. Will isd1420 occasionally trigger an abnormal alarm?
2. Will the system occasionally enter an abnormal state when powered on?
********************************************************************/
#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
sbit WRITE_ALARM=P1^1; //White indicator
sbit GREEN_ALARM=P1^2; //Green indicator
sbit DQ = P3^7; //Define ds18b20 communication port
sbit LCM_RS=P2^0; //Data/command end
sbit LCM_RW=P2^1; //Read/write selection end
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 command 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 signalDATAPORT
=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 times display mode setting, 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); //Close 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 sub-function of the specified coordinates **************/
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);
}
/***********Display a string of characters at the specified coordinates sub-function***********/
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 subfunction ( 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); //delay
DQ = 0; // MCU pulls DQ low
delay_18B20(80); //accurate delay greater than 480us
DQ = 1; //Pull up the bus
delay_18B20(14);
x=DQ; //After a short delay if x=0, initialization is successful 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 writes 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;
}
}
/**************Read the current temperature of ds18b20************/
void ReadTemperature(void)
{
unsigned char a=0;
unsigned char b=0;
unsigned int t=0;
Init_DS18B20();
WriteOneChar(0xCC); // Skip the operation of reading the serial number and column
numberWriteOneChar(0x44); // Start temperature conversion
delay_18B20(100); // this message is wery important
Init_DS18B20();
WriteOneChar(0xCC); // Skip the operation of reading the serial number and column
numberWriteOneChar(0xBE); //Read the temperature registers, etc. (9 registers can be read in total) The first two are the temperature
delay_18B20(100);
a=ReadOneChar(); //Read the lower 8 bits of the temperature value
b=ReadOneChar(); //Read the high 8 bits of the temperature value
temp1=b<<4;
temp1+=(a&0xf0)>>4; //Data before the decimal point
temp2=a&0x0f; //Data after the decimal point
temp=temp1;
// temp=((b*256+a)>>4); //The current collected temperature value is 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 detectedDisplayListChar
(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 sub-function***************************/
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 constant temperature control
{
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:STC12C4052AD STC MCU ADC sampling C program
Next article:LCD Practical Display Subroutine of T6963C Controller
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How is the storage period of components calculated?
- Let me show you how to calculate a current transformer!
- UHF Duplexer
- How to assign initial values to a continuous RAM range in C2000 chip
- Urgently hiring Linux driver engineer + six insurances and one fund + talent apartment + work residence permit
- Theory and Implementation of Narrow-Band IF Sampling Based on DSP_C54X
- [TI recommended course] #Boost and buck-boost DCDC converters help wireless charging design#
- The microcontroller has its own EEPROM. Is it necessary to add an external EEPROM? Small-volume and high-capacity EEPROMs are more expensive!
- I am facing a problem during the debian burning process of the Sipeed LicheeRV 86 development board?
- FIFO problem of vivado2018.1