#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
Void main ()
{
Uchar n=0;
Uchar * s="both Please start!" ;
Key_n=0;
LcdInitiate ();
Delayms (10);
Show ();
WriteAddress (0 x00);
While (s [n].='\ 0')
{
WriteData ([n] s);
n++;
}
While (key_n!=0)
{
The key ();
}
While (1)
{
The key ();
If (key_n==1) show1 ();//static display
If (key_n==2) show2 ();//whole flashing
If (key_n==3) show3 ();//words flashing
If (key_n==4) show4 ();//whole forward and backward scrolling
If (key_n==5) show5 ();//single character move
If (key_n==6) show6 ();//on both sides to the middle compression
If (key_n==7) show7 ();//in the middle on both sides to expand
If (key_n==8) show8 ();//and compression
If (key_n==9) show9 ();//text scrolling up and down
If (key_n==10) show10 ();//action
}
#include
C # include "delay."
# include "intrins. H"
Sbit RS=P2 ^ 0;//register choice, defined the RS a P2.0 pin
Sbit RW=P2 ^ 1; Choice//, speaking, reading and writing, defined RW a P2.1 pin
Sbit E=P2 ^ 2;//enable signal, defined E a P2.2 pin
Sbit BF=P0 ^ 7;//busy sign bit, and defined the BF a P0.7 pin
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function: judge LCD module busy
Return value: the result, the result=1, busy; Result=0,
is not busy* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Unsigned char BusyTest (void)
{
Bit result;
RS=0;//according to the regulation, the RS as low level, state of RW for high electricity at ordinary times, can read
RW=1;
E=1;//E=1, is allowed to read and write
_nop_();//short operation
_nop_();
_nop_();
_nop_();//short four machine cycle operation, to hardware response time
Result=BF;//will be a busy sign level assigned to the result
E=0;
return result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function: set the pattern instructions or display LCD module address write
Entrance parameters: dictate
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void WriteInstruction (unsigned char dictate)
{
While (BusyTest ()==1);//if busy just waiting for
RS=0;//according to the regulation, low RS and R/W at the same time as the electricity at ordinary times, can be written instructions
RW=0;
E=0;//E buy low level (according to the table 8-6, written instructions, E for high pulse,
//is from 0 to 1 E is jump occurs, so you should buy "0"
_nop_();
_nop_();//short operate two machine cycles, to hardware response time
P0=dictate;//the data into P0 mouth, namely written instructions or address
_nop_();
_nop_();
_nop_();
_nop_();//short four machine cycle operation, to hardware response time
E=1;//E buy high level
_nop_();
_nop_();
_nop_();
_nop_();//short four machine cycle operation, to hardware response time
E=0;//when E from high level to jump into low electricity at ordinary times, LCD module begins to execute the command
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function: the specified character shows the actual address
Entrance parameters: x
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void WriteAddress (unsigned char x)
{
WriteInstruction (x | 0 x80);//show the location of the method for determining the rules to "address x 80 h +"
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function: the data (standard ASCII characters) in the LCD module
Entrance parameters: y (character constants)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void WriteData (unsigned char y)
{
While (BusyTest ()==1);
RS=1;//RS for high level, RW for low electricity at ordinary times, can write data
RW=0;
E=0;//E buy low level (according to the table 8-6, written instructions, E for high pulse,
//is from 0 to 1 E is jump occurs, so you should buy "0"
P0=y;//the data into P0 mouth, the data to the LCD module
_nop_();
_nop_();
_nop_();
_nop_();//short four machine cycle operation, to hardware response time
E=1;//E buy high level
_nop_();
_nop_();
_nop_();
_nop_();//short four machine cycle operation, to hardware response time
E=0;//when E from high level to jump into low electricity at ordinary times, LCD module begins to execute the command
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Function: initialized for LCD display mode Settings
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void LcdInitiate (void)
{
Delayms (15); 15 ms//delay, for the first time writing instruction should give the LCD a longer response time
X38 WriteInstruction (0);//display mode: 16 x 2, 5 x 7 lattice, 8 bits of data interface
Delayms (5);//delay 5 ms
X38 WriteInstruction (0);
Delayms (5);
X38 WriteInstruction (0);
Delayms (5);
X0c WriteInstruction (0);//display mode: display, a cursor, cursor blink
Delayms (5);
WriteInstruction x06 (0);//display mode: the cursor moves to the right, don't move a character
Delayms (5);
WriteInstruction (0 x01);//clear screen instructions, will be used to display content to clear
Delayms (5);
}
#include
#include
Sbit P23=P2 ^ 3;//key_1
Sbit P24=P2 ^ 4;//2
Sbit P25=P2 ^ 5;//3
Sbit he=P2 ^ 6;//4
Sbit P27=P2 ^ 7;//5
Sbit P10 P1=^ 0;//6
Sbit P11 P1=^ 1;//7
Sbit P12=p ^ 2;//8
Sbit P13 P1=^ 3;//9
Sbit P14=P1 ^ 4;//10
Void key_init ()//button pin initializing
{
P23=1; P24=1; P25=1; He=1; P27=1;
P10=1; P11=1; P12=1; P13=1; P14=1;
}
Void the key ()//keypad scanning
{
Key_init ();
If (P23==0)//if P23 pick button press
{
Delayms (10);//short delay, the keys to shake
If (P23==0) key_n=1;//if the button or press the P23, key_n=1
}
Else if (P24==0)
{
Delayms (10);
If (P24==0) key_n=2;
}
Else if (P25==0)
{
Delayms (10);
If (P25==0) key_n=3;
}
Else if (he==0)
{
Delayms (10);
If (he==0) key_n=4;
}
Else if (P27==0)
{
Delayms (10);
If (P27==0) key_n=5;
}
Else if (P10==0)
{
Delayms (10);
If (P10==0) key_n=6;
}
Else if (P11==0)
{
Delayms (10);
If (P11==0) key_n=7;
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull