Ðề tài: PIC báo unknown
View Single Post
Old 27-10-2009, 08:34 PM   #3
vutranthelan
Đệ tử 1 túi
 
vutranthelan's Avatar
 
Tham gia ngày: Jul 2009
Bài gửi: 17
:
Trích:
Nguyên văn bởi namqn View Post
Code của bạn ra sao? Nếu bạn thiết lập chân Timer 0 là ngõ ra, và xuất logic ngược với logic của chân RB7 (chân RB7 = '1' còn chân RA4 = '0'), thì con PIC nóng lên là đúng rồi. Khả năng PIC còn sống có lẽ là thấp, do đó WinPic800 báo unknown cũng không có gì là khó hiểu.

Thân,
Em thiết lập Timer0 ở chế độ đếm. Code (sorry vì phải post code kiểu này, upload file toàn bị báo lỗi):

Code:
#include <16F877A.h>
#FUSES NOWDT                   
#FUSES HS                      
#FUSES NOPUT                   
#FUSES NOPROTECT               
#FUSES NODEBUG                  
#FUSES NOBROWNOUT              
#FUSES NOLVP                    
#FUSES NOCPD                    
#FUSES NOWRT                    
#use delay (clock=20000000) //20Mhz
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define START_VALUE_TIMER0    55  //tri khoi tao ban dau cua timer0
#define START_VALUE_TIMER1  3035 // 65536 - 3036, tao thoi gian ngat 50ms

int16 j = 0;
int16 flag_timer1;
int16 pulse;

#INT_TIMER0 // ngat timer0 tang bien len 1
void TIMER0_int()
{
      pulse++;
}
#INT_TIMER1 // ngat timer0 tang bien len 1
void timer1_int() // moi lan timer1 tran la 0.05s
{
   if (j == 4){ // chu ki lay mau 0.05 * 4 = 0.2s
      j = 0;
      pulse = pulse*256 + get_timer0();
      flag_timer1 = 1;
      printf(" \t%ld",pulse); // truyen toc do xung dong co 1 ve may tinh
   }
   else
      j++;
}

void init_timer()
{
   setup_timer_0(RTCC_EXT_H_TO_L);
   set_timer0(START_VALUE_TIMER0);
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_4); // moi lan tran timer1 la (65536-3036)*4*4/20000000=50ms
   set_timer1(START_VALUE_TIMER1);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER0); 
}

void main()
{
    init_timer();  
     while(true)
    {
     if (flag_timer1 ==1){
      flag_timer1 = 0;
      output_high(PIN_B7);
      delay_us(1200);
      output_low(PIN_B7);
      delay_ms(18);
     }
     }
   }
}

thay đổi nội dung bởi: namqn, 27-10-2009 lúc 09:54 PM. Lý do: định dạng code
vutranthelan vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn