# include "lcd1602. H"//various header file
# define uchar unsigned char
# define uint unsigned int
11059200 l//# define FOSC System frequency System frequency
9600//# define BAUD UART baudrate UART BAUD rate
Sbit kz=P2 ^ 2;
Uchar jieshou [1].
Void chuan_init (void)//9600 [email protected]
{
SCON=0 x50;//8-bit variable UART 8-bit variable
TMOD |=0 x20;//Set Timer1 as 8-bit auto reload mode will automatically reload time 1 Set to 8 bits mode
TH1=TL1=- (FOSC/12/32/BAUD);//Set auto - reload vaule Set automatically reload valve
TR1=1;//Timer1 start the run time 1 running
ES=1;//Enable UART interrupt Enable UART interrupt
EA=1;//Open the master interrupt switch switch on main interrupt
}
Void show_init ()//LCD initial display content
{
Write_string (1, 0, LOCK "CLOSE");//
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void main ()
{
Init_1602 ();//LCD initialization
Show_init ();//LCD display basic information
Chuan_init ();//serial port initialization
While (1)
{
;
}
}
Void Uart_Isr () interrupt 4//receiving data from the above
{
The static uchar count=0;
ES=0;
If (RI)
{
RI=0;//Clear the receive interrupt flag
Jieshou [count]=SBUF;//no, he endures RevBuf [] array
If (jieshou [0]==10)//received data
{
Kz=0;
Write_string (1, 0, "");//
Write_string (1, 0, LOCK "OPEN");//
}
Else if (jieshou [0]==20)
{
Kz=1;
Write_string (1, 0, "");//
Write_string (1, 0, LOCK "CLOSE");//
}
}
ES=1;
}
# # ifndef _LCD1602_H_
# define _LCD1602_H_
# define uchar unsigned char
# define uint unsigned int
Sbit rs=P0 ^ 0;
Sbit rw=P0 ^ 1;
Sbit e=P0 ^ 2;
Sbit d0=P0 ^ 3;
Sbit d1=P0 ^ 4;
Sbit d2=P0 ^ 5;
Sbit d3=P0 ^ 6;
Sbit d4=P0 ^ 7;
Sbit d5=P2 ^ 7;
Sbit d6=P2 ^ 6;
Sbit d7=P2 ^ 5;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name: delay_uint ()
* function: a small delay,
* input: no
No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void delay_uint (uint q)
{
- while (q);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name: write_com (uchar com)
* function: 1602
command function* input: input command values
No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void write_com (uchar com)
{
E=0;
Rs=0;
Rw=0;
D0=(com& 0 x01)==0 x01? 1-0.
D1=(com& 0 x02)==0 x02? 1-0.
D2=(com& 0==0 x04 x04)? 1-0.
D3=(com& 0 x08)==0 x08? 1-0.
D4=(com& 0 x10)==0 x10? 1-0.
D5=(com& 0 x20)==0 x20? 1-0.
D6=(com& 0 x40)==0 x40? 1-0.
D7=(com& 0 x80)==0 x80? 1-0.
Delay_uint (3);
E=1;
Delay_uint (25);
E=0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name: write_data (uchar dat)
* function: 1602
write data function* input: need to write 1602 data
No
* output:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void write_data (uchar date)
{
E=0;
Rs=1;
Rw=0;
D0=(date& 0 x01)==0 x01? 1-0.
D1=(date& 0 x02)==0 x02? 1-0.
D2=(date& 0==0 x04 x04)? 1-0.
D3=(date& 0 x08)==0 x08? 1-0.
D4=(date& 0 x10)==0 x10? 1-0.
D5=(date& 0 x20)==0 x20? 1-0.
D6=(date& 0 x40)==0 x40? 1-0.
D7=(date& 0 x80)==0 x80? 1-0.
Delay_uint (3);
E=1;
Delay_uint (25);
E=0;
}
/* * * * * * * * * * * * * * * * * * * * * * * on the lcd1602 display the character function * * * * * * * * * * * * * * * * * * * * * * * */
Void write_string (uchar hang, uchar add, uchar * p)
{
If (hang==1)
Write_com (0 x80 + add);
The else
Write_com (0 x80 + 0 x40 + add);
While (1)
{
If (* p=='\ 0') break;
Write_data (* p).
P++;
}
}
/* * * * * * * * * * * * * * * * * * * * * * * lcd1602 initialization Settings * * * * * * * * * * * * * * * * * * * * * * * */
Void init_1602 ()//lcd1602 initialization setting
{
Write_com (0 x38);//
Write_com (0 x0c);
Write_com (0 x06);
}
////////////////at the specified position displays the specified character//////////
/* void write_zifu (uchar hang, uchar add, uchar dat)
{
If (hang==1)
Write_com (0 x80 + add);
The else
Write_com (0 x80 + 0 x40 + add);
Write_data (dat);
} */
/* void write (pp) uchar *
{
While (* pp!='\ 0')
{
Write_data (* pp);
Pp++;
}
} */
# endif
CodePudding user response:
A serial port communication, liquid crystal display 1602