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

VD 2

This C program code defines constants and variables for controlling an LCD display and 7-segment LED display. It includes functions to check button presses, increment a counter when a limit is exceeded, display time and productivity statistics on the LCD, and light up the 7-segment LED display to show the current time. The main loop continuously calls functions to update the displays and check for user input.

Uploaded by

Hồ Bảo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

VD 2

This C program code defines constants and variables for controlling an LCD display and 7-segment LED display. It includes functions to check button presses, increment a counter when a limit is exceeded, display time and productivity statistics on the LCD, and light up the 7-segment LED display to show the current time. The main loop continuously calls functions to update the displays and check for user input.

Uploaded by

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

C:\Users\Ho Quoc Bao\Documents\Zalo Received Files\Ontap.

c
#include<16f887.h>
#fuses intrc_io
#use delay(clock=8M)
#define lcd_e pin_e1
#define lcd_rw 0
#define lcd_rs pin_e0
#define output_lcd output_d
#define led8 pin_c7
#define led7 pin_a7
#define led6 pin_a6
#define led5 pin_a5
#define led4 pin_a3
#define led3 pin_a2
#define led2 pin_a1
#define led1 pin_a0
#include<TV_LCD.c>
#include<TV_KEY4x4.c>
#bit TM1IF =0x0c.0
signed int8 T0,save, GHD=20, dem=0, mp, chuc, dv,
d=0, a=0, NS, NANG_SUAT, Nang_Suat1, TRAN=0;
unsigned int16 bdn1=0;
unsigned int8 giay=0, phut, gio;
const unsigned int8 ma7doan[10]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,0x80,0x90};
void xuatma7doan()
{
output_c(ma7doan[giay/1%10]);
output_low(led8); delay_ms(1); output_high(led8);
output_c(ma7doan[giay/10%10]);
output_low(led7); delay_ms(1); output_high(led7);
output_c(0xff-64);
output_low(led6); delay_ms(1); output_high(led6);
output_c(ma7doan[phut/1%10]);
output_low(led5); delay_ms(1); output_high(led5);
output_c(ma7doan[phut/10%10]);
output_low(led4); delay_ms(1); output_high(led4);
output_c(0xff-64);
output_low(led3); delay_ms(1); output_high(led3);
output_c(ma7doan[gio/1%10]);
output_low(led2); delay_ms(1); output_high(led2);
output_c(ma7doan[gio/10%10]);
output_low(led1); delay_ms(1); output_high(led1);
}

//!void CHECK_F_BUTTON()
//!{
//!mp=key_4x4();
//!if (mp==15) dem++;
//!if (dem==4) dem=0;
//!}

void CHECKPHIM()
{

if (d==0) //nap hang chuc


{
mp=-1;
mp=key_4x4();
if (mp==0) { chuc=0; a=1;} //A= PHAT HIEN CO NHAN
if (mp==1) {chuc=1; a=1;}
if (mp==2) {chuc=2; a=1;}
if (mp==3) {chuc=3; a=1;}

1
C:\Users\Ho Quoc Bao\Documents\Zalo Received Files\Ontap.c
if (mp==4) {chuc=4; a=1;}
if (mp==5) {chuc=5; a=1;}
if (mp==6) {chuc=6; a=1;}
if (mp==7) {chuc=7; a=1;}
if (mp==8) {chuc=8; a=1;}
if (mp==9) {chuc=9; a=1;}
if (mp!=-1) d=1;
}

if (d==1) //nap hang don vi


{
mp=-1;
mp=key_4x4();
if (mp==0) {dv=0; a=1;}
if (mp==1) {dv=1; a=1;}
if (mp==2) {dv=2; a=1;}
if (mp==3) {dv=3; a=1;}
if (mp==4) {dv=4; a=1;}
if (mp==5) {dv=5; a=1;}
if (mp==6) {dv=6; a=1;}
if (mp==7) {dv=7; a=1;}
if (mp==8) {dv=8; a=1;}
if (mp==9) {dv=9; a=1;}
if (mp!=-1) d=0;
}

if (a==1) GHD=chuc*10+dv;
else GHD=20;

if (mp==15) dem++; //check phim F


if (dem==4) dem=0;

void DEMSP()
{
//!{ CHECK_F_BUTTON();

CHECKPHIM();

if (dem==0)
{
set_timer0(0);
lcd_command(0x80);
printf(lcd_data,"SAN PHAM:%d CAI",T0);
lcd_command(0xC0);
printf(lcd_data,"GIOI HAN:%d CAI", GHD);
}
if (dem==1)
{
T0=get_timer0();
if (T0>GHD) { set_timer0(1); tran++;}
lcd_command(0x80);
printf(lcd_data,"SAN PHAM:%d CAI",T0);
lcd_command(0xC0);
printf(lcd_data,"GIOI HAN:%d CAI", GHD);
}

if (dem==2)
{

2
C:\Users\Ho Quoc Bao\Documents\Zalo Received Files\Ontap.c
save=T0;
lcd_command(0xd4+12);
printf(lcd_data,"SAVED:%d ",save);
set_timer0(save);
}

if (dem==3)
{
T0=get_timer0();
if (T0>GHD) { set_timer0(1); tran++;}
lcd_command(0x80);
printf(lcd_data,"SAN PHAM:%d CAI",T0);
lcd_command(0xC0);
printf(lcd_data,"GIOI HAN:%d CAI", GHD);
lcd_command(0xd4+12);
printf(lcd_data," ");
}
//!
}

void thoigian()
{

if(TM1IF) // CHECK TIMER1 TRAN


{ set_timer1(3036);
bdn1++;
TM1IF=0;
if(bdn1==4) // OVER
{
bdn1=0; //dinh thoi da du
giay++;

NS=get_timer0();

Nang_Suat=abs(NS+tran*(GHD));

if (giay==60)
{ giay=0;
phut++;
Nang_Suat1=Nang_Suat;
tran=0;
set_timer0(0);
Nang_Suat=0;

}
if (phut==60)
{ phut=0;
gio++;
if (gio==24) gio=0;
}

}
}
lcd_command(0x94);
printf(lcd_data,"NANG SUAT:%d ",NANG_SUAT);
}

void main()
{
set_tris_a(0x10); //input A4
set_tris_c(0x00);

3
C:\Users\Ho Quoc Bao\Documents\Zalo Received Files\Ontap.c
set_tris_d(0);
set_tris_e(0);
set_tris_b(0);

lcd_setup();
setup_timer_0(t0_ext_h_to_l|t0_div_1);
set_timer0(0);

setup_timer_1(T1_internal|T1_DIV_BY_8);//setup for timer 1


set_timer1(3036);
while(true)
{

lcd_command(0xd4);
printf(lcd_data,"Phim F: %d", dem);
DEMSP();
thoigian();
xuatma7doan();

You might also like