100% found this document useful (1 vote)
84 views

Timer 0

This code configures a microcontroller to read temperature data from an ADC, display it on an LCD screen, and toggle an LED using a timer interrupt. It initializes the ADC, LCD, and timer peripherals. It then enters a loop to continuously read the ADC channel, display the temperature value, and toggle the LED via the timer interrupt.

Uploaded by

andres felipe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
84 views

Timer 0

This code configures a microcontroller to read temperature data from an ADC, display it on an LCD screen, and toggle an LED using a timer interrupt. It initializes the ADC, LCD, and timer peripherals. It then enters a loop to continuously read the ADC channel, display the temperature value, and toggle the LED via the timer interrupt.

Uploaded by

andres felipe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <16f877a.

h>
#device adc=10 // Usa resoluci�n de 10 bits
#fuses HS, NOWDT,NOPROTECT,NOPUT
#use delay(clock=20M)
#include <lcd.c> //incluye librer�a del LCD
#use rs232 (baud=9600, parity=N, xmit=pin_c6, rcv=pin_c7, bits=8)//230400 baud
#define use_portd_lcd TRUE //Configuraci�n puerto D control lcd
#USE STANDARD_IO(A)
#USE STANDARD_IO(B)
#USE STANDARD_IO(C)
#USE STANDARD_IO(D)

float32 A=0.0;
float32 V=0.0;
float32 Kg=0.0;
INT16 DATO=0;
FLOAT DATO1;
VOID TEMPERATURA()
{
SET_ADC_CHANNEL(0);
DELAY_MS(500);
DATO=READ_ADC();
DATO1=DATO*1;
DELAY_MS(500);
PRINTF("%4.1f\r\n",DATO1);
}
#INT_TIMER0
void Timer0_isr(void)
{
output_toggle(PIN_B0);
set_timer0(250);
clear_interrupt(INT_TIMER0);

}
void main()
{
//set_tris_b(0XF0);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_2);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
clear_interrupt(INT_TIMER0);
set_timer0(250);
setup_timer_0(T0_INTERNAL|T0_DIV_256);

lcd_init(); //Se inicia el LCD

lcd_putc("\f Bascula \n"); // Saca texto


lcd_putc(" Electronica "); // Saca texto
delay_ms(2000);

lcd_putc("\f"); // Limpia pantalla

lcd_putc("DATO\n"); // Saca texto


delay_ms(1000);

//lcd_gotoxy(13,2); // Acomoda cursor LCD


//lcd_putc("Kg");
//delay_ms(50);
// setup_ccp1(CCP_PWM);
//setup_timer_2(T2_DIV_BY_1, 255, 1);

//setup_adc (adc_clock_internal);

//setup_adc_ports (0);

//set_adc_channel (0); // Elige canal a medir RA0

while(true)
{
TEMPERATURA();

//lcd_gotoxy(4,2); // Acomoda cursor LCD


//delay_ms(10); // Limpia ese sector de pantalla
//lcd_gotoxy(4,2); // Acomoda cursor LCD
//set_pwm1_duty(0);
//A=read_adc();

//Kg=(A/10)-15.2;
// set_pwm1_duty(100);

//lcd_gotoxy(1,2); // Acomoda cursor LCD

// printf(lcd_putc,"%02.3f",kg);
// printf("%4.1f\r\n",kg);

}
}

You might also like