Académique Documents
Professionnel Documents
Culture Documents
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);
} }} }}