Vous êtes sur la page 1sur 7

1.

Chương
2.
3. chuong trình
trinh
4. chuong
2lam
làm
ledcho
8dich
led
trình
ledtu
chớp
dich
dich
bit tăt
thap
tu
2 led
led
den
tu
0 den
bit cao
led (0
den
7 den
bit7)
thap
ròi va
dịch
nguoc lai (0-2,1-3,
ngược lại từ 2-4,
bit cao
3-5,tới4-6,
bit 5-7
thất
set_tris_d(0x00);
while(1)
#include<16f887.h> {
#fuses HS,NOWDT,NOPROTECT,PUT a=0b00000011;
#use delay (clock=16000000) for(i=0;i<8;i++)
//chuong trinh lam 8 led chop tat {
void main() output_d(a);
{ delay_ms(100);
set_tris_d(0x00); a<<=1;
while(1) }
{ b=0b11000000;
output_d(0xff); for(j=8;j>0;j--)
delay_ms(100); {
output_d(0x00); output_d(b);
delay_ms(100); delay_ms(100);
} b>>=1;
} }

#include<16f887.h>
#fuses HS,NOWDT,NOPROTECT,PUT #fuses HS,NOWDT,NOPROTECT,PUT
#use delay (clock=16000000) #use delay(clock=16000000)
//chuong trinh lam cho led dich tu led 0 den led 7 //chuong trình dich 2 led tu bit cao den bit thap va
void main() nguoc lai
{ void main()
char a,i; {
set_tris_d(0x00); char a,i;
while(1) while(1)
{ {
a=0x01; a=0b00000101;
for(i=0;i<8;i++) for(i=0;i<9;i++)
{ {
output_d(a); if(i<5)
delay_ms(100); {
a<<=1; output_d(a);
} delay_ms(3500);
#fuses HS,NOWDT,NOPROTECT,PUT a<<=1;
#use delay(clock=16000000) }
//chuong trình 2 led dich tu bit thap den bit cao (0 else
den 7): {
void main() output_d(a);
{ delay_ms(3500);
char a,b,i,j; a>>=1;
6. chuong trinh
5. TIMER 8.7.dem
chương Viet
chuong
BCD
chuong
trinh trinh
tu 00
dungtrình
cho
denthuc
2 99
timer2ledhien
dichthời
định bien
tu trong
doi dien
100ms rava
2 ben
the
đảoanalog
roi tu thai
trạng 2ngo
benvào
vaothành
trong
của led. giá tri nhi phân 8 bit và xuat ra led (bien doi ADC).
}}}} a=b=0x00;
#include<16f887.h>
#fuses HS,NOWDT,NOPROTECT,PUT while(a<0x99)
#use delay(clock=8000000) {
#byte PIR1 = 0x0c output_d(a^b);
#bit TMR2IF = PIR1.1 delay_ms(50);
void main() b++;
{ if(b>9)
char a=0; {b=0;
int i; a+=0x10;
long int count=0; }}}}
set_tris_d(0x00); #use delay(clock=16000000)
disable_interrupts(global); void main()
disable_interrupts(int_timer2); {
setup_TIMER_2(T2_DIV_BY_1, 200, 1); char i,a,b,c;
set_TIMER2(0); set_tris_d(0x00);
while(1) while(1)
{ {
a=0x01; a=0x01;
output_d(a); b=0x80;
for(i=0;i<8;i++) for(i=0;i<4;i++)
{ {
while(1) c=a^b;
if(TMR2IF==1) output_d(c);
{ delay_ms(150);
TMR2IF=0; a<<=1;
count++; b>>=1;
{ }
count=0; for(i=0;i<4;i++)
a<<=1; {
output_d(a); c=a^b;
break;} output_d(c);
}}}} delay_ms(150);
a>>=1;
b<<=1;
#use delay(clock=16000000) }}}
//chuong trinh dem bcd tu 0 den 99
void main() #DEVICE ADC=8
{ #use delay(clock=8000000)
char a,b; void main()
while(1){ {
set_tris_d(0x00); char value;
9. Name 10. Name
set_tris_d(0x00); clear_interrupt(INT_EXT);
set_tris_a(0xff); }
disable_interrupts(global); void main()
setup_adc(ADC_CLOCK_INTERNAL); {
setup_adc_ports(ALL_ANALOG); while(1)
set_adc_channel(0); {
while(1) a=a+1;
{ output_d(a);
if(ADC_done()) delay_ms(100);
{ enable_interrupts(global);
delay_us(10); enable_interrupts(INT_EXT);
value=read_adc(); ext_int_edge( H_TO_L );
output_d(value); clear_interrupt(INT_EXT);
} }} }}

#use delay (clock=8000000) #use delay(clock=8000000)


char a=0; char a,i,k;
#INT_EXT #INT_EXT
void ext_isr() void ext_isr()
{ {
unsigned char b,c,i,j; for(i=0;i<8;i++)
for(j=0;j<5;j++) {
{ b=0x80; output_d(a);
c=0x01; delay_ms(200);
output_d(b|c); a>>=1;
delay_ms(50); }
for(i=0;i<8;i++) clear_interrupt(INT_EXT);
{ }
if(b==0x01&c==0x40) void main()
{ {
b<<=1; while(1)
c>>=1; {
output_d(b|c); enable_interrupts(global);
delay_ms(50); k=enable_interrupts(INT_EXT);
} ext_int_edge( H_TO_L );
else clear_interrupt(INT_EXT);
{ a=0x01;
b>>=1; //set_tris_d(0x01);
c<<=1; for(i=0;i<8;i++)
output_d(b|c); {
delay_ms(50); output_d(a);
} }} delay_ms(200);
11. Name 12. 2led dich tu that toi cao roi dich nguoc lai
a<<=1; }
} }} BaiCongTac
#use delay(clock=8000000)
#byte portb=0x06
#use delay(clock=8000000)
#bit rb0=portb.0
#byte PIR1 = 0x0c
void main()
#bit TMR2IF = PIR1.1
{
char i,a;
long int count=0;
set_tris_d(0x00);
char a,b,j,i,kq;
set_tris_b(0xff);
#INT_TIMER2
output_d(0x00);
void timter2_isr()
while(1)
{
{
count++;
if(rb0==1)
if(count==10000)
{
{
a=0x01;
count=0;
for(i=0;i<8;i++)
for(i=0;i<10;i++)
{
{
output_d(a);
for(j=0;j<10;j++)
delay_ms(200);
{
a<<=1;
a=i;
}}
a<<=4;
else
b=j;
{
// b=b+1;
a=0x80;
kq=a+b;
for(i=0;i<8;i++)
output_d(kq);
{
delay_ms(100);
output_d(a);
delay_ms(200);
}}
a>>=1;
}
} }}}
clear_interrupt(INT_TIMER2);
}
void main()
#use delay(clock=16000000)
{
void main()
char a=0;
{
char b=0;
char a,i;
set_tris_d(0x00);
set_tris_d(0x00);
enable_interrupts(global);
while(1)
enable_interrupts(int_timer2);
{
setup_TIMER_2(T2_DIV_BY_1, 200, 1);
a=0x03;
set_TIMER2(0);
for(i=0;i<12;i++)
while(1);
13. 2leddichtuthaplencao14. dịch 15.
hai
16. led
2led
NgatNgoai
tu cao
dichtotuthap
that toi cao roi dich nguoc lai
{ output_d(a);
if(i<6) delay_ms(2);
{ a>>=1;
output_d(a); }}}
delay_ms(20);
a<<=1;
} #use delay(clock=16000000)
else void main()
{ {
output_d(a); char a,i;
delay_ms(20); set_tris_d(0x00);
a>>=1; while(1)
}}}} {
a=0x03;
for(i=0;i<12;i++)
#use delay(clock=16000000) {
void main() if(i<6)
{ {
char a,i; output_d(a);
set_tris_d(0x00); delay_ms(20);
while(1) a<<=1;
{ }
a=0x03; else
for(i=0;i<16;i++) {
{ output_d(a);
output_d(a); delay_ms(20);
delay_ms(20); a>>=1;
a<<=1; }}}
}}}}

#use delay(clock = 8000000)


#include<16f887.h> #INT_EXT
#fuses HS,NOWDT,NOPROTECT,PUT void ext_isr()
#use delay(clock=16000000) {
void main() //a^=0xff;
{ //output_d(a);
char a,i; char a,i;
set_tris_d(0x00); a=0x80;
while(1) for(i=0; i <8 ; i++ )
{ {
a=0xc0; output_d(a);
for(i=0;i<16;i++) delay_ms(100);
{ a>>=1;
17. dich led theo hinh chu Z 18.
20. 7led choptrình
Chuong tat19.
led duổi
Led vòng
sáng nhau
dần từ 0-7
} output_d(a);
clear_interrupt(INT_EXT); //cau lenh xoa ngat, sau delay_ms(200);
khi thuc thi se xoa ngat ve 0, tang len 1 bao hieu a>>=1;
khi co 1 ngat xay }}}
}
void main()
{ #include<16f887.h>
char a,i; #fuses HS,NOWDT,NOPROTECT,PUT
set_tris_d(0x00); #use delay(clock=16000000)
set_tris_b(0xff); void main()
enable_interrupts(global); {
// cho phep thuc hien chuong trinh ngat tren toan set_tris_d(0x00);
cuc while(1)
enable_interrupts(INT_EXT); {
// cho phep chuong trinh thuc thi ngat tuong ung, output_d(0xff);
ngat o day la theo INT_EXT delay_ms(100);
ext_int_edge(H_TO_L); output_d(0x00);
//dinh nghia ngat tu muc cao xuong muc thap delay_ms(100);
clear_interrupt(INT_EXT);//cau lenh xoa ngat }}
while(1)
{
a=0x01; #USE delay(clock=16000000)
for(i=0;i<8; i++) void main()
{ {
output_d(a); char a,i,j;
delay_ms(100); set_tris_d(0x00);
a<<=1; while(1)
}}} {
a=0x00;
output_d(a);
#use delay(clock=16000000) delay_ms(100);
void main() for(i=0;i<8;i++)
{ {
unsigned char a,i; a<<=1;
set_tris_d(0x00); a=a^0x01;
while(1) output_d(a);
{ delay_ms(100);
a=0x01; }}}
for(i=0;i<6;i++)
{
output_d(a); #use delay(clock=16000000)
delay_ms(100); void main()
a<<=2; {
char a,i;
set_tris_d(0x00);
while(1)
{
a=0xc0;
for(i=0;i<8;i++)
{
if(i>6)
{
output_d(0x81);
delay_ms(200);
}
else
{
output_d(a);
delay_ms(200);
a>>=1;
}
}}}

Vous aimerez peut-être aussi