0% found this document useful (0 votes)
7 views6 pages

Code

The document describes code for an embedded system that uses buttons and an LCD to select different subjects and display their temperature readings. It initializes the LCD, reads button and ADC inputs, and conditions LCD output on the button states and temperature thresholds.

Uploaded by

nam nguyên
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
7 views6 pages

Code

The document describes code for an embedded system that uses buttons and an LCD to select different subjects and display their temperature readings. It initializes the LCD, reads button and ADC inputs, and conditions LCD output on the button states and temperature thresholds.

Uploaded by

nam nguyên
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

#include<16f877a.

h>

#device ADC=10

#use delay(crystal=20M)

#define LCD_ENABLE_PIN PIN_C2

#define LCD_RS_PIN PIN_C0

#define LCD_RW_PIN PIN_C1

#define LCD_DATA4 PIN_C3

#define LCD_DATA5 PIN_C4

#define LCD_DATA6 PIN_C5

#define LCD_DATA7 PIN_C6

#include<lcd.c>

void main()

lcd_init();

while(true)

setup_adc(ADC_CLOCK_INTERNAL);

setup_adc_ports(AN0);

set_adc_channel(0);

lcd_putc(' ');

int a1,a2,a3,a4;

a1=input_state(pin_b0);

a2=input_state(pin_b1);

a3=input_state(pin_b2);

a4=input_state(pin_b3);

if(a1==0 && a2==0 && a3==0 && a4==0)

lcd_putc(' ');
lcd_gotoxy(1, 1);

lcd_putc(" ");

lcd_gotoxy(1, 2);

lcd_putc("chon doi tuong");

delay_ms(500);

else

if(a2==0 && a1==1 && a3==0 && a4==0)

lcd_putc(' ');

lcd_gotoxy(1, 1);

lcd_putc("DT: 1-4 tuoi ");

delay_ms(500);

if(a2==1 && a1==0 && a3==0 && a4==0)

lcd_putc(' ');

lcd_gotoxy(1, 1);

lcd_putc("DT: 5-9 tuoi ");

delay_ms(500);

if(a2==0 && a1==0 && a3==1 && a4==0)

lcd_putc(' ');

lcd_gotoxy(1, 1);

lcd_putc("DT: tren 10 tuoi");

delay_ms(500);
}

if(a2==0 && a1==0 && a3==0 && a4==1)

lcd_putc('f');

lcd_gotoxy(1, 1);

lcd_putc("DT:van dong vien");

delay_ms(500);

if(a1==1 && a2==1 ||a1==1 && a3==1||a1==1 && a4==1||a2==1 && a3==1||a2==1 &&
a4==1||a3==1 && a4==1)

lcd_putc(' ');

Lcd_gotoxy(1, 1);

lcd_putc("loi che do ");

lcd_gotoxy(1, 2);

lcd_putc("hai ba nut an");

delay_ms(500);

else

int16 i;

float value;

value=read_adc();

i=value*130/1024;

lcd_putc(' ');

lcd_gotoxy(1, 2);

lcd_putc("NT:");

lcd_gotoxy(4, 2);
printf(lcd_putc," %4lu",i);

if(a1==1)

if(i<130 && i>80)

lcd_gotoxy(9, 2);

lcd_putc("an toan ");

else

lcd_gotoxy(9, 2);

lcd_putc("canh bao");

output_high(pin_d0);

delay_ms(300);

output_low(pin_d0);

delay_ms(300);

if(a2==1)

if(i<115 && i>70)

lcd_gotoxy(9, 2);

lcd_putc("an toan ");

else

lcd_gotoxy(9, 2);
lcd_putc("canh bao");

output_high(pin_d0);

delay_ms(300);

output_low(pin_d0);

delay_ms(300);

if(a3==1)

if(i<100 && i>60)

lcd_gotoxy(9, 2);

lcd_putc("an toan ");

else

lcd_gotoxy(9, 2);

lcd_putc("canh bao");

output_high(pin_d0);

delay_ms(300);

output_low(pin_d0);

delay_ms(300);

if(a4==1)

if(i<60 && i>40)

{
lcd_gotoxy(9, 2);

lcd_putc("an toan ");

else

lcd_gotoxy(9, 2);

lcd_putc("canh bao");

output_high(pin_d0);

delay_ms(300);

output_low(pin_d0);

delay_ms(300);

You might also like