12864 LCD ultrasonic distance measurement and voice broadcast circuit and program

Publisher:luanzgcLatest update time:2015-01-14 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Component list:

single-chip ceramic capacitor 0.1uf electrolytic capacitor 10uf electrolytic capacitor 220uf electrolytic capacitor 4.7uf 0.001uf (ceramic capacitor) 22PF (ceramic capacitor) LED small light (5mm) voice chip 12864 LCD speaker microphone (microphone) six-pin plug-in (pin) four-pin plug-in (pin) three-pin plug-in (pin) resistor  1k potentiometer 1k independent button (two pins) crystal oscillator.

 


 

 

The code is as follows: The code still needs debugging [page]

 #include
 #include
//Ultrasonic pin definition
   sbit     RX    P1 ^ 1; //Connect to the Echo pin of the ultrasonic module
   sbit     TX    P1 ^ 2; //Connect to the Trig pin of the ultrasonic module.
//LCD12864 pin definition
   sbit     CS    P2 ^ 5; //Chip select high level is valid. When using a single-chip LCD, the high level can be fixed   to the RS pin
   sbit     SID   P2 ^ 6; //Data is connected to the RW pin
   sbit     SCLK  P2 ^ 7; //Clock is connected to the E pin

//ISD1820 pin definition
   sbit     REC   P2 ^ 4; //
sbit     PLAYE =  P2 ^ 3; //
sbit     PLAYL =  P2 ^ 2;   // 


//Function Definition function declaration
void Delay(int num);
void Init_DS18B20(void);
unsigned char ReadOneChar(void);
void WriteOneChar(unsigned char dat);
unsigned int ReadTemperature(void);
void clock_out(unsigned char dd);
unsigned char clock_in(void);
unsigned char read_clock(unsigned char ord);
void write_clock(unsigned char ord, unsigned char dd);
void Disp(void);
void id_case1_key(void);
void id_case2_key(void);
void Set_time(unsigned char sel,bit sel_1);
void Timer0_Init(void);
void Init_1302(void);
void Set_Bell(unsigned char sel, bit sel_1);
void Bell(void);
//12864
void Write_char(bit start, unsigned char ddata);
void Send_byte(unsigned char bbyte);
void Delaynms(unsigned int di);
void Lcd_init(void);
void Disp_img(unsigned char *img);
void LCD_Write_string(unsigned char X,unsigned char Y,unsigned char *s);
void LCD_set_xy( unsigned char x, unsigned char y );
unsigned char code num[]={"0123456789 :.-"};
unsigned char code waves[]={"Ultrasonic ranging system" };
unsigned char code znwk[] ={"Distance:"};
unsigned char code CM[] =  {"M"};
unsigned int  time=0;
        long S=0;
        bit  flag =0;
