Advertisement
RuiViana

Float com Ponto

Jul 24th, 2015
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. #include <16F877a.h> //O PIC utilizado, obrigatório!
  2.  
  3. #FUSES NOWDT //Sem Watch dog, evitando reset
  4. #FUSES XT //Crystal de oscilação igual a 4mhz
  5. #FUSES PUT //Tempo de início do PIC
  6. #FUSES NOPROTECT //Codigo sem proteção de leitura, software livre!
  7. #FUSES NODEBUG //No Debug mode for ICD
  8. #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
  9. #FUSES NOCPD //No EE protection
  10.  
  11. #use delay(clock=4000000)
  12. #include <lcd.c>
  13.  
  14. //t16 rpm;
  15. int8 aux;
  16. int8 escreve_numero;
  17. int n1 = 0;
  18. int n2 = 0;
  19. int n3 =0;
  20. int n4 =0;
  21. int n5 = 0x46; // Caracter ponto decimal
  22. int nx;
  23. int8 linha;
  24. long value;
  25. //---------------------------------------------------------------
  26. void lcd_load_custom_chars(void);
  27. //---------------------------------------------------------------
  28. void escreve_numero(int8 *numero, linha);
  29.  
  30. int8 num[10][6] ={ {5, 2, 5, 5, 3, 5},
  31. {2, 5, 1, 3, 5, 3},
  32. {2, 4, 5, 5, 3, 3},
  33. {2, 4, 5, 3, 3, 5},
  34. {5, 3, 5, 1, 1, 5},
  35. {5, 4, 2, 3, 3, 5},
  36. {5, 4, 2, 5, 3, 5},
  37. {2, 2, 5, 1, 1, 5},
  38. {5, 4, 5, 5, 3, 5},
  39. {5, 4, 5, 3, 3, 5} };
  40. //--------------------------------------------------------------
  41. void escreve_numero(int8 *numero, int8 linha) {
  42. int8 j;
  43. int8 k;
  44. int8 aux= 0;
  45.  
  46. for (k=1; k<=2; k++) {
  47. for (j=0; j<=2; j++) {
  48. lcd_gotoxy(linha + j, k);
  49. lcd_putc(numero[aux]);
  50. aux++;
  51. }
  52. }
  53. }
  54. //--------------------------------------------------------------
  55. void main(void) {
  56. lcd_init();
  57. lcd_load_custom_chars();
  58. delay_ms (50);
  59. linha= 1;
  60.  
  61. while (TRUE) {
  62. float test = 21.38; // Variavel para guardar valor float com 2 casas decimair
  63. long value ; // Variavel para guardar valor em long
  64. value = (long)(test*100); // Multiplica float por 100 para zerar 2 casas depois da virgula, e
  65. // Transforma o float em long
  66. n1 = ((value/1000)%10); // Calcula valor digito milhar
  67. n2 = ((value/100)%10); // Calcula valor digito centena
  68. n3 = ((value/10)%10); // Calcula valor digito dezena
  69. n4 = ((value)%10); // Calcula valor digito unidade
  70.  
  71. escreve_numero(num[n1], 1);
  72. escreve_numero(num[n2], 5);
  73. escreve_numero(num[n5], 9); // Manda o caracter ponto decimal
  74. escreve_numero(num[n3], 13);
  75. escreve_numero(num[n4], 17);
  76. }
  77. }
  78. //----------------------------------------------------------------
  79. const int8 lcd_custom_chars[]=
  80. {
  81. 0b00011111, //2 em cima (0)
  82. 0b00011111,
  83. 0b00000000,
  84. 0b00000000,
  85. 0b00000000,
  86. 0b00000000,
  87. 0b00000000,
  88. 0b00000000,
  89.  
  90. 0b00000000, //nada (1)
  91. 0b00000000,
  92. 0b00000000,
  93. 0b00000000,
  94. 0b00000000,
  95. 0b00000000,
  96. 0b00000000,
  97. 0b00000000
  98.  
  99. 0b00011111, //3 em cima (2)
  100. 0b00011111,
  101. 0b00000000,
  102. 0b00000000,
  103. 0b00000000,
  104. 0b00000000,
  105. 0b00000000,
  106. 0b00000000,
  107.  
  108. 0b00000000, //3 em baixo (3)
  109. 0b00000000,
  110. 0b00000000,
  111. 0b00000000,
  112. 0b00000000,// alterado
  113. 0b00000000,
  114. 0b00011111,
  115. 0b00011111, // alterado
  116.  
  117. 0b00011111, //2 em cima e 2 em baixo (4)
  118. 0b00011111,
  119. 0b00000000,
  120. 0b00000000,
  121. 0b00000000,
  122. 0b00000000,
  123. 0b00011111,
  124. 0b00011111,
  125.  
  126. 0b00011111, //completo (5)
  127. 0b00011111,
  128. 0b00011111,
  129. 0b00011111,
  130. 0b00011111,
  131. 0b00011111,
  132. 0b00011111,
  133. 0b00011111, // alterado
  134.  
  135. 0b00000000,
  136. 0b00000000,
  137. 0b00000000,
  138. 0b00000000,
  139. 0b00000000,
  140. 0b00000000,
  141. 0b00000000,
  142. 0b00000000,
  143.  
  144. 0b00000000,
  145. 0b00000000,
  146. 0b00000000,
  147. 0b00000000,
  148. 0b00000000,
  149. 0b00000000,
  150. 0b00000000,
  151. 0b00000000
  152.  
  153. 0b00000000, // SEQUENCIA PARA O PONTO
  154. 0b00000000,
  155. 0b00000000,
  156. 0b00000000,
  157. 0b00000000,
  158. 0b00000000,
  159. 0b00111100,
  160. 0b00111100
  161. };
  162. //----------------------------------------------------------------
  163. void lcd_load_custom_chars(void) // copiadooo
  164. {
  165. int8 i;
  166. lcd_send_byte(0, 0x40);
  167. for(i= 0; i < sizeof(lcd_custom_chars); i++)
  168. {
  169. lcd_send_byte(1, lcd_custom_chars[i]);
  170. }
  171. lcd_send_byte(0, 0x80);
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement