Académique Documents
Professionnel Documents
Culture Documents
Conocer las caractersticas y el funcionamiento del ADC del PIC18F4550 utilizando el puerto Serial.
2. Objetivos de la Prueba.
Realizar un programa para realizar la conversin ADC del canal 0 y enviarla por el puerto serial. Realizar un programa para realizar la conversin ADC del canal 0 mostrarla en el LCD. Disear Hardware y software que tenga las siguientes caractersticas:
Teclado matricial 4*4 LCD de 2 filas y 16 columnas En el LCD debe mostrarse un solo canal ADC, el canal ADC a desplegarse en el LCD debe ser seleccionado por el teclado.
3. Diagramas de Flujo.
3.1. ADC Propuesto I.
INICIO
while (1)
FIN
3.2.
while (1)
FIN
3.3.
char txt[7]; int lectura; void main() { TRISA = 0x01; //configuracion adcon1 //VCFG1=0 //El voltaje de referencia bajo del ADC es tierra //VCFG0=0 //El voltaje de referencia alto del ADC es vcc ADC_Init(); ADCON1=0b00001110; UART1_Init(2400); }
UART1_Write_Text("Ejercicio 1"); UART1_Write(10);UART1_Write(13); while(1){ lectura = ADC_Read(0); //10 bits desde 0 hasta 1023 IntToStr(lectura, txt); UART1_Write_Text(txt); UART1_Write(10);UART1_Write(13); delay_ms(1000); //se realiza la lectura cada 1seg }
4.2.
ADC Propuesto 2.
// LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit;
TRISA = 0x01; ADC_Init(); //PCFG3=1; PCFG2=1; PCFG1=1; PCFG0=0; ADCON1=0b00001110; //ver en el datasheet PIC18F4550 hoja:268 Lcd_Init(); Lcd_Out(1,1,"Ejercicio 2"); delay_ms(1000);
sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections
Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); while(1){ lectura = ADC_Read(0); //10 bits desde 0 hasta 1023 IntToStr(lectura, txt); Lcd_Out(1,1,txt); delay_ms(500);
} }
4.3.
ADC Propuesto 3.
TRISA = 0xff; TRISC = 0xff; TRISD=0xff; ADC_Init(); //PCFG3=0; PCFG2=0; PCFG1=0; PCFG0=1; ADCON1=0b000000001; Lcd_Init(); Lcd_Out(1,1,"Ejercicio 3");
char keypadPort at PORTD; // LCD module connections sbit LCD_RS at RC0_bit; sbit LCD_EN at RC1_bit; sbit LCD_D4 at RC2_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISC0_bit; sbit LCD_EN_Direction at TRISC1_bit; sbit LCD_D4_Direction at TRISC2_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections
char txt[7]; char txt2[4]; int lectura; char kp; char tecla=0; char convierte(char kp); /*se declara la subrutina convierte, sirve para convertir la posicion por el keypad a valor de teclado*/ void main() {
} lectura = ADC_Read(tecla);
IntToStr(lectura, txt); Lcd_Out(2,1,txt); delay_ms(100); } } //la tecla + correspoonde al numero 10 //la tecla - correspoonde al numero 11 //la tecla * correspoonde al numero 12 //la tecla / correspoonde al numero 13 //la tecla = correspoonde al numero 14 //la tecla AC correspoonde al numero 15 char convierte(char kp) { char tecla=0; switch(kp){ case 1: tecla=7; break; } }
case 5: tecla=4; break; case 6: tecla=5; break; case 7: tecla=6; break; case 8: tecla=12; break; case 9: tecla=1; break; case 10: tecla=2; break; case 11: tecla=3; break; case 12: tecla=11; break; case 13: tecla=15; break; case 14: tecla=0; break; case 15: tecla=14; break; case 16: tecla=10; break;
return tecla;
5. Simulaciones.
5.1. ADC Propuesto I.
5.2.
5.3.
Escribiendo en el PIC18F4550
Verificando
8. Anexos.