0% found this document useful (0 votes)
17 views16 pages

Utp

Uploaded by

22142107
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)
17 views16 pages

Utp

Uploaded by

22142107
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/ 16

1

#include<16f887.h> // Nhan ON thi bat LED

#fuses intrc_io // Nhan OFF thi tat LED

#use delay(clock=8M) // Nhan INV thi dao trang thai LED

void main()

set_tris_e(0xff);

set_tris_c(0);

while(true)

if(input(pin_e0)==0) // NUT ON khong chong doi

output_high(pin_c0);

if(input(pin_e1)==0) // NUT OFF khong chong doi

output_low(pin_c0);

if(input(pin_e2)==0) // NUT INV => chong doi

delay_ms(20);

if(input(pin_e2)==0)

output_toggle(pin_c0);

while(input(pin_e2)==0);
}

2
#include<16f887.h> // Nhan phim 6 thi bat LED

#fuses intrc_io // Nhan phim D thi tat LED

#use delay(clock=8M)

#include<tv_key4x4.c>

unsigned int8 mp;

void main()

set_tris_b(0x0f);

set_tris_c(0);

while(true)

mp = key4x4();

if(mp==6) output_high(pin_c0);

if(mp==13) output_low(pin_c0);

}
3

#include<16f887.h> // Dem len tu 00-99

#fuses intrc_io

#use delay(clock=8M)

const unsigned int8


m7d[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

unsigned int8 n;

void main()

set_tris_c(0);

set_tris_d(0);

while(true)

for(n=0;n<100;n++)

output_c(m7d[n/10%10]); // Hang chuc

output_d(m7d[n/1%10]); // Hang don vi

delay_ms(300);

}
4
#include<16f887.h> // Hien thi bien n va chu oC

#fuses intrc_io

#use delay(clock=8M)

const unsigned int8


m7d[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

unsigned int32 n=123456;

void quetled()

output_c(m7d[n/100000%10]); output_low(pin_d0); delay_ms(1);


output_d(0xff);

output_c(m7d[n/10000%10]); output_low(pin_d1); delay_ms(1);


output_d(0xff);

output_c(m7d[n/1000%10]); output_low(pin_d2); delay_ms(1);


output_d(0xff);

output_c(m7d[n/100%10]); output_low(pin_d3); delay_ms(1);


output_d(0xff);

output_c(m7d[n/10%10]); output_low(pin_d4); delay_ms(1);


output_d(0xff);

output_c(m7d[n/1%10]); output_low(pin_d5); delay_ms(1);


output_d(0xff);

output_c(0x9c); output_low(pin_d6); delay_ms(1); output_d(0xff);

output_c(0xc6); output_low(pin_d7); delay_ms(1); output_d(0xff);

void main()

set_tris_c(0);

set_tris_d(0);
while(true)

quetled();

#include<16f887.h> // Hien thi bien bang lenh printf

#fuses intrc_io

#use delay(clock=8M)

#define lcd_rs pin_c5 // Phai dinh nghia chan truoc khi add thu vien
lcd

#define lcd_rw pin_c6

#define lcd_e pin_c7

#define output_lcd output_d

#include<tv_lcd.c> // Cam vie lai thu vien nay trong bai thi

unsigned int8 nd=32;

void main()

set_tris_c(0);

set_tris_d(0);

lcd_setup(); // Thieu lenh nay LCD khong chay => Rot mon

lcd_command(0x80); // Di chuyen con tro den dau hang 0

lcd_data("VXL BAI HOC LCD"); // Hien thi chuoi ky tu


lcd_command(0xc0+12); // Di chuyen con tro den hang 1 cot 12

lcd_data(0xdf); // Hien thi dau tron cua chu do C - tra trong bang
ma ascii

lcd_data("C");

while(true)

lcd_command(0xc0+9); // Di chuyen con tro den hang 1 cot 9

printf(lcd_data,"%u ",nd);

nd++; nd%=100; delay_ms(100);

// %d khi bien thuoc kieu signed int8

// %u khi bien thuoc kieu unsigned int8

// %ld khi bien thuoc kieu signed int16, int32

// %lu khi bien thuoc kieu unsigned int16, int32

// %03x => lay 3 chu so , neu khong co so 03 thi se tu dong xoa so 0 vo


nghia

#include<16f887.h> // Counter 0 dem san pham tu 0 den 24

#fuses hs // Counter 1 dem san pham tu 24 ve 0

#use delay(clock=20M) // Nhan nut OFF de dung dem san pham dung
Counter 1, Nhan ON de cho phep dem lai

#define lcd_rs pin_c5

#define lcd_rw pin_c6


#define lcd_e pin_c7

#define output_lcd output_d

#include<tv_lcd.c>

signed int8 T0,T1;

void main()

set_tris_a(0xff);

set_tris_c(0x01);

set_tris_d(0);

set_tris_e(0xff);

lcd_setup();

setup_timer_0(T0_EXT_H_TO_L | T0_DIV_1); // Cau hinh Counter 0

set_timer0(0);

setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1); // Cau hinh Counter 1

