12864 control forMSP430

Publisher:脑电狂潮Latest update time:2015-09-17 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
 
  1. /***************************************************************** 
  2. //File name: 12864.c 
  3. //Description: This file defines various interfaces and functions related to 12864, applicable to MSP430F149 
  4. //Written by: Xiaoxie@清水 
  5. //Version number: 2.01 
  6. *****************************************************************/  
  7.   
  8. #include   
  9. #include "12864.h"  
  10. #define uchar unsigned char   
  11. #define uint unsigned int   
  12.   
  13. #define BIT(x)  (1 << (x))  
  14. unsigned char NUM[] = {"0123456789."};  
  15. uchar Address[4][8] = {  
  16.         {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87},  
  17.         {0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97},  
  18.         {0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f},  
  19.         {0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f}  
  20.         };  
  21.   
  22. /***************************************************************** 
  23. //Some macro definitions about 12864 
  24. //Note: All data must be changed according to the actual IO port used 
  25. *****************************************************************/  
  26. #define CS      0                                               //CS  = P3.0  
  27. #define SID     1                                               //SID = P3.1    
  28. #define CLK     2                                               //CLK = P3.2  
  29. #define PORT    P3OUT    
  30. #define DIR P3DIR  
  31.   
  32. /************************************************************************* 
  33. //Name: delay_Nus 
  34. //Parameter: delay time n 
  35. //Return value: None 
  36. //Function: Delay time n Ns 
  37. *************************************************************************/  
  38. void delay_Nus(uint n)  
  39. {  
  40.     flying i;  
  41.     for(i = n;i > 0;i--)  
  42.         _NOP();  
  43. }  
  44.   
  45. /************************************************************************* 
  46. //Name: delay_1ms 
  47. //Parameters: None 
  48. //Return value: None 
  49. //Function: Delay 1 ms 
  50. *************************************************************************/   
  51. void delay_1ms(void)  
  52. {  
  53.     flying i;  
  54.     for(i = 150;i > 0;i--)     _NOP();  
  55. }   
  56.   
  57. /************************************************************************* 
  58. //Name: delay_Nms 
  59. //Parameter: delay time n 
  60. //Return value: None 
  61. //Function: Delay 1 ms 
  62. *************************************************************************/  
  63. void delay_Nms(uint n)  
  64. {  
  65.     uint i = 0;  
  66.       
  67.     for(i = n;i > 0;i--)  
  68.         delay_1ms();  
  69. }  
  70.   
  71. /************************************************************************* 
  72. //Name: LcdInit 
  73. //Parameters: None 
  74. //Return value: None 
  75. //Function: Initialize 12864 
  76. *************************************************************************/  
  77. void LcdInit(void)  
  78. {     
  79.     DIR |= BIT(CLK) + BIT(SID) + BIT(CS); //The corresponding bit port is set to output  
  80.     delay_Nms(100); //Delay to wait for LCD to reset  
  81.     Send(0,0x30); //Function setting: send 8 bits of data at a time, basic instruction set  
  82.     delay_Nus(72);  
  83.     Send(0,0x02); //DDRAM address reset  
  84.     delay_Nus(72);  
  85.     Send(0,0x0c); //Display setting: turn on display, do not display cursor, do not highlight and flash the current display position  
  86.     delay_Nus(72);  
  87.     Send(0,0x01); //Clear the screen and adjust the DDRAM address counter to "00H"  
  88.     delay_Nus(72);  
  89.     Send(0,0x06); //Function setting, point setting: display characters/cursor shifts from left to right, DDRAM address plus 1  
  90.     delay_Nus(72);        
  91. }    
  92.   
  93. /************************************************************************* 
  94. //Name: Send 
  95. //Parameter: data type type: 0--control command, 1--display data, transdata--sent data 
  96. //Return value: None 
  97. //Function: Send a byte of data to 12864, which can be used to control the display 
  98. *************************************************************************/  
  99. void Send(uchar type,uchar transdata)  
  100. {  
  101.     fly firstbyte = 0xf8;  
  102.     flying tempo;  
  103.     fly i,j = 3;  
  104.     if(type) firstbyte |= 0x02;  
  105.     PORT |=  BIT(CS);             
  106.     PORT &= ~BIT(CLK);        
  107.     while(j > 0)  
  108.     {  
  109.         if(j == 3) temp = firstbyte;  
  110.         else if(j == 2) temp = transdata&0xf0;  
  111.         else  temp = (transdata << 4) & 0xf0;  
  112.         for(i = 8;i > 0;i--)  
  113.         {  
  114.             if(temp & 0x80) PORT |=  BIT(SID);   
  115.             else        PORT &= ~BIT(SID);            
  116.             PORT |= BIT(CLK);                 
  117.             temp <<= 1;  
  118.             PORT &= ~BIT(CLK);  
  119.         } // There must be enough delay between the three bytes, otherwise timing problems may occur  
  120.         if(j == 3) delay_Nus(600);   
  121.         else       delay_Nus(200);  
  122.         j--;  
  123.     }   
  124.     PORT &= ~BIT(SID);         
  125.     PORT &= ~BIT(CS);         
  126. }  
  127.   
  128. /************************************************************************* 
  129. //Name: Clear_GDRAM 
  130. //Parameter: data type type: 0--control command, 1--display data, transdata--sent data 
  131. //Return value: None 
  132. //Function: Send a byte of data to 12864, which can be used to control the display 
  133. *************************************************************************/  
  134. void Clear_GDRAM(void)  
  135. {  
  136.     flying i,j,k;  
  137.     Send(0,0x34); //Open the extended instruction set  
  138.     i = 0x80;              
  139.     for(j = 0;j < 32;j++)  
  140.     {  
  141.         Send(0,i++);         
  142.         Send(0,0x80);    
  143.         for(k = 0;k < 16;k++)  
  144.         {  
  145.             Send(1,0x00);   
  146.         }  
  147.     }  
  148.     i = 0x80;  
  149.     for(j = 0;j < 32;j++)  
  150.     {  
  151.         Send(0,i++);         
  152.         Send(0,0x88);        
  153.         for(k = 0;k < 16;k++)  
  154.         {  
  155.             Send(1,0x00);   
  156.         }   
  157.     }     
  158.     Send(0,0x30); //Return to basic instruction set     
  159. }  
  160.   [page]
  161. /************************************************************************* 
  162. //Name: WriteStr 
  163. //Parameters: display address addr, pointer to data to be displayed, display length 
  164. //Return value: None 
  165. //Function: Display the string at the specified position 12864, including Chinese characters 
  166.           The characters in the ASCII code table can be displayed, but the length should be halved 
  167. *************************************************************************/  
  168. void WriteStr(uchar addr,const uchar * pt,uchar num)  
  169. {  
  170.     flying i;  
  171.     Send(0,addr);            
  172.     for(i = 0;i < (num*2);i++)   
  173.        Send(1,*(pt++));   
  174. }   
  175.   
  176. /************************************************************************* 
  177. //Name: DrawPic 
  178. //Parameter: pointer to the image to be displayed 
  179. //Return value: None 
  180. //Function: Draw a picture on the entire screen 
  181. *************************************************************************/  
  182. void DrawPic(const uchar *ptr)  
  183. {  
  184.     flying i,j,k;  
  185.     Send(0,0x34); //Open the extended instruction set  
  186.     i = 0x80;              
  187.     for(j = 0;j < 32;j++)  
  188.     {  
  189.         Send(0,i++);         
  190.         Send(0,0x80);    
  191.         for(k = 0;k < 16;k++)  
  192.         {  
  193.             Send(1,*ptr++);   
  194.         }  
  195.     }  
  196.     i = 0x80;  
  197.     for(j = 0;j < 32;j++)  
  198.     {  
  199.         Send(0,i++);         
  200.         Send(0,0x88);        
  201.         for(k = 0;k < 16;k++)  
  202.         {  
  203.             Send(1,*ptr++);   
  204.         }   
  205.     }  
  206.     Send(0,0x36); //Open drawing display  
  207.     Send(0,0x30); //Return to basic instruction set     
  208. }  
  209.   
  210. /************************************************************************* 
  211. //Name: Draw1Pic 
  212. //Parameters: Yaddr--Y address, Xaddr--X address 
  213. //Return value: None 
  214. //Function: Draw a 16*16 graphic on the LCD 
  215. *************************************************************************/  
  216. void Draw1Pic(volat Memory,volat Hd,const volat * dp)   
  217. {  
  218.     flying j;  
  219.     uchar k = 0;  
  220.     Send(0,0x34); //Use extended instruction set to turn off drawing display  
  221.     for(j = 0;j < 16;j++)  
  222.     {  
  223.         Send(0,Yaddr++); //Y address    
  224.         Send(0,Xaddr); //X address  
  225.         Send(1,dp[k++]); //Send two bytes of display data   
  226.         Send(1,dp[k++]);                  
  227.     }  
  228.     Send(0,0x36); //Open drawing display  
  229.     Send(0,0x30); //Return to basic instruction set mode  
  230. }  
  231.   
  232. /************************************************************************* 
  233. //Name: LocateXY 
  234. //Parameters: address to be written, horizontal coordinate X, vertical coordinate Y (starting from 0) 
  235. //Return value: None 
  236. //Function: 12864 pointer points to the specified location 
  237. *************************************************************************/  
  238. void LocateXY(float X, float Y)  
  239. {  
  240.     Send(0,Address[Y][X]);  
  241. }  
  242.   
  243. /************************************************************************* 
  244. //Name: WriteNum 
  245. //Parameters: Number to be written Num, horizontal coordinate X, vertical coordinate Y (starting from 0) 
  246. //Return value: None 
  247. //Function: Display a number at the specified position (no more than 5 digits and less than 65536) 
  248. *************************************************************************/  
  249. void WriteNum(uint n,writer x,writer y)  
  250. {  
  251.     uchar five,four,three,two,one;  
  252.     LocateXY(x,y);  
  253.     if((n >= 10000)&&(n <= 65535))  
  254.     {  
  255.         five = n / 10000;  
  256.         four = (n % 10000) / 1000;  
  257.         three = ((n - five * 10000) % 1000) / 100;  
  258.         two = ((n - five * 10000) % 1000 - three * 100 ) / 10;  
  259.         one = ((n - five * 10000) % 1000 - three * 100 ) % 10;  
  260.         Send(1,NUM[five]);  
  261.         Send(1,NUM[four]);  
  262.         Send(1,NUM[three]);  
  263.         Send(1,NUM[two]);  
  264.         Send(1,NUM[one]);  
  265.     }  
  266.     if((n >= 1000)&&(n <= 9999))  
  267.     {  
  268.         four = n / 1000;  
  269.         three = (n % 1000) / 100;  
  270.         two = (n % 1000 - three * 100 ) / 10;  
  271.         one = (n % 1000 - three * 100 ) % 10;  
  272.         Send(1,NUM[four]);  
  273.         Send(1,NUM[three]);  
  274.         Send(1,NUM[two]);  
  275.         Send(1,NUM[one]);  
  276.     }  
  277.     if((n >= 100)&&(n <= 999))  
  278.     {  
  279.         three = n / 100;  
  280.         two = (n - three * 100 ) / 10;  
  281.         one = (n - three * 100 ) % 10;  
  282.         Send(1,NUM[three]);  
  283.         Send(1,NUM[two]);  
  284.         Send(1,NUM[one]);  
  285.     }  
  286.     if((n >= 10)&&(n <= 99))  
  287.     {  
  288.         two = n / 10;  
  289.         one = n % 10;  
  290.         Send(1,NUM[two]);  
  291.         Send(1,NUM[one]);  
  292.     }  
  293.     if((n >= 0)&&(n <= 9))Send(1,NUM[n]);  
  294. }  
  295.   
  296. /************************************************************************* 
  297. //Name: WriteFloat 
  298. //Parameters: floating point number to be written, unsigned char x, unsigned char y 
  299. //Return value: None 
  300. //Function: Display a floating point number at a given position (both the integer part and the decimal part do not exceed two digits) 
  301. *************************************************************************/  
  302. void WriteFloat(float n, float x, float y)  
  303. {  
  304.     uint Integer, Decimal; //Integer is used to store the integer part, Decimal is used to store the decimal part  
  305.     Integer = (uint)(n/1);  
  306.     Decimal = (uint)(n * 100 - Integer * 100);  
  307.         if(Integer<10)  
  308.         {  
  309.           LocateXY(x,y);  
  310.           Send(1,' ');  
  311.           WriteNum(Integer,x+1,y);  
  312.         }  
  313.         if(Integer>=10)WriteNum(Integer,x,y);  
  314.     Send(1,NUM[10]);  
  315.     WriteNum(Decimal,x+2,y);  
  316. }  
  317.   
  318. /************************************************************************* 
  319. //名称    :WriteArrary 
  320. //Parameters: array to be written, array length, unsigned char x, unsigned char y 
  321. //Return value: None 
  322. //Function: Display an array at a given position 
  323. *************************************************************************/  
  324. void WriteArrary(uint *a,uint n,uchar x,uchar y)  
  325. {  
  326.   flying i;  
  327.   LocateXY(x,y);  
  328.   for(i = 0;i < n;i ++)  
  329.   {  
  330.     a[i] = a[i] + '0';  
  331.     Send(1,a[i]);  
  332.   }  
  333. }  
  334.  

Keywords:MSP430 Reference address:12864 control forMSP430

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]
51 MCU LCD12864 Driver C Language ST7920
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]
Design of serial communication between MSP430 microcontroller and PC based on VB6.0
51 MCU 12864 large LCD screen Tetris
Reference source code: //************************************************************************************************* //************************************************************************************************* // Program name : Tetris game** // Version Description : This version is the first version, w
[Microcontroller]
51 MCU 12864 large LCD screen Tetris
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]
MSP430F5529 (IV) Power Supply &&& (V) Operating Mode
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]
MCU-based non-invasive visual pulse oximeter circuit
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]
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号