unsigned char disbuff[4 ]   ={ 0,0,0,0,};
unsigned char code logo[]={ 
 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0 x00, 0x00,0x60,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xE0,0x00,0x00,0x0C,0x00,0x00,0x40,0x70,0x00,0x00,0x00,0x80,0x00,
0x00,0x00,0x00,0xE0,0x00,0x00,0x1E,0x00,0x00,0x60,0x70,0x00,0x00,0x0F,0xE0,0x00,
0x00,0x00,0x01,0xC0,0x00,0x60,0x3C,0x00,0 x00, 0xE0,0x60,0x00,0x1F,0xFF,0xE0,0x00,
0x00,0x00,0x03,0x80,0x00,0x70,0x70,0x40,0x00,0xE0,0x7E,0x00,0x1F,0xE0,0xC0,0x00,
0x00,0x00,0x03,0x00,0x00,0x73,0xC3,0xF0,0x01,0xC3,0xFC,0x00,0x38,0xE1,0xC0,0x00,
0x00,0x03,0xC6,0x3C,0x00,0x33,0x9F,0xF0,0x 03, 0x8F,0xC0,0x00,0x30,0xC1,0xC0,0x00,
0x00,0x3F,0xEF,0xFE,0x00,0x03,0x1C,0xE0,0x07,0x01,0xCC,0x00,0x31,0xF1,0x80,0x00,
0x00,0x79,0xDF,0xBC,0x00,0x06,0x18,0xC0,0x0E,0x01,0xFE,0x00,0x77,0xF9,0x80,0x00,
0x00,0x01,0xB0,0x30,0x01,0xC6,0x19,0xC0,0x1E , 0x7F,0xDE,0x00,0x6F,0x83,0x80,0x00,
0x00,0x23,0xAC,0x60,0x0F,0xE6,0xF1,0x80,0x3E,0x7B,0x38,0x00,0x61,0x83,0x00,0x00,
0x00,0x37,0x0E,0x00,0x0F,0xC7,0xB7,0x80,0xEC,0x63,0x30,0x00,0xE3,0x03,0x00,0x00,
0x00,0x3E,0x0E,0x00,0x01,0x8F,0x37,0x01,0x CC, 0x6F,0xF0,0x00,0xC7,0xF7,0x00,0x00,
0x00,0x1E,0x0C,0x00,0x03,0x1E,0x66,0x03,0x0C,0x7F,0x00,0x01,0xFF,0xE6,0x00,0x00,
0x00,0x1E,0x1C,0x00,0x03,0x1C,0x60,0x02,0x19,0xAC,0x00,0x01,0x96,0x06,0x00,0x00,
0x00,0x3E,0x3E,0x00,0x03,0x18,0x60,0x00,0x 19, 0xFC,0x00,0x03,0x86,0x0E,0x00,0x00,
0x00,0x7E,0x36,0x00,0x03,0x00,0xC0,0x00,0x38,0x78,0x00,0x03,0x06,0x0C,0x00,0x00,
0x00,0xE6,0x67,0x00,0x03,0x00,0xC0,0x00,0x30,0x78,0x00,0x06,0x0C,0x0C,0x00,0x00,
0x01,0xC6,0xC3,0x80,0x7F,0xF0,0xC0,0x00,0 x30, 0xFE,0x00,0x0E,0x0C,0x1C,0x00,0x00,
0x03,0x81,0x83,0xC0,0x78,0xFF,0x80,0x00,0x61,0xCF,0x80,0x1C,0x08,0x18,0x00,0x00,
0x06,0x07,0x03,0xE0,0x00,0x1F,0xFF,0xE0,0x67,0x07,0xE0,0x38,0x18,0xF8,0x00,0x00,
0x08,0x0E,0x01,0xF8,0x00,0x07,0xFF,0x80,0xCE , 0x03,0xF8,0x60,0x00,0x70,0x00,0x00,
0x00,0x18,0x01,0xF8,0x00,0x01,0xFC,0x00,0xC0,0x01,0xFC,0xC0,0x00,0x70,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x06,0x00,0x00,0x00,0x1C,0x00,0 x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x07,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x06,0x00,0x00,0x00,0x0C,0xE0,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0E,0x00,0x00,0x00,0x3F,0xE0,0 x00, 0xFF,0xF0,0x00,0x38,0x00,0xE0,0x00,
0x00,0x00,0x0C,0x00,0x00,0x0F,0xFF,0x80,0x00,0xF8,0xF0,0x00,0x38,0x00,0xE0,0x00,
0x00,0x00,0x0C,0xF0,0x00,0x0F,0xC7,0x00,0x00,0x60,0xE0,0x00,0x38,0x00,0xE0,0x00,
0x00,0x00,0x1F,0xF0,0x00,0x01,0x8E,0x00,0 x00, 0x60,0xC0,0x00,0x70,0x01,0xC0,0x00,
0x00,0x07,0xFF,0x80,0x00,0x01,0x8C,0x00,0x00,0xE1,0x80,0x00,0x70,0x01,0xC0,0x00,
0x00,0x07,0xF8,0x00,0x00,0x01,0x98,0x00,0x00,0xDF,0xC0,0x00,0x70,0x01,0xC0,0x00,
0x00,0x00,0x78,0x00,0x00,0x01,0xBF,0xE0,0x0 0, 0xFF,0x00,0x00,0x60,0x01,0x80,0x00,
0x00,0x00,0xFC,0x00,0x00,0x7F,0xFF,0xE0,0x00,0xC0,0x00,0x00,0xE0,0x03,0x80,0x00,
0x00,0x01,0xFE,0x00,0x00,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0xC0,0x03,0x00,0x00,
0x00,0x03,0xB7,0x00,0x00,0x60,0x00,0x00,0x 00, 0x00,0x3C,0x00,0xC0,0x03,0x00,0x00,
0x00,0x07,0x67,0x00,0x00,0x60,0x00,0x00,0x03,0x9F,0xFE,0x00,0x80,0x02,0x00,0x00,
0x00,0x0E,0x63,0x80,0x00,0xE0,0x00,0x01,0xFF,0xCF,0x1E,0x01,0x80,0x06,0x00,0x00,
0x00,0x1C,0xE1,0xE0,0x00,0xC0,0x00,0x00,0xE3,0x9C,0x38,0x01,0x80,0x06,0x00,0x00,
0x00,0x38,0xC1,0xF8,0x01,0xC0,0x00,0x00,0 xC3, 0x18,0x30,0x00,0x00,0x00,0x00,0x00,
0x00,0xE0,0xFC,0xFE,0x03,0x80,0x00,0x01,0xC7,0x18,0x60,0x00,0x00,0x00,0x00,0x00,
0x01,0xDF,0xF8,0xFE,0x03,0x00,0x00,0x01,0x8E,0x1B,0xE0,0x07,0x00,0x1C,0x00,0x00,
0x07,0x07,0x80,0x00,0x07,0x00,0x00,0x01,0xFF , 0x3F,0xE0,0x07,0x00,0x1C,0x00,0x00,
0x0C,0x03,0x80,0x00,0x0E,0x00,0x00,0x01,0xF0,0x38,0x00,0x0F,0x00,0x3C,0x00,0x00,
0x00,0x03,0x00,0x00,0x1C,0x00,0x00,0x01,0x00,0x20,0x00,0x06,0x00,0x18,0x00,0x00,
0x00,0x03,0x00,0x00,0x38,0x00,0x00,0x00,0 x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x02,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

void Lcd_init(void) //Initialize LCD
{
Delaynms(10); //Start waiting, wait for LCM to enter working state
 CS=1;
 Write_char(0,0x30);  //8-bit interface, basic instruction set
 Write_char(0,0x0c);  //Display on, cursor off, reverse white off
 Write_char(0,0x01);  //Clear screen, reset DDRAM address counter to zero 
}

void Write_char(bit start, unsigned char ddata) //write command or data
{
unsigned char start_data,Hdata,Ldata;
 if(start==0)
start_data=0xf8; //write commandelse
   start_data    
   =0xfa;  //write dataHdata
 
 =ddata&0xf0;  //get the upper four
 bitsLdata=(ddata<<4)&0xf0;  //get the lower four
 bitsSend_byte(start_data);  //send the start signalDelaynms
 (5); //delay is necessarySend_byte
 (Hdata);      //send the upper four
 bitsDelaynms(1);  //delay is necessarySend_byte
 (Ldata);  //send the lower four
 bitsDelaynms(1);  //delay is necessary
}

void Send_byte(unsigned char bbyte) //Send a byte
{
unsigned char i;
 for(i=0;i<8;i++)
   {
   SID=bbyte&0x80; //Take out the highest bit
 SCLK=1;
   SCLK=0;
   bbyte<<=1; //Shift left
   
}

void Delaynms(unsigned int di) //Delay
{
unsigned int da,db;
 for(da=0;da
   for(db=0;db<10;db++);
}

void Disp_img(unsigned char  *img) //Graphics mode 12864 display font 221 horizontal film
{
unsigned char i,j;
unsigned int k = 0;

Write_char(0,0x36); //Graphic mode
for(i=0;i<32;i++)
 {
Write_char(0,0x80+i);
Write_char(0,0x80);
   for(j=0;j<16; j++)
{
Write_char(1,img[k++]);
}
 }

 for(i=0;i<32;i++)
 {
Write_char(0,0x80+i);
Write_char(0,0x88);
   for(j=0;j<16;j++)
{
Write_char(1,img[k++] );
 }
}
}
void Clr_Scr(void)//Clear screen function
{
Write_char(0,0x01);
}

void LCD_set_xy( unsigned char x, unsigned char y )
{ //Set the starting position of the LCD display, X is the row, Y is the column
   unsigned char address;
switch(x)
{
case 0: address = 0x80 + y; break;    
   case 1: address = 0x80 + y; break;
case 2: address = 0x90 + y; break;
   case 3: address = 0x88 + y; break;
case 4: address = 0x98 + y; break;
default:address = 0x80 + y ; break;
}
   Write_char(0, address);
}

void LCD_Write_string(unsigned char X,unsigned char Y,unsigned char *s)
{ // Chinese and English string display function
LCD_set_xy( X, Y );
   
   while (*s)
   {
Write_char( 1, *s );
  s ++;
Delaynms(1);
}
}

void LCD_Write_number(unsigned char s)//Number display function
{
Write_char(1,num[s]);
Delaynms(1);
}
void Lcd_Mark2(void)
{
Clr_Scr();//Clear screen
LCD_Write_string(1,0,znwk );//
LCD_Write_string(2,0,waves);//
LCD_Write_string(3,7,CM);//
}

 void Conut(void) //Calculate the distance. If you want to change the accuracy, you can modify it here.
{
 time=TH0*256+TL0;
 TH0=0;
 TL0=0;
 S=time*1.87/100;       //The calculated value is CM  11. The 0592M crystal oscillator   must be modified
 if(S>200)          //Debugging is required here.
 {
 PLAYE=1;
Delaynms(1);
PLAYE=0;
 }
 if(flag==1)      //Out of measurement.
 
 flag=0;
 LCD_set_xy( 3, 4 ); LCD_Write_number (
 13); LCD_Write_number(12 ); LCD_set_xy( 3, 5 ); LCD_Write_number(13); LCD_Write_number(13); } else { disbuff[1]=S00/100; disbuff[2]=S000/10; disbuff[3]=S00 ; LCD_set_xy( 3, 4 ); LCD_Write_number(disbuff[1]); LCD_Write_number(12); LCD_set_xy( 3, 5 ); LCD_Write_number(disbuff[2]); LCD_Write_number(disbuff[3]); } } void delayms(unsigned int ms) { unsigned char i=100,j; for(;ms;ms--) { while(--i) { j=10; while(--j); } } } void zd0() interrupt 1 //T0 interrupt is used for counter overflow, exceeding the ranging range { flag=1; //interrupt overflow flag } void  StartModule()  //T1 interrupt is used to scan the digital tube and count 800MS start module { TX=1;  //800MS  start module once _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_() ; _nop_(); _nop_(); _nop_( ); _nop_(); _nop_ (); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); TX= 0; } void main(void) {  TMOD=0x01;  //Set T0 as mode 1, GATE=1 TH0=0; TL0=0; TR0=1;
 
 
 
 
 
 

 
 
 
 
 
 
 
 
 
 
 

 












    
 
   
 
         
 
                
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


    


Lcd_init();       //Set up the LCD display
Clr_Scr();        //Clear the screen
Disp_img(logo);  //Show the welcome to use this product LOGO
Delaynms(1000);
Lcd_init();       //Return from the graphics display state
   Lcd_Mark2();

REC=0;  //Record first.   If you can't record first, this may not work.
PLAYE=0;  //Rising edge trigger
PLAYL=0;  //High level trigger

while(1)
{
StartModule(); 
       //Calculatewhile
(!RX); //When RX is zero, wait for
TR0=1;    //Start countingwhile
(RX); //When RX is 1, count and wait for
TR0=0; //Stop countingConut
();
delayms(80); //80MS

}

}

Reference address:12864 LCD ultrasonic distance measurement and voice broadcast circuit and program

Previous article:Single chip microcomputer minimum system_button control digital tube display
Next article:DS1302 four-digit digital tube adjustable clock based on 51 single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 22:21

LCD12864 circuit connection
Now let's make a summary of the problems encountered by those who have just come into contact with single-chip microcomputer driving LCD screens. 1. No display         A: Hardware problem           1: This is the most common problem for novices. If you encounter this situation, first refer to the corresponding har
[Microcontroller]
LCD12864 circuit connection
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号