set_timer1(0);

while(true)

T0 = get_timer0(); // Doc ket qua dem cua Counter 0

if(T0>=25)set_timer0(T0-24); // khong che gioi han dem

lcd_command(0x80);

printf(lcd_data,"COUNTER0: %d ", T0); // Hien thi

T1 = 24- get_timer1(); // Doc ket qua dem COUNTER 1

if(T1<0) set_timer1(-T1); // Khong che gioi han dem

lcd_command(0xc0);

printf(lcd_data,"COUNTER1: %d ", T1); // Hien thi

if(input(pin_e0)==0) setup_timer_1(T1_EXTERNAL |
T1_DIV_BY_1); // Nhan ON Counter 1 dem
if(input(pin_e1)==0) setup_timer_1(T1_DISABLED); // Nhan OFF
COUNTER 1 dung dem

6
#include<16f887.h> // Dinh thoi 1s dung ca 3 bo timer

#fuses hs

#use delay(clock=20M)

#define lcd_rs pin_c5

#define lcd_rw pin_c6

#define lcd_e pin_c7

#define output_lcd output_d

#include<tv_lcd.c>

#bit TM0IF =0x0b.2 // Khai báo c? ng?t timer 0

#bit TM1IF =0x0c.0 // Khai báo c? ng?t timer 1

#bit TM2IF =0x0c.1 // Khai báo c? ng?t timer 2

unsigned int8 n0=0,giay0=0,n1=0,giay1=0,n2=0,giay2=0;

void main()

set_tris_c(0x00);

set_tris_d(0);
lcd_setup();

setup_timer_0(T0_INTERNAL|T0_DIV_256); // Cau hinh TIMER 0

set_timer0(2);

setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // Cau hinh TIMER 1

set_timer1(3036);

setup_timer_2(T2_DIV_BY_16, 254,16); // Cau hinh TIMER 2

set_timer2(0);

while(true)

if(TM0IF==1) // Kiem tra T0 tran chua

set_timer0(2); // Dat lai gia tri dem cho chu ky moi

n0++; // Tang so lan tran

TM0IF=0; // Xoa co tran

if(n0==77) // Neu tran du n lan thi dinh thoi xong

n0=0;

giay0++;

lcd_command(0x80);

printf(lcd_data,"T0:%u ",giay0);

if(TM1IF)

{ set_timer1(3036);

n1++;TM1IF=0;

if(n1==10)
{

n1=0;

giay1++;

lcd_command(0xc0);

printf(lcd_data,"T1:%u ",giay1);

if(TM2IF)

n2++;TM2IF=0;

if(n2==77)

n2=0;

giay2++;

lcd_command(0x94);

printf(lcd_data,"T2:%u ",giay2);

//T0: CT=256, n=77, nap=2

// T1:ct=8, n=10, nap =3036

// T2: ct=16,cs=16,n=77, nap=254


7
#include<16f887.h> // Do nhiet do 3 LM35, su dung 10 bit, dien ap tham
chieu noi

#device adc =10

#fuses intrc_io

#use delay(clock=8M)

#define lcd_rs pin_c5

#define lcd_rw pin_c6

#define lcd_e pin_c7

#define output_lcd output_d

#include<tv_lcd.c>

unsigned int16 kq0, kq4, kq10;

void main()

set_tris_a(0xff);

set_tris_b(0xff);

set_tris_c(0);

set_tris_d(0);

lcd_setup();

setup_adc(ADC_CLOCK_DIV_32);

setup_adc_ports(SAN0|SAN4|SAN10|VSS_VDD);

while(true)

set_adc_channel(0); delay_ms(1); // chon kenh 0

kq0=read_adc()*0.489; //do nhiet do kenh 0

lcd_command(0x80);

printf(lcd_data,"Nhiet do K0:%03lu",kq0); // Hien thi nhiet do


kenh 0
set_adc_channel(4); delay_ms(1); // chon kenh 4

kq4=read_adc()*0.489; //do nhiet do kenh 4

lcd_command(0xc0);

printf(lcd_data,"Nhiet do K4:%03lu",kq4); // Hien thi nhiet do


kenh 4

set_adc_channel(10); delay_ms(1); // chon kenh 10

kq10=read_adc()*0.489; //do nhiet do kenh 10

lcd_command(0x94);

printf(lcd_data,"Nhiet do K10:%03lu",kq10); // Hien thi nhiet do


kenh 10

#include<16f887.h> // Do nhiet do 3 LM35, su dung 8 bit, dien ap tham


chieu vref+=1.5v, vref-=0v

//#device adc =10 // bo dong nay la 8 bit

#fuses intrc_io

#use delay(clock=8M)

#define lcd_rs pin_c5

#define lcd_rw pin_c6

#define lcd_e pin_c7

#define output_lcd output_d


#include<tv_lcd.c>

unsigned int16 kq0, kq4, kq10;

void main()

set_tris_a(0xff);

set_tris_b(0xff);

set_tris_c(0);

set_tris_d(0);

lcd_setup();

setup_adc(ADC_CLOCK_DIV_32);

setup_adc_ports(SAN0|SAN4|SAN10|VSS_Vref); // Phai sua lai dien ap


tham chieu cho dung

while(true)

set_adc_channel(0); delay_ms(1); // chon kenh 0

kq0=read_adc()*0.588; //do nhiet do kenh 0

lcd_command(0x80);

printf(lcd_data,"Nhiet do K0:%03lu",kq0); // Hien thi nhiet do


kenh 0

set_adc_channel(4); delay_ms(1); // chon kenh 4

kq4=read_adc()*0.588; //do nhiet do kenh 4

lcd_command(0xc0);

printf(lcd_data,"Nhiet do K4:%03lu",kq4); // Hien thi nhiet do


kenh 4

set_adc_channel(10); delay_ms(1); // chon kenh 10

kq10=read_adc()*0.588; //do nhiet do kenh 10

lcd_command(0x94);
printf(lcd_data,"Nhiet do K10:%03lu",kq10); // Hien thi nhiet do
kenh 10

#include<16f887.h> // Dem giay dung ngat timer 1

#device adc =10 // Do nhiet do dung ngat ADC

#fuses hs

#use delay(clock=20M)

#define lcd_rs pin_c5

#define lcd_rw pin_c6

#define lcd_e pin_c7

#define output_lcd output_d

#include<tv_lcd.c>

unsigned int8 bdn=0, giay=0;

unsigned int16 kq;

void main()

set_tris_c(0);

set_tris_d(0);

set_tris_e(0xff);

lcd_setup();
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);

set_timer1(3036);

setup_adc(ADC_CLOCK_DIV_32);

setup_adc_ports(san5|vss_vdd);

set_adc_channel(5); delay_us(20);

enable_interrupts(INT_TIMER1); // Cho phep ngat Timer 1

enable_interrupts(INT_AD); // Cho phep ngat ADC

enable_interrupts(GLOBAL); // Cho Phep ngat toan cuc

while(true)

lcd_command(0x80);

printf(lcd_data,"GIAY=%03d",giay);

read_adc(ADC_START_ONLY);

lcd_command(0xc0);

printf(lcd_data,"NHIET DO=%03lu",kq);

#INT_TIMER1 // Chuong trinh xu ly ngat timer 1

void xulyngattimer1()

set_timer1(3036);

bdn++;

if(bdn==10)

bdn=0; giay++;

}
#INT_AD // Chuong trinh xu ly ngat ADC

void xulyngatadc()

kq =read_adc(ADC_READ_ONLY)*0.489;

You might also like