Giáo trình AVR - Chương 3: Các ứng dụng - Cao Bá Vinh

Mục đích:
• giúp cho Sinh viên tìm hiểu thực hành viết chương trình của ATmega.
• Điều khiển led đơn.
• Điều khiển nút nhấn đơn .
• Điều khiển led 7 đoạn.
• Điều khiển led ma trận.
• Điều khiển lcd_text.
• Các ứng dụng liên quan tới robot
Yêu cầu:
• Sinh viên phải nắm được các thanh ghi xuất nhập(PORTx,DDRx,PINx)
• Phải hiểu rõ phần tính toán timer , cấu hình ngắt ngoài.
• Nắm rõ chuyển đổi ADC và lưu dữ liệu eeprom.
• Biết cách sử dụng các chuẩn giao tiếp (spi,usart,i2c)
pdf 262 trang thamphan 27/12/2022 1600
Bạn đang xem 20 trang mẫu của tài liệu "Giáo trình AVR - Chương 3: Các ứng dụng - Cao Bá Vinh", để tải tài liệu gốc về máy hãy click vào nút Download ở trên.

File đính kèm:

  • pdfgiao_trinh_avr_chuong_3_cac_ung_dung_cao_ba_vinh.pdf

Nội dung text: Giáo trình AVR - Chương 3: Các ứng dụng - Cao Bá Vinh

  1. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng chay_do_lai(90,120,1); chay_do_lai(100,40,1); chay_thang(40,30,500); // queo_phai_lui_cham(); queo_phai(); //dung(0); chay_thang(30,90,750); chay_do_lai(90,100,3); chay_do_lai(70,40,1); chay_thang(40,30,500);xl_tay_kep_on; //queo_phai_lui_cham(); queo_phai(); val_pwm=40;role_tru_off;fet_tru=0;tm_out=0; while(!(!nut_truoc || tm_out>1500)) { do_lai(); } dung(2); xl_kep_on; delay_ms(150); encoder_tru=0; role_tru_off;fet_tru=150; while(encoder_tru 5) i++; else i=0; delay_ms(1); Biên son : Ks.Cao Bá Vinh 207
  2. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng lui_trai(30);lui_phai(30); encoder_trai=320; while(!(encoder_trai 5) i++; else i=0; delay_ms(1); } encoder_trai=750; while(!(encoder_trai<10));dung(50);xl_tay_lon_on; } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx void lay_de_lan2_vung1_xanh(void) { //queo_phai_gap_de2(); if(bit_vung==2){queo_trai_gap_de2();} else queo_phai_gap_de2(); queo_trai_lui(); chay_thang(20,150,6250); chay_do_lai(120,40,2); chay_thang(40,30,570); queo_trai(); chay_thang(30,70,625); chay_do_lai(70,70,2); chay_do_lai(60,40,1); chay_thang(40,30,500); queo_trai_lui(); bit_nang_tru=1;val_tru=300; role_tru_off;fet_tru=200; Biên son : Ks.Cao Bá Vinh 209
  3. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng lui_trai(40);lui_phai(40); while(!(encoder_trai 5 || encoder_phai>825)) { do_lai(); if(dem_cb()>5) i++; else i=0; } encoder_tru=0; bit_nang_tru=1;val_tru=60; role_tru_off;fet_tru=150; chay_thang(30,30,730);dung(100); lay_qua_xanh_xa(); trang_tri_xanh(); encoder_trai=1000;encoder_phai=1000; lui_trai(40);lui_phai(40); while(!(encoder_trai<10 && encoder_phai<10));dung(100); chay_thang(30,30,1050); cho_bang_tay(); while(nut_truoc) { cap_thanh_trai(26,475); delay_ms(20); } lay_de_len_song_xanh(); Biên son : Ks.Cao Bá Vinh 211
  4. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng if(dem_cb()==0)i++; else i=0; } delay_ms(350); dung(10); xl_tay_lon_off;xl_kep_off; encoder_trai=1200; lui_trai(30);lui_phai(30); while(!(encoder_trai 250)); //chay_thang(40,30,150); //queo_trai(); queo_phai_lui_t(); chay_thang(40,60,300); chay_do_lai(40,60,2); chay_do_lai(60,40,1); chay_thang(40,40,200); queo_phai_lui_t(); len_doc_xep_de_xanh(); lay_qua_xanh(); trang_tri_xanh(); Biên son : Ks.Cao Bá Vinh 213
  5. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng while(!(encoder_trai>2750)) { chay_thang_goc_nho(80,900); delay_ms(4); } chay_do_lai(90,40,2); chay_thang(40,30,620); queo_trai(); chay_thang(30,30,200); encoder_tru=0; role_tru_off;fet_tru=120; bit_nang_tru=1;val_tru=60; dung(100); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxlay qua nho lay_qua_xanh_xa(); // lay_qua_nho() &&& lay qua lon trang_tri_xanh(); encoder_trai=1500; while(!(encoder_trai 1400)) { cap_thanh_trai(20,435); delay_ms(10); } dung(100); cho_bang_tay();i=0;tm_out=0; ct_trai_ldls(); xl_tay_lon_off; //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx queo len song toi_trai(30);lui_phai(4); i=0; Biên son : Ks.Cao Bá Vinh 215
  6. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng dung(100); role_tru_on;fet_tru=0; while(!(encoder_tru 3500 && encoder_phai>3500)) { cap_thanh_phai(180,520);//475 //120 delay_ms(10); } tm_out=0; while(!(!nut_truoc || tm_out>1800 )) // { cap_thanh_phai(20,530); //475 delay_ms(3); //chay_thang_goc(20,2750); chay_thang_goc(0,20,2750); delay_ms(3); } Biên son : Ks.Cao Bá Vinh 217
  7. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng while(!(encoder_trai>10220)) //7500 { chay_thang_goc(0,10,1550);//475 //120 delay_ms(5); } // dung(100);while(1); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bit_nang_tru=1;val_tru=350; role_tru_off;fet_tru=255; //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx queo_len doc dung(100); toi_trai(55);lui_phai(15); i=0; while(!(i>3)) { if(gocquay()>2450)i++; else i=0; } toi_trai(20);lui_phai(8); i=0; while(!(i>3)) { if(gocquay()>2600)i++; else i=0; } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //dung(100);while(1); dung(100); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx len doc encoder_trai=0;encoder_phai=0; while(!(encoder_trai>3000 && encoder_phai>3000)) //7500 Biên son : Ks.Cao Bá Vinh 219
  8. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng { cap_thanh_phai(60,420); delay_ms(10); //if(tm_out>2000)break; } //zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz dung(10); // dung(100);while(1); bit_ha_tru=0; role_tru_on;fet_tru=40; i=0; while(!(!nut_tru || i>1000)){delay_ms(1);i++;} xl_kep_off;xl_tay_lon_off;xl_tay_kep_off;role_tru_off;fet_tru=0; delay_ms(100); xl_xoay_tru_on; encoder_trai=0;encoder_phai=0;tm_out=0; while(!(encoder_phai>1540)) { cap_thanh_phai(16,420);//395 delay_ms(10); if(tm_out>150) { if(encoder_trai 400)break; } Biên son : Ks.Cao Bá Vinh 221
  9. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng } encoder_tru=0; role_tru_off;fet_tru=80; bit_nang_tru=1;val_tru=60; dung(50); //xl_tay_nho_on; //delay_ms(300);encoder_tru=60; // role_tru_off;fet_tru=250; //bit_nang_tru=1;val_tru=610; //while(!(encoder_tru>610)); /* lay_qua_nho(); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //val_pwm=30; encoder_trai=0;i=0; while(!(encoder_trai>800 || i>3)) { cap_thanh_phai(35,475); chay_thang_goc(0,35,2750); chay_thang_goc(0,35,2750); if(dem_cb()>4)i++; else i=0; } encoder_trai=0; while(!(encoder_trai>350)) { cap_thanh_phai(35,475); chay_thang_goc(0,35,2750); chay_thang_goc(0,35,2750); } Biên son : Ks.Cao Bá Vinh 223
  10. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng dung(100);while(1); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx void kt_xanh(void) { while(1) { lcd_gotoxy(0,0); lcd_putsf(" xanh xanh xanh "); val_adc=read_adc(0); if(val_adc 150) && (val_adc<300)) { lcd_gotoxy(0,1); lcd_putsf(" dau trung quoc "); if(!nut_green) { delay_ms(150); if(!nut_green){dau_trungquoc();} //x_qua1_xanh() } } else if((300<val_adc) && (val_adc<450)) { lcd_gotoxy(0,1); lcd_putsf(" start cham "); if(!nut_green) { delay_ms(50); if(!nut_green) {bat_dau_xanh_cham();} } } Biên son : Ks.Cao Bá Vinh 225
  11. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng } else if(!nut_pink) { delay_ms(50); if(!nut_pink) {lay_de_lan2_vung2_xanh();} } } else if((770<val_adc) && (val_adc<800)) { i=gocquay(); sprintf(mang,"%d",i); lcd_gotoxy(0,0);lcd_puts(mang); lcd_putsf(" "); /* if(!nut_green) { delay_ms(50); if(!nut_green) {beta=i;} } sprintf(mang,"%d",beta); lcd_gotoxy(6,0);lcd_puts(mang); lcd_putsf(" "); sprintf(mang,"%d",goc()); lcd_gotoxy(0 ,1);lcd_puts(mang); lcd_putsf(" "); */ } else if((800<val_adc) && (val_adc<850)) { lcd_gotoxy(0,0); lcd_putsf("sa_t sa_p sa_t "); j=sieuam_trai(); sprintf(mang,"%d",j); lcd_gotoxy(0,1);lcd_puts(mang); j=sieuam_phai(); sprintf(mang,"%d",j); lcd_gotoxy(6,1);lcd_puts(mang); } Biên son : Ks.Cao Bá Vinh 227
  12. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx void lay_de_do(void) { /* encoder_trai=0; toi_trai(50);toi_phai(50); while(!(encoder_trai>4000)); dung(200); lui_trai(50);lui_phai(50); while(!(encoder_trai 4000 && encoder_phai>4000)) { cap_thanh_trai(100,570);//475 //120 delay_ms(10); } tm_out=0; while(!(!nut_truoc || tm_out>1800 )) // { cap_thanh_trai(22,570); //475 delay_ms(3); //chay_thang_goc(20,2750); chay_thang_goc(0,22,2750); delay_ms(3); } dung(20); Biên son : Ks.Cao Bá Vinh 229
  13. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng // s=190+j; //encoder_trai=s;encoder_phai=s; lui_trai(30);lui_phai(34); while(!(encoder_phai 3600 && encoder_phai>3600)) //7500 { chay_thang_goc(0,100,2806);//475 //120 delay_ms(2); } */ if(bit_nhanh_cham==1){len_doc_cham();} else { Biên son : Ks.Cao Bá Vinh 231
  14. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng // dung(100);while(1); so_line=0; encoder_phai=0;encoder_trai=0; while(so_line 1500)){delay_ms(1);i++;} xl_kep_off;xl_tay_lon_off;xl_tay_kep_off;role_tru_off;fet_tru=0; delay_ms(100); xl_xoay_tru_on; encoder_trai=0;encoder_phai=0;tm_out=0; while(!(encoder_phai>1540)) { cap_thanh_trai(16,435);//395 delay_ms(10); if(tm_out>250) { j=encoder_trai; if((ji)<3){break;} Biên son : Ks.Cao Bá Vinh 233
  15. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng xl_xoay_tru_on; encoder_trai=0;encoder_phai=0;tm_out=0; while(!(encoder_phai>1540)) { cap_thanh_trai(16,420);//395 delay_ms(10); if(tm_out>150) { if(encoder_trai 400)break; } dung(40); encoder_trai= 2350;encoder_phai=2350; while(!(encoder_trai<925 && encoder_phai<925)) { chay_lui_goc(60,2770); delay_ms(5); } while(!(encoder_trai<500 && encoder_phai<500)) { chay_lui_goc(30,2770); delay_ms(5); } while(!(encoder_trai<10 && encoder_phai<10)) { Biên son : Ks.Cao Bá Vinh 235
  16. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng { cap_thanh_trai(35,475);delay_ms(4); chay_thang_goc(0,35,2750);delay_ms(3); } while(!(i>1 || encoder_trai>1000 )) { cap_thanh_trai(35,475);delay_ms(4); chay_thang_goc(0,35,2750);delay_ms(3); if(dem_cb()>3)i++; else i=0; } chay_thang(30,30,450); dung(10); xl_tay_lon_on; delay_ms(400); role_tru_off;fet_tru=250; bit_nang_tru=1;val_tru=1300; while(!(encoder_tru>1300)); //lui_phai(6);toi_trai(6); xl_xoay_tru_off; tm_out=0;i=0; // delay_ms(400); while(nut_truoc) { if(tm_out>2500)break; cap_thanh_trai(26,410); delay_ms(20); } //lui_phai(3);lui_trai(3); dung(650); } Biên son : Ks.Cao Bá Vinh 237
  17. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng void bat_dau_do_cham(void) { bit_nhanh_cham=1; bat_dau_do(); } //xxxxxxxxxxxxxxxxxxxxxxxxxxx void xep_qua_lan1_do(void) { role_tru_on;fet_tru=10; chay_5_lai_xanh(); dung(50); encoder_tru=0; bit_nang_tru=1;val_tru=70; role_tru_off;fet_tru=100; xl_xoay_tru_on; queo_trai_lui(); dung(50); chay_thang(40,60,1000); //3750 encoder_trai=0; while(!(encoder_trai>3500)) { chay_thang_goc(0,60,2800); delay_ms(4); } //chay_do_lai(60,40,1); i=0;encoder_trai=0; while(!(i>2)) { if(dem_cb()>4 )i++;// || else i=0; if(encoder_trai>1000)break; Biên son : Ks.Cao Bá Vinh 239
  18. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx void xep_qua_lan2_do_vung2(void) // vung 2 { role_tru_on;fet_tru=10; //chay_5_lai_xanh(); chay_thang(40,90,500); chay_do_lai(90,140,6); chay_do_lai(100,60,1); chay_do_lai(60,40,1); chay_thang(40,30,580); role_tru_off;fet_tru=0; queo_phai_lui(); //dung(100);while(1); // chay_thang(40,90,3800); chay_thang(40,80,1000); //3750 encoder_trai=0; while(!(encoder_trai>2750)) { chay_thang_goc_nho(80,900); delay_ms(4); } chay_do_lai(90,40,2); chay_thang(40,30,620); queo_phai(); // dung(100);while(1); chay_thang(30,30,200); encoder_tru=0; role_tru_off;fet_tru=120; bit_nang_tru=1;val_tru=60; dung(100); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxlay qua nho lay_qua_do_xa(); // lay_qua_nho() &&& lay qua lon trang_tri_xanh(); encoder_trai=1050; lui_trai(30);lui_phai(30); while(!(encoder_trai<10));dung(100); Biên son : Ks.Cao Bá Vinh 241
  19. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng if(bit_vung==2){queo_phai_gap_de2();} else queo_trai_gap_de2(); queo_phai_lui(); chay_thang(30,150,6250); chay_do_lai(120,40,2); chay_thang(40,30,570); queo_phai(); chay_thang(30,70,625); chay_do_lai(70,70,2); chay_do_lai(60,40,1); chay_thang(40,30,500); queo_phai_lui(); bit_nang_tru=1;val_tru=300; role_tru_off;fet_tru=200; chay_thang(40,90,3750); //xxxxxxxxlen doc chay_do_lai(90,60,1); role_tru_on;fet_tru=0; bit_ha_tru=1;val_tru=200; chay_do_lai(60,36,2); dung(50); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bit_ha_tru=0; role_tru_on;fet_tru=10; i=0; while(!(!nut_tru || i>1500)){delay_ms(1);i++;} xl_kep_off;xl_tay_lon_off;xl_tay_kep_off;role_tru_off;fet_tru=0; delay_ms(100); Biên son : Ks.Cao Bá Vinh 243
  20. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng encoder_tru=0; bit_nang_tru=1;val_tru=60; role_tru_off;fet_tru=150; chay_thang(30,30,530);dung(100); lay_qua_do_xa(); trang_tri_xanh(); encoder_trai=1050; lui_trai(30);lui_phai(30); while(!(encoder_trai 500)) { cap_thanh_phai(26,475); delay_ms(5); chay_thang_goc_nho(26,900);delay_ms(3); chay_thang_goc_nho(26,900);delay_ms(3); } dung(100); cho_bang_tay(); ct_phai_ldls(); /* while(nut_truoc) { //cap_thanh_phai(26,475); //delay_ms(5); if(!cb_tay_kep) { dung(10);i=0; while(!(i>20)) { if(cb_tay_kep)i++; else i=0; delay_ms(1); } } chay_thang_goc_nho(26,900);delay_ms(3); } Biên son : Ks.Cao Bá Vinh 245
  21. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng delay_ms(3); //chay_thang_goc(20,2750); chay_thang_goc(0,20,2750); delay_ms(3); } dung(20); xl_kep_on; xl_tay_lon_on; dung_tron(20); toi_trai(9);toi_phai(9); delay_ms(80); dung(50); encoder_tru=0; role_tru_off;fet_tru=150;tm_out=0; while(!(encoder_tru>90 || tm_out>1500)); fet_tru=20; //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx way way way lui_phai(15);toi_trai(60); i=0; while(!(i>3)) { if(gocquay()>3400)i++; else i=0; } i=0; while(!(i>2)) { if(gocquay()<3400)i++; else i=0; Biên son : Ks.Cao Bá Vinh 247
  22. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng i=0; while(!(i>3)) { if(gocquay()>3400)i++; else i=0; } toi_phai(26);lui_trai(8); i=0; while(!(i>3)) { if(gocquay() 600 && encoder_phai>600)) { chay_thang_goc(0,40,2820); //150 delay_ms(5); } while(!(encoder_trai>3000 && encoder_phai>3000)) { chay_thang_goc(0,80,2820); //150 delay_ms(5); } while(!(encoder_trai>3800 && encoder_phai>3800)) { chay_thang_goc(0,70,2820); //120 delay_ms(6); } i=0; while(!(i>4)) { Biên son : Ks.Cao Bá Vinh 249
  23. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng //zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz dung(10); bit_ha_tru=0; role_tru_on;fet_tru=20; i=0; while(!(!nut_tru || i>1000)){delay_ms(1);i++;} xl_kep_off;xl_tay_lon_off;xl_tay_kep_off;role_tru_off;fet_tru=0; delay_ms(100); xl_xoay_tru_on; encoder_trai=0;encoder_phai=0;tm_out=0;i=0; while(!(encoder_phai>1540)) { cap_thanh_trai(16,425);//395 delay_ms(10); if(tm_out>150) { if(encoder_trai 400)break; } dung(40); Biên son : Ks.Cao Bá Vinh 251
  24. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng encoder_trai=0; while(!(encoder_trai>350)) { cap_thanh_trai(35,475); chay_thang_goc(0,35,2750); chay_thang_goc(0,35,2750); } dung(10); xl_tay_lon_on; delay_ms(400); role_tru_off;fet_tru=250; bit_nang_tru=1;val_tru=1300; while(!(encoder_tru>1300)); //lui_phai(6);toi_trai(6); xl_xoay_tru_off;tm_out=0; // delay_ms(400); while(nut_truoc) { if(tm_out>2500)break; cap_thanh_trai(22,425); delay_ms(20); } //lui_phai(3);lui_trai(3); dung(600); */ trang_tri_xanh(); bit_can_pha=5; Biên son : Ks.Cao Bá Vinh 253
  25. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng else if((val_adc>150) && (val_adc 300) && (val_adc<450)) { lcd_gotoxy(0,1); lcd_putsf(" start cham "); if(!nut_green) { delay_ms(150); if(!nut_green) {bat_dau_do_cham();} } } else if((450<val_adc) && (val_adc<600)) { lcd_gotoxy(0,1); lcd_putsf("len song lan 2 "); if(!nut_green) { delay_ms(50); if(!nut_green) {len_song2_vung1_do();} } if(!nut_pink) { delay_ms(50); if(!nut_pink) {len_song2_vung2_do();} } } else if((600<val_adc)&& (val_adc<750)) Biên son : Ks.Cao Bá Vinh 255
  26. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng if(!cb_tay_nho) { lcd_gotoxy(11,1); lcd_putsf("0"); } else { lcd_gotoxy(11,1); lcd_putsf("1"); } if(!cb_tay_lon) { lcd_gotoxy(12,1); lcd_putsf("0"); } else { lcd_gotoxy(12,1); lcd_putsf("1"); } if(!nut_tru) { lcd_gotoxy(13,1); lcd_putsf("0"); } else { lcd_gotoxy(13,1); lcd_putsf("1"); } if(!nut_truoc) { lcd_gotoxy(14,1); lcd_putsf("0"); } else { lcd_gotoxy(14,1); lcd_putsf("1"); Biên son : Ks.Cao Bá Vinh 257
  27. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng DDRC=0b11111111; PORTD=0xff; DDRD=0x00; PORTE=0xff; DDRE=0b11011100; PORTF=0xff; DDRF=0b00111100; PORTG=0xff; DDRG=0B10100; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 62.500 kHz // Mode: Normal top=FFh // OC0 output: Disconnected ASSR=0x00; TCCR0=0x00; // LAM LCD KO LEN NEU 0X05 TCNT0=0x00; OCR0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 62.500 kHz // Mode: Ph. correct PWM top=00FFh // OC1A output: Inverted // OC1B output: Inverted // OC1C output: Inverted // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off // Compare C Match Interrupt: Off TCCR1A=0xFD; TCCR1B=0x04; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; Biên son : Ks.Cao Bá Vinh 259
  28. Giáo trình AVR Khoa ðinðin TTrưng ðH Lc Hng // INT0 Mode: Falling Edge // INT1: On // INT1 Mode: Falling Edge // INT2: On // INT2 Mode: Falling Edge // INT3: Off // INT4: Off // INT5: Off // INT6: Off // INT7: Off EICRA=0x2A;// canh ngat EICRB=0x00; EIMSK=0x07;//00000111; EIFR=0x07; // co ngat // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x40;//ENABLE TIMER 2(BIT CHO PHAP NGAT); ETIMSK=0x00; //NGAT NGOAI // Timer(s)/Counter(s) Interrupt(s) initialization //TIMSK=0x01; //ETIMSK=0x00; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // ADC initialization // ADC Clock frequency: 250.000 kHz // ADC Voltage Reference: AVCC pin ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0x87; // LCD module initialization delay_ms(10); lcd_init(); delay_ms(10); Biên son : Ks.Cao Bá Vinh 261