#Instruction System
#Code
* 【Course 19】 ****LCD12864 Experiment***********
*
* 【Explanation】 ****There is no ready-made font library in the simulation environment, so you need to make your own Chinese character font library
*
* 【Description】 ****Show "Sourceshare Technology"
*
******************************************************************
Basic operations:
Read status: RS=0,RW=1,EN=1
Output: D0~D7=status word;
Write instruction: RS=0, RW=0, EN=falling edge pulse
D0~D7=instruction code;
Read data: RS=1, RW=1, EN=1
Output: D0~D7=data;
Write data: RS=1, RW=1, EN=falling edge pulse
D0~D7=data;
*********************************************************/
#include //---------Two commonly used macro definitions-------------- #define uint8 unsigned char #define uint16 unsigned int //--------12864 control pin definition------------- sbit RS = P3^5; sbit RW = P3^6; sbit EN = P3^4; sbit CS2 = P3^0; sbit CS1 = P3^1; uint8 code yuan[]= { /*------------------------------------------------------------------------------ ; Source file/text: source ; Width × height (pixels): 16×16 ------------------------------------------------------------------------------*/ 0x10,0x21,0x06,0xE0,0x00,0xFE,0x02,0xF2, 0x5A,0x56,0x52,0x52,0x52,0xF2,0x02,0x00, 0x04,0xFC,0x03,0x40,0x30,0x0F,0x20,0x11, 0x4D,0x81,0x7F,0x01,0x05,0x09,0x30,0x00 }; uint8 code xiang[]= { 0x00,0x04,0x04,0x74,0x54,0x54,0x55,0x56, 0x54,0x54,0x54,0x74,0x04,0x04,0x00,0x00, 0x08,0x08,0x09,0x09,0x09,0x29,0x49,0x89, 0x7D,0x0B,0x0B,0x09,0x08,0x08,0x08,0x00 }; uint8 code k[]= { /*-- Character: Family --*/ /*-- Songti 12; The corresponding dot matrix under this font is: width x height = 16x16 --*/ 0x10,0x12,0x92,0x72,0xFE,0x51,0x91,0x00, 0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00, 0x04,0x02,0x01,0x00,0xFF,0x00,0x04,0x04, 0x04,0x02,0x02,0x02,0xFF,0x01,0x01,0x00 }; uint8 code ji[]= { /*-- Character: Technique --*/ /*-- Songti 12; The corresponding dot matrix under this font is: width x height = 16x16 --*/ 0x08,0x08,0x88,0xFF,0x48,0x28,0x00,0xC8, 0x48,0x48,0x7F,0x48,0xC8,0x48,0x08,0x00, 0x01,0x41,0x80,0x7F,0x00,0x40,0x40,0x20, 0x13,0x0C,0x0C,0x12,0x21,0x60,0x20,0x00 }; //-----------Function declaration------------------ void DelayMS(uint16 dly); //----------Declaration of LCD module--------------- bit BUSY(void); //测忙 void Write_cmd(uint8 cmd); //write command void Write_dat(uint8 dat); //write data //void LCD_Init(void); void Set_page(uint8 page); //Set page void Set_Line(uint8 line); //Set the starting line void Set_Col(uint8 col); //Set column void Set_ONOFF(uint8 switch); //1 on, 0 off void Clear(void); //清屏 void LCD_Init(void); //LCD screen initialization void Display(uint8 screen,uint8 page,uint8 col,uint8 *p); //Display Chinese characters void Select_Screen(uint8 swich); //Select LCD screen (left or right) //---------Main Task--------------------- void main(void) { LCD_Init(); Display(1,0,0,yuan); //source Display(1,2,0,xiang); //enjoy Display(1,4,0,ke); //科 Display(1,6,0,ji); //技 Display(2,0,0,yuan); Display(2,2,0,xiang); Display(2,4,0,ke); Display(2,6,0,ji); while(1) { } } /******************************************************** ** Name: void DelayMS(uint16 dly) ** Function: millisecond delay (12M crystal oscillator) ** Input parameter: dly User delay parameters ** Export parameters: None *********************************************************/ void DelayMS(uint16 dly) { uint16 x,y; for(x=dly;x>0;x--) for(y=124;y>0;y--); } /******************************************************** ** Name: bit BUSY(void) ** Function: Check whether LCD1602 is in busy state; ** Input parameters: None ** Export parameter: bit Bit Returns 1, then BUSY Return 0, then OK *********************************************************/ bit BUSY(void) { bit Bit; P0 = 0x00; RS = 0; RW = 1; EN = 1; DelayMS(1); Bit = (bit)(P0 & 0x80); //The highest bit is the busy signal bit EN = 0; return Bit; } /******************************************************** ** Name: void Write_cmd(uint8 cmd) ** Function: Write command ** Entry parameter: cmd control commands ** Export parameters: None *********************************************************/ void Write_cmd(uint8 cmd) { while(BUSY()); //测忙 RS = 0; RW = 0; EN = 0; P0 = cmd; EN = 1; DelayMS(1); EN = 0; } /******************************************************** ** Required: void Write_dat(uint8 dat) ** Function: write data ** Input parameter: dat Data to display ** Export parameters: None *********************************************************/ void Write_dat(uint8 dat) { while(BUSY()); //测忙 RS = 1; RW = 0; EN = 0; P0 = that; EN = 1; DelayMS(1); EN = 0; } /******************************************************** ** Name: void LCD_Init(void) ** Function: LCD initialization ** Input parameters: None ** Export parameters: None *********************************************************/ /*void LCD_Init(void) { Write_cmd(0x34); //Extended instruction operation DelayMS(5); Write_cmd(0x30); //Basic instruction operation DelayMS(5); Write_cmd(0x0C); //Display on and off cursor DelayMS(5); Write_cmd(0x01); //Clear the LCD display content DelayMS(5); }*/ /******************************************************** ** Name: void Set_page(uint8 page) ** Function: Settings page ** Input parameter: uint8 Page 0~7 Total 8 pages ** Export parameters: None *********************************************************/ void Set_page(uint8 page) { page = 0xb8|page; //The first address of the page is 0XB8 Write_cmd(page); } /******************************************************** ** Name: void Set_Line(uint8 line) ** Function: Set the starting line ** Input parameter: uint8 line ** Export parameters: None *********************************************************/ void Set_Line(uint8 line) { line = 0xc0|line; Write_cmd(line); } /******************************************************** ** Name: void Set_Col(uint8 col) ** Function: Set the starting position of the column ** Input parameter: uint8 col ** Export parameters: None *********************************************************/ void Set_Col(uint8 col) { col = col&0x3f; col = 0x40|col; Write_cmd(col); } /******************************************************** ** Name: void Select_Screen(uint8 switch) ** Function: Select screen --- left and right screen ** Input parameter: uint8 switch ** Export parameters: None *********************************************************/ void Select_Screen(uint8 swich) { switch(swich) { case 0: CS1 = CS2 =0; //full screen break; case 1: CS1 = 0; CS2 = 1; //left screen break; case 2: CS1 =1; CS2 = 0; //右屏 break; default: break; } } /******************************************************** ** Name: void Set_ONOFF(uint8 switch) //0 or 1 ** Function: Set the display switch ** Input parameter: uint8 swich 0---off 1---Open ** Export parameters: None *********************************************************/ void Set_ONOFF(uint8 switch) //0 or 1 { swich = 0x3e|swich; Write_cmd(swich); } /******************************************************** ** 名称 :void Clear(void) ** Function: Clear screen ** Input parameters: None ** Export parameters: None *********************************************************/ void Clear(void) { uint8 i,j; for(i=0;i<8;i++) { Set_page(i); Set_Col(0); for(j=0;j<64;j++) { Write_dat(0x00); } } } /******************************************************** ** Name: void LCD_Init(void) ** Function: Initialization ** Input parameters: None ** Export parameters: None *********************************************************/ void LCD_Init(void) { while(BUSY()); //测忙 Set_ONOFF(1); Clear(); Set_Line(0); } /******************************************************** ** 名称 :void Display(uint8 screen,uint8 page,uint8 col,uint8 *p) ** Function: Display of Chinese characters ** Input parameter: uint8 screen page col column *p Displayed Chinese character pointer ** Export parameters: None *********************************************************/ void Display(uint8 screen,uint8 page,uint8 col,uint8 *p) { uint8 i; Select_Screen(screen); Set_page(page); Set_Col(col); for(i=0;i<16;i++) { Write_dat(p[i]); } Set_page(page+1); Set_Col(col); for(i=0;i<16;i++) { Write_dat(p[i+16]); } }
Previous article:107: Operation of DS1302
Next article:199: Temperature reading of DS18B20
Recommended ReadingLatest update time:2024-11-16 12:55
- 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
- [LiChuang Open Source] First try of the national MCU N32G430 current meter and fast charging sampling
- 2019 Electricity Competition Power Supply Competition Topic Analysis and Data Sharing
- FPGA and Digital Image Processing
- Score points! Tell us how you have prepared for the eSports tournament so far and what you think.
- Prize live broadcast opens up IoT society Nichicon's new power storage device
- SensorTile.box_--Unicleo-GUI debugging tutorial
- What are the main parameters for selecting magnetic beads?
- Learn embedded development from engineers——Based on STM32 and μC/OS-III
- What is the output/input impedance value of CC2xxx?
- EEWORLD University Hall----Live Replay: Infineon & Intron Explanation- How to Choose a Suitable Automotive MOSFET