Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. char keypadPort at PORTD;
  2. sbit LCD_RS at RA4_bit;
  3. sbit LCD_EN at RA5_bit;
  4. sbit LCD_D4 at RA0_bit;
  5. sbit LCD_D5 at RA1_bit;
  6. sbit LCD_D6 at RA2_bit;
  7. sbit LCD_D7 at RA3_bit;
  8. sbit LCD_RS_Direction at TRISA4_bit;
  9. sbit LCD_EN_Direction at TRISA5_bit;
  10. sbit LCD_D4_Direction at TRISA0_bit;
  11. sbit LCD_D5_Direction at TRISA1_bit;
  12. sbit LCD_D6_Direction at TRISA2_bit;
  13. sbit LCD_D7_Direction at TRISA3_bit;
  14.  
  15. int flag;
  16. int k;
  17. int kp;
  18. int countPom = 0;
  19. int nizaPom[3];
  20. char uart_rd;
  21. char pp[4];
  22. char print[15];
  23. char print2[15];
  24. int niza[6];
  25. int niza2[40];
  26. int pom = 14;
  27. int trocifren;
  28. int value, count = 0;
  29. int isStarted = 0;
  30. int brojach = 0;
  31. int brojach2 = 0;
  32. int broj;
  33. int Dvocifren(int a){
  34. if(a >= 10 && a <= 99)
  35. return 1;
  36. else
  37. return 0;
  38. }
  39.  
  40. int makeTrocifren(int niza3[3]){
  41. trocifren = niza3[0] * 100 + niza3[1] * 10 + niza3[2];
  42. return trocifren;
  43.  
  44. }
  45.  
  46. void main() {
  47. Keypad_Init(); // initialize the keypad
  48. ANSEL = 0;
  49. ANSELH = 0; // AN pins are configured as digital
  50. ANSELH.B4 = 1;
  51. TRISB.B0 = 1;
  52. Lcd_Init(); // initialize the LCD
  53. Lcd_Cmd(_LCD_CLEAR); // clear the screen
  54. Lcd_Cmd(_LCD_CURSOR_OFF);
  55. C1ON_bit = 0; // comparators are disabled
  56. C2ON_bit = 0;
  57. UART1_Init(9600); // Initialization of UART on 9600 bps
  58. Delay_ms(100);
  59.  
  60. do
  61. {
  62. kp = 0;
  63. do
  64. kp = Keypad_Key_Click();
  65. while (!kp);
  66. switch (kp)
  67. {
  68. case 1: kp = -1; break;
  69. case 2: kp = 1; break;
  70. case 3: kp = -1; break;
  71. case 4: kp = -1; break;
  72. case 5: kp = 2; break;
  73. case 6: kp = 3; break;
  74. case 7: kp = -1; break;
  75. case 8: kp = -1; break;
  76. case 9: kp = 4; break;
  77. case 10: kp = 5; break;
  78. case 11: kp = -1; break;
  79. case 12: kp = -1; break;
  80. case 13: kp = -1; break;
  81. case 14: kp = 6; break;
  82. case 15: kp = -1; break;
  83. case 16: kp = -1; break;
  84. }
  85. if(kp == 2){
  86. isStarted = 1;
  87. Lcd_Cmd(_LCD_CLEAR);
  88.  
  89. LCD_Out(1,1, "Reading");
  90.  
  91. while(count < 6){
  92. value = ADC_Read(12);
  93. if(Dvocifren(value) == 1)
  94. {
  95. niza[count] = value;
  96. count++;
  97. }
  98. Delay_ms(25);
  99. }
  100. count = 0;
  101. Lcd_Cmd(_LCD_CLEAR);
  102. while(count < 6){
  103. print[count * 2] = niza[count] / 10 + 48;
  104. print[count * 2 + 1] = niza[count] % 10 + 48;
  105. count++;
  106. }
  107. LCD_Out(1,1,print);
  108. Lcd_Cmd(_LCD_CLEAR);
  109.  
  110. while(1){
  111. flag = 0;
  112. brojach = 0;
  113. brojach2 = 0;
  114. while(1){
  115. if (UART1_Data_Ready()) {
  116. uart_rd = UART1_Read();
  117. LCD_Chr(1,1,uart_rd);
  118. Delay_ms(15);
  119. Lcd_Cmd(_LCD_CLEAR);
  120. if(isdigit(uart_rd)){
  121. nizaPom[brojach] = uart_rd - 48;
  122. brojach++;
  123. LCD_Out(2,1, "IS DIGIT");
  124. }
  125. else if (uart_rd == '-'){
  126. if(brojach != 3){
  127. flag = 1;
  128.  
  129. LCD_Out(1,1,"FIRST ONE");
  130. Lcd_Cmd(_LCD_CLEAR);
  131. break;
  132. }
  133. else{
  134. brojach = 0;
  135. broj = MakeTrocifren(nizaPom);
  136. niza2[brojach2] = broj;
  137. brojach2++;
  138. IntToStr(brojach2, pp);
  139. LCD_Out(2,1, pp);
  140. }
  141. }
  142. else if( uart_rd == '$'){
  143. if(brojach2 != 3){
  144. LCD_Out(1,1,"SECOND ONE");
  145. Lcd_Cmd(_LCD_CLEAR);
  146. flag = 1;
  147.  
  148. }
  149. break;
  150. }
  151. else{
  152. flag = 1;
  153. LCD_Out(1,1,"THIRD ONE");
  154. Lcd_Cmd(_LCD_CLEAR);
  155. break;
  156. }
  157. }
  158. }
  159. if(flag == 1){
  160. Lcd_Cmd(_LCD_CLEAR);
  161. LCD_Out(1,1, "Error");
  162. }
  163. else if (flag == 0){
  164. brojach2 = 0;
  165. //Lcd_Cmd(_LCD_CLEAR);
  166. LCD_Out(1,1, "IT'S OKAY");
  167. while(brojach2 < 4){
  168. k = niza2[brojach2] / 100 - 48;
  169. print2[brojach2 * 3] = k;
  170. print2[brojach2 * 3 + 1] = ((niza2[brojach2] / 10) % 10) - 48;
  171. print2[brojach2 * 3 + 2] = niza2[brojach2] % 100 - 48;
  172. }
  173. LCD_Out(1,1,print2);
  174. Delay_ms(20);
  175. break;
  176. }
  177. }
  178. if(isStarted){
  179.  
  180. }
  181. }
  182.  
  183. }
  184. while(1);
  185.  
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement