[B]unsigned int[/B] adc_value = 0;
[B]unsigned int[/B] mseg_1 = 0;
[B]unsigned short[/B] temp,second;
[B]char[/B] error = 3;
[B]char[/B] text [20];
[B]float[/B] resolution = 0.0;
[B]float[/B] temp_value = 0.0;
[B]bit[/B] letra;
[B]void[/B] interrupt([B]void[/B]) {
if(T0IF_bit == 1) {
TMR0 = 0x06;
mseg_1++;
if(mseg_1 >= 1000){
second++;
mseg_1 = 0;
} T0IF_bit = 0;
}
}
[B]void[/B] temperature([B]void[/B]) {
ADON_bit = 1;
delay_us(40);
GO_bit = 1;
while(GO_bit == 1) {
} adc_value = (ADRESH << 8)
+ ADRESL + error;
resolution = 2.5/10.23;
temp_value = resolution * adc_value;
temp = temp_value;
}
[B]void[/B] main([B]void[/B]) {
PORTA = 0;
PORTB = 0;
PORTC = 0;
TRISA = 0x0B;
TRISB = 0;
ANSEL = 0x0B;
ADCON0 = 0x80;
ADCON1 = 0x90;
ANSELH = 0;
SPBRG = 12;
SPEN_bit = 1;
TXEN_bit = 1;
OPTION_REG = 0xD2;
INTCON = 0xA0;
[B]while[/B](1) {
temperature();
ByteToStr(temp, text);
[B]if[/B](TRMT == 1 && second >= 1) {
UART1_Write_Text(text);
[B]if[/B](!letra) { UART1_Write(0x41);
CHS0_bit = 1;
} [B]else[/B] { UART1_Write(0x42);
CHS0_bit = 0;
} TXREG = 0x0D;
letra++;
second = 0x00;
} [B]while[/B](!TRMT);
delay_us(10);
}
}