Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sbit LCD_RS at RB2_bit;
- sbit LCD_EN at RB3_bit;
- sbit LCD_D4 at RB7_bit;
- sbit LCD_D5 at RB6_bit;
- sbit LCD_D6 at RB5_bit;
- sbit LCD_D7 at RB4_bit;
- sbit LCD_RS_Direction at TRISB2_bit;
- sbit LCD_EN_Direction at TRISB3_bit;
- sbit LCD_D4_Direction at TRISB7_bit;
- sbit LCD_D5_Direction at TRISB6_bit;
- sbit LCD_D6_Direction at TRISB5_bit;
- sbit LCD_D7_Direction at TRISB4_bit;
- #define cs porta.f3 //Port_A,ADCCS
- #define clock porta.f1 //Port_A,ADCCLK
- #define dato porta.f2
- #define L portb.f1
- #define L_ trisb.f1
- #define buff portb.f0
- #define v 0 //sensibilidad
- #define t 20 //tiempo de alarma
- unsigned short ad,i;
- char txt[5];
- void Pb(){
- buff=1; // buffer cerrado
- delay_ms(300); // tiempo de espera para que se recargue el condensador milisegundos
- L=0; // exita bobinado
- L_=0;
- delay_us(1000); // tiempo de exitacion de la bobina
- L=1;
- L_=1; // apaga bobina
- delay_us(100); // tiempo de espera en microsegundos antes de tomar la muestra
- // extablese el alcanse y sensibilidad
- buff=0; // Abre buffer
- delay_us(30); // tiempo durante el cual se toma una muestra en microsegundos
- buff=1; // cierra el buffer
- }
- void demora(){
- delay_ms(32);
- }
- void pulse(){
- clock=1;
- demora();
- clock=0;
- demora();
- }
- unsigned short read_adc(){
- unsigned short a;
- a=0;
- clock=0; cs=1; demora(); cs=0; pulse();
- pulse(); a.f7=dato; pulse(); a.f6=dato;
- pulse(); a.f5=dato; pulse(); a.f4=dato;
- pulse(); a.f3=dato; pulse(); a.f2=dato;
- pulse(); a.f1=dato; pulse(); a.f0=dato;
- pulse(); pulse(); pulse(); pulse();
- return a;
- }
- void main() {
- unsigned short j;
- CMCON=7;
- L=1;
- TRISB = 0;
- TRISA = 0xFF;
- Lcd_Init();
- Lcd_Cmd(_LCD_CLEAR);
- Lcd_Cmd(_LCD_CURSOR_OFF);
- lcd_out(1,1,"Test Ok");
- delay_ms(1000);
- buff=1; // deshabilitado buffer
- clock=0;
- cs=1;
- TRISA.f1=0;
- TRISA.f3=0;
- buff=1; // deshabilitado buffer
- lcd_cmd(_lcd_clear);
- while(1){
- Pb();
- }
- //if (ad>v){lcd_out(1,1,"metal");}else{lcd_out(1,1,"no ");}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement