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.
[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--; } } } } } }
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Is it a way out for hardware engineers to switch to embedded software?
- Let's talk about the specific applications of alumina ceramic substrates
- Relationship between CD4051's switching voltage and power supply voltage VCC
- DIY power supply: if you don't change the color of the digital tube, the operation will be uncomfortable
- Question about zero crossing comparator
- stm32 CANOpen
- [Ultra-low power STM32U5 IoT exploration kit]
- The advantages of GaN in the RF field
- 【AT-START-F425 Review】+ A/D Data Acquisition and Display
- Keil compilation and bit-band operation issues