0% found this document useful (0 votes)
6 views4 pages

Clip11 DS1307

The document contains a C program for a microcontroller that manages a graphical LCD display and processes input from various sensors. It includes functions for reading time from a DS1307 RTC, displaying temperature from a DS18B20 sensor, and calculating distance using an analog sensor. The main loop handles button presses, updates the display, and manages timers for accurate readings and updates.

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)
6 views4 pages

Clip11 DS1307

The document contains a C program for a microcontroller that manages a graphical LCD display and processes input from various sensors. It includes functions for reading time from a DS1307 RTC, displaying temperature from a DS18B20 sensor, and calculating distance using an analog sensor. The main loop handles button presses, updates the display, and manages timers for accurate readings and updates.

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/ 4

signed int16 lm35b, distance, ng, tp;

unsigned int1 mode=0;

unsigned int8 i;

void giaodien_glcd()

if(ds1307_read_time()==ok)

second=(ds1307.second/16)*10+ds1307.second%16;

minute=(ds1307.minute/16)*10+ds1307.minute%16;

hour=(ds1307.hour/16)*10+ds1307.hour%16;

if(mode==0)

glcd_text_setup(15,25,2,1,1);

printf(glcd_text,"%d%d:%d%d:%d%d",

ds1307.hour/16,ds1307.hour%16,

ds1307.minute/16,ds1307.minute%16,

ds1307.second/16,ds1307.second%16);

s7seg_display();

glcd_update();

else

glcd_circle(70,30,30,0,1);

glcd_circle(70,30,26,1,0);

glcd_bar(70, 30,70+25*cos((second-15)*pi/30), 30+25*sin((second-15)*pi/30), 1, 1);

glcd_bar(70, 30,70+22*cos((minute-15)*pi/30), 30+22*sin((minute-15)*pi/30), 2, 1);

glcd_bar(70, 30,70+20*cos((hour-3)*pi/6), 30+20*sin((hour-3)*pi/6), 3, 1);

glcd_update();

s7seg_display();
}

else;

void xuly_nutnhan()

if(inputcd(inv)==0) {mode=~mode; glcd_clear(0);}

s7seg_display();

void main()

system_init();

lcd_setup();

glcd_setup();

setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);

set_timer1(3036);

enable_interrupts(int_timer1);

enable_interrupts(global);

setup_timer_0(T0_EXT_H_TO_L|T0_DIV_1);

set_timer0(0);

setup_adc(adc_clock_div_32);

setup_adc_ports(analog_pins|vss_vdd);

ds18b20_set_resolution(11);

s7seg.led[5]=0xbf;

s7seg.led[2]=0xbf;

while(true)

xuly_nutnhan();

if(bdn>=10)
{

bdn=bdn-10; giay++;

if(giay>=60)

giay=0; phut++;

if(phut>=60)

phut=0; gio++;

gio%=24;

if(ds18b20_read_temperature()==ok)

ng=ds18b20.temperatureA>>4;

tp=(ds18b20.temperatureA&0x0f)*1000/16;

lcd_goto(8,3);

printf(lcd_data,"%ld",ng);

lcd_goto(10,3);

printf(lcd_data,".%03ld",tp);

giaodien_glcd();

s7seg.led[7]=m7d[gio/10%10];

s7seg.led[6]=m7d[gio%10];

s7seg.led[4]=m7d[phut/10%10];

s7seg.led[3]=m7d[phut%10];

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

s7seg.led[0]=m7d[giay%10];

for(i=0;i<100;i++) xuly_nutnhan();
T0=get_timer0();

if(T0>gh) set_timer0(1);

lcd_goto(9,0);

printf(lcd_data,"%02d",T0);

set_adc_channel(lm35b_channel);

lm35b=read_adc()/2.046;

lcd_goto(9,1);

printf(lcd_data,"%02ld",lm35b);

set_adc_channel (gp2d12_channel);

distance=read_adc();

distance=pow(4277/distance,1.115);

if(distance<10) distance=10;

else if(distance>80) distance=80;

lcd_goto(9,2);

printf(lcd_data,"%02ld",distance);

#int_timer1

void ngat_timer1()

set_timer1(3036);

bdn++;

You might also like