51 MCU C Programming (XI. Telephone dialing simulation LCD display)

Publisher:cw57324588Latest update time:2015-09-25 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
*Program name: Telephone dial simulation (LCD display)

*Created by   : jumpmysoul
*Completed date: 2009.06.06
   Version : V1.0
*Functional description: Press a key on the phone keypad, and the corresponding
character of the pressed key will be displayed on the LCD screen. Press the DEL key to delete a character (Disadvantage: After deleting all characters,
the cursor disappears. If you continue to delete several times, you will have to press the key several more times when entering again)

[Reprint] 51 MCU C Programming (XI, Telephone Dial Simulation LCD Display)

#include
#define uchar unsigned char
#define uint unsigned int
#define LCDPORT P0
#define KEY  P1
//#define WEI  P2

sbit DEL=P3^0;
sbit LCDE=P3^5;
sbit LCDRW=P3^6;
sbit LCDRS=P3^7;

uchar code NUM[12]="0123456789*#";

fly addr=0;

void WriteCMD(uchar);  
void init();
void WriteData(uchar);
void Delete();

void Delay_ms(uint);
uchar KeyScan();
void main()
{
 init();
 while(1)
 {
  if(KeyScan()!=20)   //Judge whether the phone key is pressed
  {
   addr++;     //Add 1 to the address variable
   WriteData(NUM[KeyScan()]);   //Display the pressed key value on the LCD
   Delay_ms(100);      //Delay, the function is to display only one character, if there is no delay, a string of characters will be displayed
  }

  if(DEL==0)      //Judge whether the DEL button is pressed
  {
   Delay_ms(10);
   if(DEL==0)
   while(DEL==0);
   Delay_ms(10);
   while(DEL==0);
   Delete();
  }
 }

}
uchar KeyScan()
{
 uchar temp=20;
 KEY=0xef;       //扫描第1列键
 switch(KEY)
 {
  case 0xee:temp=1;break;
  case 0xed:temp=4;break;
  case 0xeb:temp=7;break;
  case 0xe7:temp=10;break;
  default:break;
 
 KEY=0xdf;       //扫描第2列键
 switch(KEY)
 {
  case 0xde:temp=2;break;
  case 0xdd:temp=5;break;
  case 0xdb:temp=8;break;
  case 0xd7:temp=0;break;
  default:break;
 
 KEY=0xbf;       //扫描第3列键
 switch(KEY)
 {
  case 0xbe:temp=3;break;
  case 0xbd:temp=6;break;
  case 0xbb:temp=9;break;
  case 0xb7:temp=11;break;
  default:break;
 }
 return(temp);      //返回按键键值
}
void Delay_ms(uint x)
{
 uint i,j;
 for(i=x;i>0;i--)
  for(j=120;j>0;j--);
}
void WriteCMD(uchar Command)      
{
 Delay_ms(10);    //先延时。

 LCDE=1;      //Then change LCD to write command status.
 LCDRS=0;
 LCDRW=0;

 LCDPORT=Command;   //Output command again.

 LCDE=0;      //Finally execute the command.
}
void WriteData(uchar dat)       
{
 Delay_ms(10);       //Delay first.

 LCDE=1;        //Then change the LCD to write data state.
 LCDRS=1;
 LCDRW=0;

 LCDPORT=dat;      //Output data again.

 LCDE=0;        //Finally display the data.
}
void init()
{
 LCDRW=0;
    LCDE=0;
  WriteCMD(0x38);
 WriteCMD(0x0f);
 WriteCMD(0x06);
 WriteCMD(0x01);
 WriteCMD(0x80);
}
void Delete()
{
 if( (addr--)>0)
 {
  WriteCMD(0x04);     //After reading and writing a character, the address pointer decreases by 1 and the cursor moves left
  WriteData(' '); 
 }
 WriteCMD(0x06);      //After reading and writing a character, the address pointer increases by 1 and the cursor moves right
 
}

Reference address:51 MCU C Programming (XI. Telephone dialing simulation LCD display)

Previous article:51 MCU C programming (ten, 74LS165 serial port input)
Next article:51 MCU C programming (Twelve, LM016L LCD display)

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号