PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Cơ bản về vi điều khiển và PIC (http://www.picvietnam.com/forum/forumdisplay.php?f=8)
-   -   Dotocdo_dongco_pic (http://www.picvietnam.com/forum/showthread.php?t=2761)

0509592 30-08-2008 12:58 AM

Dotocdo_dongco_pic
 
Chào các bác!
em muốn đo tốc độ động cơ nhưng không làm được!
nó không hiện lên gì cả!
các bác chỉ giúp em sai ở đâu???
Code:

#include <16f877a.h>
#include <def_877a.c>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD,NOWRT
#use delay(clock=8000000)
#include <lcd_lib_4bit.c>

int16 value,a;
int8 a,a1,a2,a3,a4;

#int_TIMER0  //counter0
void  TIMER0_isr(void)
{
dem++; 
set_timr0(155);
tmr0if=0;
}
#int_TIMER1  //timer1
void  TIMER1_isr(void)
{
if(tim1if==1)
{
set_timr1(15536);
intcon=0;                      //stop timer1, counter0

value=(dem*100/4)/(100*0.1*60)  //de*100/4 la so xung dem duoc o counter0
                                //100*0.1*60 la do phan giai cua encoder vaf tinh ra phut
dem=0;timer1if=0;
}
}

void main()
{
  trisc=0x00;
  setup_timer_2(T2_DIV_BY_16,255,1);//khoi dong timer2
  setup_ccp1(CCP_PWM);              // khoi dong pwm
  // setup_ccp2(CCP_PWM);

  setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
  set_timr0(155);                    //thoi gian ngat 0.2ms
  setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
  set_timr1(15536);                  //tao thoi gian ngat 100ms
  enable_interrupts(INT_TIMER0);
  enable_interrupts(INT_TIMER1);
  enable_interrupts(GLOBAL);
  delay_ms(1000);

while(1)
{
  set_pwm1_duty(1000);
  // set_pwm2_duty(700);
a=(int16)value;              //toc do dong co vong/phut
a1=a/1000;
a2=(a-a1*1000)/100;
a3=(a-a1*1000-a2*100)/10;
a4=ceil(a%10);

  lcd_init();                // hien thi toc do dong co
  LCD_PutCmd (0x80);
  lcd_putchar(a1+48);
  lcd_putchar(a2+48);
  lcd_putchar(a3+48);
  lcd_putchar(a4+48);
  delay_ms(200);
  LCD_PutCmd (0x01 );
}
}



Múi giờ GMT. Hiện tại là 02:30 AM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam