- /*****************************************************************
- //File name: 12864.c
- //Description: This file defines various interfaces and functions related to 12864, applicable to MSP430F149
- //Written by: Xiaoxie@清水
- //Version number: 2.01
- *****************************************************************/
- #include
- #include "12864.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define BIT(x) (1 << (x))
- unsigned char NUM[] = {"0123456789."};
- uchar Address[4][8] = {
- {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87},
- {0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97},
- {0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f},
- {0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f}
- };
- /*****************************************************************
- //Some macro definitions about 12864
- //Note: All data must be changed according to the actual IO port used
- *****************************************************************/
- #define CS 0 //CS = P3.0
- #define SID 1 //SID = P3.1
- #define CLK 2 //CLK = P3.2
- #define PORT P3OUT
- #define DIR P3DIR
- /*************************************************************************
- //Name: delay_Nus
- //Parameter: delay time n
- //Return value: None
- //Function: Delay time n Ns
- *************************************************************************/
- void delay_Nus(uint n)
- {
- flying i;
- for(i = n;i > 0;i--)
- _NOP();
- }
- /*************************************************************************
- //Name: delay_1ms
- //Parameters: None
- //Return value: None
- //Function: Delay 1 ms
- *************************************************************************/
- void delay_1ms(void)
- {
- flying i;
- for(i = 150;i > 0;i--) _NOP();
- }
- /*************************************************************************
- //Name: delay_Nms
- //Parameter: delay time n
- //Return value: None
- //Function: Delay 1 ms
- *************************************************************************/
- void delay_Nms(uint n)
- {
- uint i = 0;
- for(i = n;i > 0;i--)
- delay_1ms();
- }
- /*************************************************************************
- //Name: LcdInit
- //Parameters: None
- //Return value: None
- //Function: Initialize 12864
- *************************************************************************/
- void LcdInit(void)
- {
- DIR |= BIT(CLK) + BIT(SID) + BIT(CS); //The corresponding bit port is set to output
- delay_Nms(100); //Delay to wait for LCD to reset
- Send(0,0x30); //Function setting: send 8 bits of data at a time, basic instruction set
- delay_Nus(72);
- Send(0,0x02); //DDRAM address reset
- delay_Nus(72);
- Send(0,0x0c); //Display setting: turn on display, do not display cursor, do not highlight and flash the current display position
- delay_Nus(72);
- Send(0,0x01); //Clear the screen and adjust the DDRAM address counter to "00H"
- delay_Nus(72);
- Send(0,0x06); //Function setting, point setting: display characters/cursor shifts from left to right, DDRAM address plus 1
- delay_Nus(72);
- }
- /*************************************************************************
- //Name: Send
- //Parameter: data type type: 0--control command, 1--display data, transdata--sent data
- //Return value: None
- //Function: Send a byte of data to 12864, which can be used to control the display
- *************************************************************************/
- void Send(uchar type,uchar transdata)
- {
- fly firstbyte = 0xf8;
- flying tempo;
- fly i,j = 3;
- if(type) firstbyte |= 0x02;
- PORT |= BIT(CS);
- PORT &= ~BIT(CLK);
- while(j > 0)
- {
- if(j == 3) temp = firstbyte;
- else if(j == 2) temp = transdata&0xf0;
- else temp = (transdata << 4) & 0xf0;
- for(i = 8;i > 0;i--)
- {
- if(temp & 0x80) PORT |= BIT(SID);
- else PORT &= ~BIT(SID);
- PORT |= BIT(CLK);
- temp <<= 1;
- PORT &= ~BIT(CLK);
- } // There must be enough delay between the three bytes, otherwise timing problems may occur
- if(j == 3) delay_Nus(600);
- else delay_Nus(200);
- j--;
- }
- PORT &= ~BIT(SID);
- PORT &= ~BIT(CS);
- }
- /*************************************************************************
- //Name: Clear_GDRAM
- //Parameter: data type type: 0--control command, 1--display data, transdata--sent data
- //Return value: None
- //Function: Send a byte of data to 12864, which can be used to control the display
- *************************************************************************/
- void Clear_GDRAM(void)
- {
- flying i,j,k;
- Send(0,0x34); //Open the extended instruction set
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- Send(0,i++);
- Send(0,0x80);
- for(k = 0;k < 16;k++)
- {
- Send(1,0x00);
- }
- }
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- Send(0,i++);
- Send(0,0x88);
- for(k = 0;k < 16;k++)
- {
- Send(1,0x00);
- }
- }
- Send(0,0x30); //Return to basic instruction set
- }
- [page]
- /*************************************************************************
- //Name: WriteStr
- //Parameters: display address addr, pointer to data to be displayed, display length
- //Return value: None
- //Function: Display the string at the specified position 12864, including Chinese characters
- The characters in the ASCII code table can be displayed, but the length should be halved
- *************************************************************************/
- void WriteStr(uchar addr,const uchar * pt,uchar num)
- {
- flying i;
- Send(0,addr);
- for(i = 0;i < (num*2);i++)
- Send(1,*(pt++));
- }
- /*************************************************************************
- //Name: DrawPic
- //Parameter: pointer to the image to be displayed
- //Return value: None
- //Function: Draw a picture on the entire screen
- *************************************************************************/
- void DrawPic(const uchar *ptr)
- {
- flying i,j,k;
- Send(0,0x34); //Open the extended instruction set
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- Send(0,i++);
- Send(0,0x80);
- for(k = 0;k < 16;k++)
- {
- Send(1,*ptr++);
- }
- }
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- Send(0,i++);
- Send(0,0x88);
- for(k = 0;k < 16;k++)
- {
- Send(1,*ptr++);
- }
- }
- Send(0,0x36); //Open drawing display
- Send(0,0x30); //Return to basic instruction set
- }
- /*************************************************************************
- //Name: Draw1Pic
- //Parameters: Yaddr--Y address, Xaddr--X address
- //Return value: None
- //Function: Draw a 16*16 graphic on the LCD
- *************************************************************************/
- void Draw1Pic(volat Memory,volat Hd,const volat * dp)
- {
- flying j;
- uchar k = 0;
- Send(0,0x34); //Use extended instruction set to turn off drawing display
- for(j = 0;j < 16;j++)
- {
- Send(0,Yaddr++); //Y address
- Send(0,Xaddr); //X address
- Send(1,dp[k++]); //Send two bytes of display data
- Send(1,dp[k++]);
- }
- Send(0,0x36); //Open drawing display
- Send(0,0x30); //Return to basic instruction set mode
- }
- /*************************************************************************
- //Name: LocateXY
- //Parameters: address to be written, horizontal coordinate X, vertical coordinate Y (starting from 0)
- //Return value: None
- //Function: 12864 pointer points to the specified location
- *************************************************************************/
- void LocateXY(float X, float Y)
- {
- Send(0,Address[Y][X]);
- }
- /*************************************************************************
- //Name: WriteNum
- //Parameters: Number to be written Num, horizontal coordinate X, vertical coordinate Y (starting from 0)
- //Return value: None
- //Function: Display a number at the specified position (no more than 5 digits and less than 65536)
- *************************************************************************/
- void WriteNum(uint n,writer x,writer y)
- {
- uchar five,four,three,two,one;
- LocateXY(x,y);
- if((n >= 10000)&&(n <= 65535))
- {
- five = n / 10000;
- four = (n % 10000) / 1000;
- three = ((n - five * 10000) % 1000) / 100;
- two = ((n - five * 10000) % 1000 - three * 100 ) / 10;
- one = ((n - five * 10000) % 1000 - three * 100 ) % 10;
- Send(1,NUM[five]);
- Send(1,NUM[four]);
- Send(1,NUM[three]);
- Send(1,NUM[two]);
- Send(1,NUM[one]);
- }
- if((n >= 1000)&&(n <= 9999))
- {
- four = n / 1000;
- three = (n % 1000) / 100;
- two = (n % 1000 - three * 100 ) / 10;
- one = (n % 1000 - three * 100 ) % 10;
- Send(1,NUM[four]);
- Send(1,NUM[three]);
- Send(1,NUM[two]);
- Send(1,NUM[one]);
- }
- if((n >= 100)&&(n <= 999))
- {
- three = n / 100;
- two = (n - three * 100 ) / 10;
- one = (n - three * 100 ) % 10;
- Send(1,NUM[three]);
- Send(1,NUM[two]);
- Send(1,NUM[one]);
- }
- if((n >= 10)&&(n <= 99))
- {
- two = n / 10;
- one = n % 10;
- Send(1,NUM[two]);
- Send(1,NUM[one]);
- }
- if((n >= 0)&&(n <= 9))Send(1,NUM[n]);
- }
- /*************************************************************************
- //Name: WriteFloat
- //Parameters: floating point number to be written, unsigned char x, unsigned char y
- //Return value: None
- //Function: Display a floating point number at a given position (both the integer part and the decimal part do not exceed two digits)
- *************************************************************************/
- void WriteFloat(float n, float x, float y)
- {
- uint Integer, Decimal; //Integer is used to store the integer part, Decimal is used to store the decimal part
- Integer = (uint)(n/1);
- Decimal = (uint)(n * 100 - Integer * 100);
- if(Integer<10)
- {
- LocateXY(x,y);
- Send(1,' ');
- WriteNum(Integer,x+1,y);
- }
- if(Integer>=10)WriteNum(Integer,x,y);
- Send(1,NUM[10]);
- WriteNum(Decimal,x+2,y);
- }
- /*************************************************************************
- //名称 :WriteArrary
- //Parameters: array to be written, array length, unsigned char x, unsigned char y
- //Return value: None
- //Function: Display an array at a given position
- *************************************************************************/
- void WriteArrary(uint *a,uint n,uchar x,uchar y)
- {
- flying i;
- LocateXY(x,y);
- for(i = 0;i < n;i ++)
- {
- a[i] = a[i] + '0';
- Send(1,a[i]);
- }
- }
Previous article:MSP430 Learning Notes (1) Watchdog
Next article:1602 control forMSP430
Recommended ReadingLatest update time:2024-11-17 00:55
51 MCU LCD12864 Driver C Language ST7920
main.c #include "reg52.h" #include intrins.h #include string.h #include stdio.h #include stdlib.h #include "LCD12864.h" void main( void ) { This_Lcd(); Lcd_WriteStr(0,0,"QQ137712826"); while ( 1 ) { } } lcd12864.h #include reg52.h #include intrins.h sbit RS = P2 ^ 0; sbit RW = P
[Microcontroller]
Design of serial communication between MSP430 microcontroller and PC based on VB6.0
Serial communication has become the most widely used communication method for data exchange between computers and other devices. This paper mainly introduces how to use the serial communication module of MSP430 microcontroller and the serial communication control MSComm provided by VB6.0 to realize serial communicat
[Microcontroller]
51 MCU 12864 large LCD screen Tetris
Reference source code: //************************************************************************************************* //************************************************************************************************* // Program name : Tetris game** // Version Description : This version is the first version, w
[Microcontroller]
Design scheme based on MSP430 single chip microcomputer module
At present, energy shortage has become an important factor restricting social and economic development. How to achieve efficient use of energy is an important issue we face. As a new type of green light source product, LED has the characteristics of energy saving, environmental protection, long life and small size
[Microcontroller]
MSP430F5529 (IV) Power Supply &&& (V) Operating Mode
I think power management and monitoring is a very complex and difficult part to master. It not only involves the selection of source mode, but also involves complex interrupts and how to handle interrupts, etc. Although learning this part well is very helpful to achieve the goal of reducing power consumption, it seems
[Microcontroller]
MCU-based non-invasive visual pulse oximeter circuit
A pulse oximeter is a medical device used to monitor a patient's blood oxygen level. The device measures blood oxygen and heart rate and generates an alarm when it drops below a predetermined threshold. This type of monitoring is extremely useful for newborns and during surgical procedures. The MSP430FG437 microcontro
[Microcontroller]
Notes on C language programming for MSP430
================================================== ================================================== ========================== Microprocessors are generally used in specific environments and for specific purposes. Considering cost, power consumption and size, it is generally required to save resources as much as pos
[Microcontroller]
Design of WSN node based on MSP430 and NRF2401
0 Introduction
Wireless sensor network (WSN) is a self-organizing network that consists of a large number of low-cost, resource-limited sensor node devices that work together to achieve a specific task. Due to the characteristics of easy scalability, self-organization, distributed structure and real-time pe
[Microcontroller]
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Single-chip microcomputer C language programming and simulation
- MSP430 series single chip microcomputer system engineering design and practice
- STC8 series MCU development guide: analysis and application of processors, programming and operating systems
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Digitally controlled DCDC converter
- How to deal with the prompt "Transient time point calculation did not converge" during Multisim simulation
- What are the configurations of the computer that ranks fourth in the world?
- Hahaha
- The development board is connected to the Internet via a shared network
- Thonny Python Editor upgraded to 4.0.0 Beta1
- control
- DSP water light source program
- Embracing the era of big data and interpreting 5G communication clock synchronization technology
- 【CH579M-R1】+W25Q16 storage module reading and writing