View Single Post
Old 21-03-2011, 10:58 AM   #3
tudonghoa_bk
Nhập môn đệ tử
 
Tham gia ngày: Mar 2011
Bài gửi: 4
:
#include <16f877a.h>
#fuses HS,PUT,NOWDT
#device adc=10
#use delay (clock = 20000000)
#use rs232(baud = 9600 , parity = n , xmit = pin_c6 , rcv = pin_c7 , bits = 9)
#include <LCD_4BIT_fix.c>

float e,e1,a,b,i,x;
int16 value,j , vttb ;

int8 c,d , tg;

int8 chuyendoi(int8 gt) ;
#int_timer0
void ngat()
{
i=get_timer1();
set_timer1(0x00);

e=x-i;
a = e - e1;
b = (e + e1) + b;
e1 = e;

value = (int16)(e + b/30);
c = (int8)(!(bit_test (value,15)));

value = value * c ;
d = (int8)((bit_test(value,11))|(bit_test(value,12))|
(bit_test(value,13))|(bit_test(value,14)));

value = value * (!d) + 1023 * d;

set_pwm1_duty(value);


}

void main ()
{
value=0;
i=0;
e=0;
e1=0;
a=0;
vttb=0;
b=0;


setup_adc(ADC_CLOCK_INTERNAL );
setup_adc_ports( AN0);
set_ADC_channel( 0 );
delay_us(10);


lcd_init(); //ham khoi tao LCD
lcd_setposition(line_1);
printf(lcd_putchar,"SET : RPM");

lcd_setposition(line_2);
printf(lcd_putchar,"SPEED : 0 RPM");


output_e (0xf2);

enable_interrupts (INT_TIMER0);
enable_interrupts (GLOBAL);



while(true)
{

j= (Read_ADC())*17/10; // so vong / phut
x=(j*0.032768);
lcd_setposition(line_1);
printf(lcd_putchar,"SET : RPM");
LCD_PutCmd ( 0x88 );
printf(lcd_putchar,"%ld",j);
vttb=(int16)(i*30.51757812); // vantoc trung binh

lcd_setposition(line_2);
printf(lcd_putchar,"SPEED : RPM");
LCD_PutCmd ( 0xc8 );
printf(lcd_putchar,"%ld",vttb);
delay_ms (200);

}
}

mình bận quá nên ít hôm mình hướng dẫn code này cho bạn, thông cảm nha, code này cũng hơi nhứt đầu.
tudonghoa_bk vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn