View Single Post
Old 03-03-2011, 08:44 PM   #19
stupid11
Đệ tử 6 túi
 
stupid11's Avatar
 
Tham gia ngày: Dec 2009
Nơi Cư Ngụ: TP.Hồ Chí Minh
Bài gửi: 133
:
Send a message via Yahoo to stupid11
doan chuong trinh dieu khien toc do dong co & hien thi toc do/giay len 2 led 7 doan

#include<16f877a.h>
#device 16F877*16ADC=8
#fuses nowdt,noprotect,nolvp,xt,put
#use delay(clock=4000000)
#use fast_io(d)
#use fast_io(c)
#use fast_io(a)
#use fast_io(e)
#byte porte=0x9
#byte portd=0x8
#byte portc=0x7
#byte porta=0x5
#byte option=0x81//option_reg//
#byte tmr0=0x1
#bit e1=porte.1
#bit e0=porte.0
#bit p0=option.0
#bit p1=option.1
#bit p2=option.2
#bit p3=option.3
#bit p4=option.4
#bit p5=option.5
int x,i,chuc,dv,y;
void xuatxung();
void docADC();
void main()
{
int a[10]={192,249,164,176,153,146,130,248,128,144};
set_tris_d(0);
set_tris_c(0);
set_tris_a(0b010001);
set_tris_e(0);
tmr0=0;
portd=0;
portc=0;
porta=0;
while(1)
{
p3=0;
p2=0;p1=1;p0=0;//chia tan 1:8//encoder duc 8 lo tren 1 vong
docADC();
x=read_ADC();
xuatxung();
p4=p5=1; // cho TMR0 hoat dong//
for(i=0;i<50;i++)
{
e1=1;e0=0;
portd=a[chuc];
delay_ms(10);
e0=1;e1=0;
portd=a[dv];
delay_ms(10);
}
y=tmr0;
chuc=y/10;
dv=y%10;
tmr0=0;// cai lai gia tri cho TMR0//
}}
void docADC()
{
setup_ADC(ADC_clock_internal);
setup_ADC_ports(AN0);
set_ADC_channel(0);
delay_us(100);
}
void xuatxung()
{
setup_ccp1(ccp_PWM);
set_pwm1_duty(x);
setup_timer_2(t2_div_by_16,255,1);
}




Su dung bo ADC de dieu chinh do rong xung (PWM)
File Kèm Theo
File Type: rar Do toc do DC.rar (50.4 KB, 175 lần tải)
stupid11 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn