Guest User

Untitled

a guest
Oct 21st, 2019
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<msp430x14x.h>
  2.  
  3.  
  4.  
  5. ///DEFINICJE---------------------------------------------------------------------------------------
  6. #define bitset(var, bitno) ((var) |= 1 << (bitno)) //toggle E for LCD
  7. #define bitclr(var, bitno) ((var) &= ~(1 << (bitno)))
  8.  
  9. #define LCD_Data P2OUT
  10. #define _100us 100 //
  11. #define _10us 10 //
  12. #define E 3 //P2.3
  13. #define RS 2 //P2.2
  14.  
  15. #define CLR_DISP 0x01 // clear display
  16. #define CUR_HOME 0x02 // return home
  17. #define ENTRY_INC 0x06 // entry mode increment
  18. #define ENTRY_INC_ROL 0x07 // entry mode increment with rol data
  19. #define ENTRY_DEC 0x04 // entry mode decrement
  20. #define ENTRY_DEC_ROL 0x05 // entry mode decrement witch rol dat
  21. #define DISP_OFF 0x08 // all display offconst char font0[8] = {0x10, 0x10, 0x10, 0x14, 0x18, 0x10, 0x1E, 0x00};
  22. #define DISP_ON 0x0c // all display on
  23.  
  24. #define DATA_ROL_LEFT 0x18 // rol data left
  25. #define DATA_ROL_RIGHT 0x1c // rol data right
  26. #define CUR_SHIFT_LEFT 0x10 // shift coursor left
  27. #define CUR_SHIFT_RIGHT 0x14 // shift coursor right
  28.  
  29. #define DD_RAM_ADDR 0x80 // set DD_RAM
  30. #define DD_RAM_ADDR2 0xc0 // set CG_RAM
  31. #define DD_RAM_ADDR3 0x28 //
  32. #define CG_RAM_ADDR 0x40 //
  33. ///KONIEC DEFINICJI-----------------------------------------------------------------------------------
  34.  
  35. /*unsigned char i;
  36. unsigned char znak;
  37. */
  38. ///deklaracje
  39.  
  40. void InitPortsLcd(void); //inicjalizacja portów
  41. void InitLCD(void);
  42.  
  43. void clearDisplay();
  44.  
  45. void gotoSecondLine();
  46.  
  47. void Delay(unsigned int a);
  48.  
  49. void Delayx100us(unsigned char b);
  50.  
  51. void _E(void);
  52.  
  53. void SEND_CHAR(unsigned char d);
  54.  
  55. void SEND_CMD(unsigned char e);
  56.  
  57. void printFloat(float number);
  58.  
  59.  
  60. ///FUNKCJE-------------------------------------------------------------
  61. void InitPortsLcd(void) //inicjalizacja portów
  62. {
  63.  
  64. P2SEL = 0;
  65. P2OUT = 0;
  66. P2DIR = ~BIT0; //only P2.0 is input
  67. }
  68.  
  69. void InitLCD(void) {
  70. bitclr(P2OUT, RS);
  71. Delayx100us(250); //Delay 100ms
  72. Delayx100us(250);
  73. Delayx100us(250);
  74. Delayx100us(250);
  75. LCD_Data |= BIT4 | BIT5; //D7-D4 = 0011
  76. LCD_Data &= ~BIT6 & ~BIT7;
  77. _E(); //toggle E for LCD
  78. Delayx100us(100); //10ms
  79. _E(); //toggle E for LCD
  80. Delayx100us(100); //10ms
  81. _E(); //toggle E for LCD
  82. Delayx100us(100); //10ms
  83. LCD_Data &= ~BIT4;
  84. _E(); //toggle E for LCD
  85.  
  86. SEND_CMD(DISP_ON);
  87. SEND_CMD(CLR_DISP);
  88. Delayx100us(250);
  89. Delayx100us(250);
  90. Delayx100us(250);
  91. Delayx100us(250);
  92. }
  93.  
  94. void clearDisplay() {
  95. SEND_CMD(CLR_DISP);
  96. Delayx100us(10);
  97. }
  98.  
  99. void gotoSecondLine() {
  100. SEND_CMD(DD_RAM_ADDR2);
  101. }
  102.  
  103. void Delay(unsigned int a) {
  104. int k;
  105. for (k = 0; k != a; ++k) {
  106. _NOP();
  107. _NOP();
  108. _NOP();
  109. _NOP();
  110. }
  111. }
  112.  
  113. void Delayx100us(unsigned char b) {
  114. int j;
  115. for (j = 0; j != b; ++j) Delay(_100us);
  116. }
  117.  
  118. void _E(void) {
  119. bitset(P2OUT, E); //toggle E for LCD
  120. Delay(_10us);
  121. bitclr(P2OUT, E);
  122. }
  123.  
  124. void SEND_CHAR(unsigned char d) {
  125. int temp;
  126. Delayx100us(5); //.5ms
  127. temp = d & 0xf0; //get upper nibble
  128. LCD_Data &= 0x0f;
  129. LCD_Data |= temp;
  130. bitset(P2OUT, RS); //set LCD to data mode
  131. _E(); //toggle E for LCD
  132. temp = d & 0x0f;
  133. temp = temp << 4; //get down nibble
  134. LCD_Data &= 0x0f;
  135. LCD_Data |= temp;
  136. bitset(P2OUT, RS); //set LCD to data mode
  137. _E(); //toggle E for LCD
  138. }
  139.  
  140. void SEND_CMD(unsigned char e) {
  141. int temp;
  142. Delayx100us(10); //10ms
  143. temp = e & 0xf0; //get upper nibble
  144. LCD_Data &= 0x0f;
  145. LCD_Data |= temp; //send CMD to LCD
  146. bitclr(P2OUT, RS); //set LCD to CMD mode
  147. _E(); //toggle E for LCD
  148. temp = e & 0x0f;
  149. temp = temp << 4; //get down nibble
  150. LCD_Data &= 0x0f;
  151. LCD_Data |= temp;
  152. bitclr(P2OUT, RS); //set LCD to CMD mode
  153. _E(); //toggle E for LCD
  154. }
  155.  
  156. /*---------- WLASNE FUNKCJE -------------*/
  157.  
  158. void printFloat(float number) {
  159. char array[32];
  160. sprintf(array, "%f", number);
  161. for (int i = 0; i < 32; i++) {
  162. if (i == 17) SEND_CMD(DD_RAM_ADDR2);
  163. SEND_CHAR(array[i]);
  164. }
  165. }
  166.  
  167.  
  168. /* KONIEC WLASNYCH FUNKCJI*/
  169.  
  170.  
  171. ///KONIEC FUNKCJI------------------------------------------------------
  172.  
  173.  
  174.  
  175.  
  176. ///_____________M A I N___________________________________
  177. void main(void) {
  178. WDTCTL = WDTPW + WDTHOLD; // zatrzymanie WDT
  179.  
  180. InitPortsLcd(); // inicjalizacja portów
  181. InitLCD(); // inicjalizacja LCD
  182. clearDisplay(); // czyszczenie LCD
  183.  
  184. SEND_CMD(CG_RAM_ADDR);
  185.  
  186. printFloat(32.323232f);
  187. }
RAW Paste Data