Code: Select all
sbit LCD_D7 at RB2_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_RS at RB7_bit;
sbit LCD_D7_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_RS_Direction at TRISB7_bit;
//************************temperature variables****************
int temp,temp1,mv;
char temper[7];
//**************************************************************
void READ_temp(void)
{
temp=ADC_Read(0);
mV= (temp* 5000.0)/1024.0;
temp1=mV/10.0;
//temp=temp1*5/1023;
//temp2=temp*100;
}
void data_conversion(void)
{
inttostr(temp1,temper);
}
void display1(void)
{
lcd_out(1,1,"TEMPERATURE=");
lcd_out(1,13, Ltrim(temper));
Lcd_Chr_Cp(0xdf);
Lcd_Chr_Cp('C');
Lcd_Chr_Cp(' ');
}
}
void main()
{
PORTD = 0;
PORTC = 0;
TRISC = 0x00;
TRISD = 0x00;
ADC_Init();
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
lcd_cmd(_LCD_CURSOR_OFF);
lcd_out(1,4,"DIGITAL TEMPERATURE");
lcd_out(2,6,"SENSOR");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
PORTD=0 ;
PORTC=0;
READ_temp();
data_conversion();
display1();
PWM2_Init(1000); // Initialize PWM2
PWM2_Start(); // start PWM2
PWM1_Init(1000); // Initialize PWM2
PWM1_Start(); // start PWM2
while(1)
{
PORTD.B0 = temp1 >= 80 ? 1 : 0;
if (Button(&PORTD, 0, 1000, 1)){
PWM2_Set_Duty(200); // increment current_duty_1
}
{
{
if (Button(&PORTD, 0, 1000, 1)){
Lcd_Out(2, 1, "HOT");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
{
PORTD.B3 = temp1 <= 65 ? 1 : 0;
if (Button(&PORTD, 3, 1000, 1)){
PWM1_Set_Duty(200); // increment current_duty_1
}
{
if (Button(&PORTD, 3, 1000, 1)){
Lcd_Out(2, 1, "COLD");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
READ_temp();
data_conversion();
display1();
}
}}}} }