AT89s52-LCD12864 multi-page menu button selection operation

Publisher:MeshulunLatest update time:2012-08-18 Source: 51heiKeywords:AT89s52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I haven't understood the code of this program yet, and I once again deeply discovered that my algorithm level is not good enough. What I learned today is okay, just some knowledge of those C files. Anyway, they are all optimization things, which will definitely be useful in the future. If you are interested in a few days, I will learn about AVR microcontrollers.

Program code: The hardware is the same as before, with the only difference being two more page-turning buttons. I haven't eaten yet, it's time to go eat. I really won't feel sleepy doing this.
Click to browse the next page

[page]

#include 
#include 

sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
sbit PSB= P2^1; //Serial-parallel port selection end parallel high serial low
#define DataPort P0   

sbit KEY_ADD=P3^3; //key
sbit KEY_DEC=P3^4;

unsigned char curr,currold; //global variable, current arrow position

unsigned char code user16x16[]={ //arrow image
0x00,0x00,0x20,0x00,0x30,0x00,0x38,0x00,0x3C,0x00,0x3E,0x00,0x3F,0x00,0x3F,0x80,
0x3F,0xC0,0x3F,0x80,0x3F,0x00,0x3E,0x00,0x3C,0x00,0x38,0x00,0x30,0x00,0x20,0x00,
};

unsigned char code *MainMenu[]=
{
 {"1.Set 1"},
 {"2.Set 2"},
 {"3.Set 3"},
 {"4.Set 4"},
 {"5.Set 5"},
 {"6.Set 6"},
 {"7.Set 7"},
 {"8.Set 8"},
 {"9.Set 9"},
 {"0.Set0"},
};

/**********************************************
                  Delay function
*************************************************/
void DelayUs2x(unsigned char t)
{   
 while(--t);
}

void DelayMs(unsigned char t)
{
     
 while(t--)
 {
     DelayUs2x(245);
  DelayUs2x(245);
 }
}

/**********************************************
                Busy detection function
*************************************************/
void Check_Busy()
{  
    RS=0; //write command
    RW=1; //Read status
    E=1;
    DataPort=0xff;
    while((DataPort&0x80)==0x80);//Wait if busy
    E=0;
}

/**********************************************
                Write Command
*************************************************/
void Write_Cmd(unsigned char Cmd)
{
 Check_Busy();
 RS=0; //write command
 RW=0; //write
 E=1;
 DataPort=Cmd;
 DelayUs2x(5);
 E=0;
 DelayUs2x(5);
}

/**********************************************
                 Writing Data
*************************************************/
void Write_Data(unsigned char Data)
{
 Check_Busy();
 RS=1; //write data
 RW=0; //write
 E=1;
 DataPort=Data;
 DelayUs2x(5);
 E=0;
 DelayUs2x(5);
}

/**********************************************
               LCD screen initialization
*************************************************/
void Init_ST7920()
{  
   DelayMs(40); //Delay program greater than 40MS
   PSB=1; //Set to 8BIT parallel port working mode
   DelayMs(1); //delay
   Write_Cmd(0x30); //Select basic instruction set
   DelayUs2x(50); //delay greater than 100us
   Write_Cmd(0x30); //Select 8bit data stream
   DelayUs2x(20); //Delay greater than 37us
   Write_Cmd(0x0c); //Open the display (no cursor, no highlight)
   DelayUs2x(50); //delay greater than 100us
   Write_Cmd(0x01); //Clear the display and set the address pointer to 00H
   DelayMs(15); //Delay is greater than 10ms
   Write_Cmd(0x06); //Specify when reading and writing data,
Set the cursor moving direction and specify the displayed shift. The cursor moves from right to left by 1 position.
   DelayUs2x(50); //delay greater than 100us
}

/**********************************************
                User defined characters
*************************************************/
void CGRAM()
{
     int i;
     Write_Cmd(0x30);
     Write_Cmd(0x40);
     for(i=0;i<16;i++)
       {
        Write_Data(user16x16[i*2]);
        Write_Data(user16x16[i*2+1]);
      }
}   

/**********************************************
               Display user-defined characters
*************************************************/
void DisplayCGRAM(unsigned char x, unsigned char y)
{
 switch(y)
     {
   case 1: Write_Cmd(0x80+x);break;
   case 2: Write_Cmd(0x90+x);break;
   case 3: Write_Cmd(0x88+x);break;
   case 4: Write_Cmd(0x98+x);break;
      default:break;
  }
    Write_Data(00);
    Write_Data(00);
}         

/**********************************************
                  Display String
            x: horizontal axis value, range 0~8
            y: vertical coordinate value, range 1~4
*************************************************/
void LCD_PutString(unsigned char x, unsigned char y, unsigned char code *s)
{
 switch(y)
     {
   case 1: Write_Cmd(0x80+x);break;
   case 2: Write_Cmd(0x90+x);break;
   case 3: Write_Cmd(0x88+x);break;
   case 4: Write_Cmd(0x98+x);break;
      default:break;
  }
 while(*s>0)
   {
      Write_Data(*s);
      s++;
      DelayUs2x(50);
   }
}

/**********************************************
                     Clear screen
*************************************************/
void ClrScreen()
{
   Write_Cmd(0x01);
   DelayMs(15);
}    
/**********************************************
               Calling Display Update
*************************************************/
void DisplayUpdata(void)
{   
    unsigned char num;
  ClrScreen();
 num=sizeof(MainMenu)/sizeof(MainMenu[0]); //Determine the number of values ​​in the array
 if((0+(curr/4)*4)0)
     { curr--; }
    }
    }
 }  
  }
}

Keywords:AT89s52 Reference address:AT89s52-LCD12864 multi-page menu button selection operation

Previous article:nRF2401 wireless communication module debugging
Next article:Solution to the problem that 51 interrupts cannot be processed normally

Recommended ReadingLatest update time:2024-11-16 16:35

Design of a Simple Digital Oscilloscope Based on AT89S52 Single Chip Microcomputer
With the development of electronic technology and the changes in circuit structure, the requirements for circuit measurement have become higher. For the majority of science and engineering students and ordinary workers in electronics and other related industries, many circuit parameters need to be measured and analy
[Microcontroller]
Design of a Simple Digital Oscilloscope Based on AT89S52 Single Chip Microcomputer
Design of dynamic measurement system for abdominal pressure
The abdominal cavity is a closed cavity. Any organ volume increase beyond a certain limit can lead to intra-abdominal hypertension. The purpose of abdominal pressure monitoring is to observe the changes in intra-abdominal pressure after abdominal surgery and in critically ill patients, so as to provide an eff
[Microcontroller]
Design of dynamic measurement system for abdominal pressure
Design of dual closed-loop speed control system for three-phase asynchronous motor based on TMS320LF2407A and AT89S52
Abstract: Aiming at the speed regulation requirements of three-phase AC asynchronous motor in a certain equipment, a current and speed dual closed-loop speed regulation control system is designed with TMS320LF2407A and AT89S52 as the core and adopting the magnetic field oriented control strategy. The hardw
[Industrial Control]
Design of dual closed-loop speed control system for three-phase asynchronous motor based on TMS320LF2407A and AT89S52
Temperature Control System Based on AT89S52 Single Chip Microcomputer
0 Introduction In the temperature matching of laser frequency doubling crystals, a very high operating temperature is sometimes required. During the crystal heating process, a rapid temperature change will cause the crystal to crack, so the operator needs to manually control the temperature of the laser crystal conti
[Industrial Control]
Temperature Control System Based on AT89S52 Single Chip Microcomputer
Design of automobile anti-theft system based on time trigger mode
  1 Introduction   Currently, the mainstream products in the anti-theft device market are electronic anti-theft devices, which are divided into one-way anti-theft devices and two-way anti-theft devices. Both of these anti-theft devices allow the owner to control the car through a remote control, while the two-way an
[Microcontroller]
Design of automobile anti-theft system based on time trigger mode
Design of program-controlled switching voltage-stabilized power supply based on AT89S52dpj
A switching power supply is a power supply that uses modern power electronics technology to control the time ratio of the switch tube to be turned on and off to maintain a stable output voltage. Due to its high efficiency and high power density, the use of switching power supplies in modern electronic systems is bec
[Power Management]
LCD12864 LCD display SHT11 temperature and humidity sensor program
Note: Lower versions of Keil software cannot be compiled successfully because they cannot handle floating-point operations. #include reg52.h #include intrins.h   #define uint unsigned int #define uchar unsigned char #define noACK 0 #define ACK   1             #define STATUS_REG_W 0x06   #define STATUS_
[Microcontroller]
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号