Advertisement
electronicosembebido

Untitled

Feb 13th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. sbit LCD_RS at RB2_bit;
  2. sbit LCD_EN at RB3_bit;
  3. sbit LCD_D4 at RB7_bit;
  4. sbit LCD_D5 at RB6_bit;
  5. sbit LCD_D6 at RB5_bit;
  6. sbit LCD_D7 at RB4_bit;
  7.  
  8. sbit LCD_RS_Direction at TRISB2_bit;
  9. sbit LCD_EN_Direction at TRISB3_bit;
  10. sbit LCD_D4_Direction at TRISB7_bit;
  11. sbit LCD_D5_Direction at TRISB6_bit;
  12. sbit LCD_D6_Direction at TRISB5_bit;
  13. sbit LCD_D7_Direction at TRISB4_bit;
  14.  
  15.  
  16.  
  17. #define cs porta.f3 //Port_A,ADCCS
  18. #define clock porta.f1 //Port_A,ADCCLK
  19. #define dato porta.f2
  20. #define L portb.f1
  21. #define L_ trisb.f1
  22. #define buff portb.f0
  23. #define v 0 //sensibilidad
  24. #define t 20 //tiempo de alarma
  25.  
  26.  
  27. unsigned short ad,i;
  28. char txt[5];
  29.  
  30. void Pb(){
  31. buff=1; // buffer cerrado
  32. delay_ms(300); // tiempo de espera para que se recargue el condensador milisegundos
  33. L=0; // exita bobinado
  34. L_=0;
  35. delay_us(1000); // tiempo de exitacion de la bobina
  36. L=1;
  37. L_=1; // apaga bobina
  38. delay_us(100); // tiempo de espera en microsegundos antes de tomar la muestra
  39. // extablese el alcanse y sensibilidad
  40. buff=0; // Abre buffer
  41. delay_us(30); // tiempo durante el cual se toma una muestra en microsegundos
  42. buff=1; // cierra el buffer
  43. }
  44.  
  45. void demora(){
  46. delay_ms(32);
  47. }
  48.  
  49. void pulse(){
  50. clock=1;
  51. demora();
  52. clock=0;
  53. demora();
  54. }
  55.  
  56. unsigned short read_adc(){
  57. unsigned short a;
  58. a=0;
  59. clock=0; cs=1; demora(); cs=0; pulse();
  60. pulse(); a.f7=dato; pulse(); a.f6=dato;
  61. pulse(); a.f5=dato; pulse(); a.f4=dato;
  62. pulse(); a.f3=dato; pulse(); a.f2=dato;
  63. pulse(); a.f1=dato; pulse(); a.f0=dato;
  64. pulse(); pulse(); pulse(); pulse();
  65. return a;
  66. }
  67.  
  68.  
  69. void main() {
  70. unsigned short j;
  71. CMCON=7;
  72. L=1;
  73. TRISB = 0;
  74. TRISA = 0xFF;
  75. Lcd_Init();
  76. Lcd_Cmd(_LCD_CLEAR);
  77. Lcd_Cmd(_LCD_CURSOR_OFF);
  78. lcd_out(1,1,"Test Ok");
  79. delay_ms(1000);
  80.  
  81. buff=1; // deshabilitado buffer
  82. clock=0;
  83. cs=1;
  84. TRISA.f1=0;
  85. TRISA.f3=0;
  86. buff=1; // deshabilitado buffer
  87. lcd_cmd(_lcd_clear);
  88. while(1){
  89. Pb();
  90.  
  91. }
  92. //if (ad>v){lcd_out(1,1,"metal");}else{lcd_out(1,1,"no ");}
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement