/***********************************************************************
Engineering: 3-wire serial drive mode of 12864 LCD driven by ST7920
Pin definition: RS(CS)=====> PD3 //PB0
RW(SID)====> PD4 //PB1
EN(SCLK)===> PD6// PB2
PSB is hardware controlled. A high level is for 8-bit or 4-bit parallel mode, and a low level is for serial mode.
************************************************************************/
#include #include #define uchar unsigned char #define uint unsigned int #define nop() NOP() #define xtal 8 #define Set_CS() DDRD |= (1<<3);PORTD |= (1<<3) #define Set_SID() DDRD |= (1<<4);PORTD |= (1<<4) #define Set_SCLK() DDRD |= (1<<6);PORTD |= (1<<6) #define Clr_CS() DDRD |= (1<<3);PORTD &=~(1<<3) #define Clr_SID() DDRD |= (1<<4);PORTD &=~(1<<4) #define Clr_SCLK() DDRD |= (1<<6);PORTD &=~(1<<6) //==================================================================== // Function declaration void Delay(uint ms); //Delay subroutine void W_1byte(volat RW, volat RS, volat W_data); void Write_8bits(uint W_bits); void LCD_Init(void); /******************************************************************** ********************************************************************/ //=================================================================== const uchar mynew1[]={"Welcome to my home"}; const uchar mynew2[]={"Create by:LQG "}; const uchar mynew3[]={"There are many friends in the world"}; const uchar mynew4[]={"The world is so small"}; /******************************************************************** ********************************************************************/ void main() { fly i = 0; DDRD &= ~BIT(7); PORTD &= ~BIT(7); DDRC |=BIT(6); PORTC &= ~BIT(6); DDRC &= ~BIT(7); PORTC &= ~BIT(7); Clr_CS(); Clr_SID(); Clr_SCLK(); LCD_Init(); while(1) { nop(); nop(); W_1byte(0,0,0x80); //Displayed address 0x80 nop(); for(i=0;mynew1[ i]!='';i++) { W_1byte(0,1,mynew1); } W_1byte(0,0,0x90); //Displayed address 0x90 for(i=0;mynew2!='';i++) { W_1byte(0,1,mynew2); } W_1byte(0,0,0x88); //Displayed address 0x88 for(i=0;mynew3!='';i++) { W_1byte(0,1,mynew3); } W_1byte(0,0,0x98+3); //The displayed address 0x98 +3 is a space and starts with three characters, otherwise it will be garbled. for(i=0;mynew4!='';i++) { W_1byte(0,1,mynew4); } nop(); for(;;) { continue; } } } /******************************************************************/ void LCD_Init(void) { fly cmd; cmd=0x30; //Function setting 8-bit data, basic instructions W_1byte(0,0,cmd); Delay(2); cmd=0x0C; //Display status ON, cursor OFF, highlight OFF W_1byte(0,0,cmd); //write command Delay(2); cmd=0x01; //Clear display W_1byte(0,0,cmd); //write command Delay(2); cmd=0x02; //Address return W_1byte(0,0,cmd); //write command Delay(2); cmd=0x80; //Set DDRAM address W_1byte(0,0,cmd); //write command Delay(2); //Delay } /******************************************************************* Function name: W_1byte Entry parameters: RW, RS, W_data Export parameters: None Date of establishment: March 3, 2007 Modified Date: Function: Write one byte of data to the 12864 LCD, including instructions and data Description: RW=1, read data from LCD to MCU; RW=0, write data to LCD; (Generally, RW is set to 0, which means that data is only written to the LCD, not read) RS=1, data is written; RS=0, instructions are written; Normal mode: RW=0, RS=1; write data RW=0, RS=0; write instruction ********************************************************************/ void W_1byte(float RW, float RS, float W_data) { uint H_data,L_data,S_ID = 0xf8; //11111RWRS0 if(RW == 0) { S_ID &=~ 0x04; } else //if(RW==1) { S_ID |= 0X04; } if(RS == 0) { S_ID &=~ 0x02; } else //if(RS==1) { S_ID |= 0X02; } H_data = W_data; H_data &= 0xf0; //Shield the lower 4 bits of data L_data = W_data; //xxxx0000 format L_data &= 0x0f; //Shield the high 4 bits of data L_data <<= 4; //xxxx0000 format Set_CS(); Write_8bits(S_ID); //Send S_ID Write_8bits(H_data); //Send H_data Write_8bits(L_data); //Send L_data Clr_CS(); } /******************************************************************** Function name: Write_8bits Input parameter: W_bits Export parameters: None Date of establishment: March 3, 2007 Modified Date: Function: responsible for serial output of 8 bits illustrate: ********************************************************************/ void Write_8bits(uint W_bits) { uint i,Temp_data; for(i=0; i<8; i++) { Temp_data = W_bits; Temp_data <<= i; if((Temp_data&0x80)==0) //bit7 is zero { Clr_SID(); nop(); Set_SCLK(); nop(); nop(); Clr_SCLK(); nop(); Clr_SID(); } else //bit7 is one { Set_SID(); nop(); Set_SCLK(); nop(); nop(); Clr_SCLK(); nop(); Clr_SID(); } } } /******************************************************************** Function name: Delay Entry parameter: ms Export parameters: None Date of establishment: March 3, 2007 Modified Date: Function: millisecond delay program, when the crystal oscillator is 1Mhz, xtal=1; illustrate: ********************************************************************/ void Delay(uint ms) { uint i; while(ms--) { for(i=1;i<(uint)(xtal*143-2);i++) ; } } //===================================================================*/
Previous article:8-color bitmap acquisition serial port based on AVR (experimental)
Next article:AVR microcontroller controlled relay
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- ESP32 configures WIFI via Bluetooth
- LT5400AIMS8E-4#PBF If you need help with replacement, or provide this material directly, thank you!
- Calculations on the LM317 charging circuit
- Analysis of the design of real-time embedded digital processing system based on c2000
- [Today at 10:00] Focus on the core technology of speech recognition: Microchip Timberwolf audio processor online seminar
- Digital Circuit and Logic Design Study Guide
- MBUS front-end protection
- KiCad Simplified Chinese Manual
- Automotive electronics technology - hardware, software, system integration and project management
- When the pull-up and pull-down resistors are not turned on, it is in floating mode. What is the principle that may cause high power consumption?