isd1420 voice chip temperature alarm program

Publisher:平安宁静Latest update time:2018-01-08 Source: eefocusKeywords:isd1420 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/********************************************************************** 
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); 
    } 


Keywords:isd1420 Reference address:isd1420 voice chip temperature alarm program

Previous article:STC12C4052AD STC MCU ADC sampling C program
Next article:LCD Practical Display Subroutine of T6963C Controller

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号