0% found this document useful (0 votes)
10 views5 pages

DS18B20

The document contains a C program for a microcontroller that interfaces with various display and sensor modules. It includes functions for displaying information on a GLCD, handling button inputs, and reading temperature and distance measurements. The program continuously updates the display based on user inputs and sensor readings.

Uploaded by

duytan170104
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

DS18B20

The document contains a C program for a microcontroller that interfaces with various display and sensor modules. It includes functions for displaying information on a GLCD, handling button inputs, and reading temperature and distance measurements. The program continuously updates the display based on user inputs and sensor readings.

Uploaded by

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

#include<tv_boards.

c>

#include<tv_glcd.c>

#include<tv_ds18b20.c>

#include<tv_lcd.c>

unsigned int16 distance;

unsigned int1 tt=0;

signed int8 pg=0,tp=0;

unsigned int16 ng,stp;

void tat()

lcd_goto(7,2);

lcd_data(" ");

lcd_goto(7,3);

lcd_data(" ");

void hienthi_GLCD()

glcd_clear(0);

glcd_rect(0,pg*15,70,pg*15+15,1,1);

glcd_text_setup(5,5,1,pg!=0,0);

glcd_text("DPG 9 BIT");

glcd_text_setup(5,20,1,pg!=1,0);

glcd_text("DPG 10 BIT");

glcd_text_setup(5,35,1,pg!=2,0);

glcd_text("DPG 11 BIT");

glcd_text_setup(5,50,1,pg!=3,0);

glcd_text("DPG 12 BIT");
glcd_rect(80,tp*15,160,tp*15+15,1,1);

glcd_text_setup(85,5,1,tp!=0,0);

glcd_text("1 SO TP");

glcd_text_setup(85,20,1,tp!=1,0);

glcd_text("2 SO TP");

glcd_text_setup(85,35,1,tp!=2,0);

glcd_text("3 SO TP");

glcd_update();

void xulynutnhan()

if(inputcd(mod)==0)

tt=~tt;

if(tt==0)

if(inputcd(up)==0)

pg++;

if(pg>=3) pg=3;

hienthi_GLCD();

ds18b20_set_resolution(9+pg);

if(inputcd(dw)==0)

pg--;
if(pg<=0) pg=0;

hienthi_GLCD();

ds18b20_set_resolution(9+pg);

if(tt==1)

if(inputcd(up)==0)

tp++;

if(tp>=2) tp=2;

hienthi_GLCD();

tat();

if(inputcd(dw)==0)

tp--;

if(tp<=0) tp=0;

hienthi_GLCD();

tat();

void main()

system_init();

glcd_setup();

setup_adc(adc_clock_div_32);
setup_adc_ports(analog_pins|vss_vdd);

glcd_setup();

lcd_setup();

hienthi_GLCD();

ds18b20_set_resolution(9+pg);

while(true)

xulynutnhan();

//Do khoang cach

set_adc_channel(gp2d12_channel); delay_us(20);

distance=read_adc();

distance=pow(4277/distance, 1.115);

if(distance>80) distance=80;

else if(distance<10) distance=10;

s7seg.led[1]=m7d[distance/10%10];

s7seg.led[0]=m7d[distance/1%10];

s7seg_display();

if(ds18b20_read_temperature()==OK) // 2. Do nhiet do thanh cong

ng = ds18b20.temperatureA>>4; // 2. Tinh toan phan nguyen

stp = (ds18b20.temperatureA&0x0f)*1000/16; // 2. Tinh toan phan thap phan, neu lay 2 so tp


thi x100, 3 so thi x1000

lcd_write_2x3_num(ng/10%10,0,2); // 2. Hien thi LCD

lcd_write_2x3_num(ng/1%10,3,2);

lcd_goto(6,3);

lcd_data(".");

if(tp==0)
{

lcd_write_2x3_num(stp/100%10,7,2);

if(tp==1)

lcd_write_2x3_num(stp/100%10,7,2);

lcd_write_2x3_num(stp/10%10,10,2);

if(tp==2)

lcd_write_2x3_num(stp/100%10,7,2);

lcd_write_2x3_num(stp/10%10,10,2);

lcd_write_2x3_num(stp/1%10,13,2);

s7seg_display();

You might also like