![]() |
|
Tài trợ cho PIC Vietnam |
||||||||
| Bootloaders - Programmers - Debuggers - Emulators Những công cụ cần thiết để lập trình cho PIC/dsPIC |
![]() |
|
|
Ðiều Chỉnh | Xếp Bài |
|
|
|
|
#1 |
|
Đệ tử 2 túi
|
Đây là chương trình dùng ngắt Timer0 định thì 1s.
Đầu tiên led ở chân RB0 sáng, sau 1s sẽ dịch sang trái, nghĩa là led 1 trên chân RB1 sáng , lần lượt như vậy cho các led trên portB và lặp lại mãi mãi. Em có đoạn code sau: Code:
#include <16F877A.h>
#fuses NOWDT,PUT,XT,NOPROTECT
#use delay(clock=4000000)
#byte PORTB = 0x06
int16 count;
int8 a;
//Chuong trinh ngat TMR0
#int_timer0
void interrupt_timer0()
{
set_timer0(6);
++count;
if(count == 2000) // 2000*500us = 500000us = 1s
{
count=0;
rotate_left(&a,1);
}
}
//Chuong trinh chinh
void main(void)
{
set_tris_b(0);
enable_interrupts(int_timer0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
enable_interrupts(global);
set_timer0(6);// T_dinhthi = 2*(256 - 6)*1us = 500us
a = 0x01;
while(true)
{
PORTB = a;
}
}
int16 count; int8 a; có ý nghĩa là gì? còn set_timer0(6); là gì ? Đáng lẽ ra là phải set_timer0(8); chứ , do set_timer0(value); là xác định giá trị ban đầu (8bit) cho timer0. thay đổi nội dung bởi: namqn, 25-02-2009 lúc 04:19 PM. |
|
|
|
|
|
#2 |
|
Đệ tử 2 túi
|
Bác namqn mong bác giải thích cho em được hiểu về đoạn mã trên . Em cảm ơn.
|
|
|
|
|
|
#3 | |
|
Trưởng lão PIC bang
|
Trích:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf Thân,
__________________
Biển học mênh mông, sức người có hạn. Đang gặp vấn đề cần được giúp đỡ? Hãy dành ra vài phút đọc luồng sau: http://www.picvietnam.com/forum/showthread.php?t=1263 |
|
|
|
|
|
|
#4 |
|
Nhập môn đệ tử
Tham gia ngày: May 2009
Bài gửi: 4
: |
//================================================== ==============
Connected to \\.\COM2 at 19200 HEX: 3 hours old, INHX8M,16Fcode, total=1380 bytes. Searching for PIC ... Found:16F 886/887 WARNING: GOTO not found in first 4 words! If using a compiler, maybe you should write some directive to enable the use of bootloaders, or maybe you could fix it by adding an interrupt handler to your program. WARNING: PCLATH not fully initialised before GOTO! ... could not repair !!!, Maybe you sould use some directive in your compiler to enable the use of bootloaders WRITE OK at 13:35, time:1.360 sec Connected to \\.\COM2 at 19200 HEX: 3 hours old, INHX8M,16Fcode, total=362 bytes. Searching for PIC ... Found:16F 886/887 WARNING: GOTO not found in first 4 words! If using a compiler, maybe you should write some directive to enable the use of bootloaders, or maybe you could fix it by adding an interrupt handler to your program. WRITE OK at 13:36, time:0.437 sec //================================================== ============= Bác nào đã dùng Bootloader cho PIC6F887 đã gặp lỗi này chưa ạ, bác nào có thể chỉ giáo cho mình để sửa lỗi này không vậy. |
|
|
|
![]() |
|
|