البرنامج :
كود:
/*LESSON 19 TUTORIAL9
LM35>>ADC>>LCD>>UART""PC Hyper Terminal
PIC16F877A
crystal: 4MHz
ENG.F.ABDELAZIZ
http://www.eeecb.com/vb/index.php
*/
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_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
unsigned char text0[4] ;
unsigned char text1[4] ;
int temp0 = 0;
int temp1 = 0;
// Main program
void main ()
{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"ROOM1 TEMP.= C"); // writes text on line 1, column 1 of the lcd
Lcd_Out(2,1,"ROOM2 TEMP.= C"); // writes text on line 2, column 1 of the lcd
Uart1_Init (9600);
do {
temp0 = Adc_Read(0); // Read channel AN0 and save value in the variable temp0
temp0 =temp0/2.05;// Convert from value to TEMPERATURE
temp1 = Adc_Read(1); // Read channel AN1 and save value in the variable temp1
temp1 =temp1/2.05; // Convert from value to TEMPERATURE
ByteToStr(temp0, text0);// converts TEMP.to string
ByteToStr(temp1, text1); // converts TEMP.to string
Lcd_Out(1,12,text0); // Write the value to LCD
delay_ms (10);
Lcd_Out(2,12,text1); // Write the value to LCD
delay_ms (10);
UART1_Write_Text("ROOM1 TEMP.=");
UART1_Write_Text(text0); // Sent to uart
UART1_Write_Text("C");
Uart1_Write('\t'); // Tabe (Horizontal)
UART1_Write_Text("ROOM2 TEMP.=");
UART1_Write_Text(text1);
UART1_Write_Text("C");
Uart1_Write('\r'); // OR 13 : Carriage Return
}
while (1);
}