realistic
Üye
- Katılım
- 20 May 2008
- Mesajlar
- 13
- Puanları
- 1
- Yaş
- 39
Merhaba arkadaşlar 877nin iki donanımsal çıkışını kullanarak aynı anda iki pwm dalgası almayı bi türlü başaramadım Yardımcı olursanız çok sevinirim
#include <16f877.h>
#include <stdlib.h>
#include <math.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=4915200)
#use rs232(baud=9600, xmit=pin_c6, rcv=pin_c7, parity = N, stop =1)
#use fast_io(c)
unsigned int16 servo1=0;
unsigned int16 servo2=0;
unsigned int8 servo1_duty;
unsigned int8 servo2_duty;
unsigned int8 aci;
int8 kontrol;
int aci_hesapla(int16 x)
{
float temp2;
printf("\r\nfonksiyonun icine giren deger :%Ld",x);
temp2=floor(76.5 + (x* ( 76.5 / 180 ) ) );
printf("\n\rtemp2 :%f",temp2);
aci=(unsigned int8)temp2;
printf("\r\n int sonuc :%u",aci);
return aci;
}
#int_rda
void seri_haberlesme_kesmesi()
{
char pozisyon[5];
disable_interrupts(int_rda);
switch (kontrol)
{
case 1:
gets(pozisyon);
servo1=atol(pozisyon);
printf("\n\rbirinci servonun acisi %Ld",servo1);
kontrol=2;
case 2:
gets(pozisyon);
servo2=atol(pozisyon);
printf("\n\rikinci servonun acisi %Ld",servo2);
kontrol=1;
}
if (kontrol=1)
{
servo1_duty=aci_hesapla(servo1);
servo2_duty=aci_hesapla(servo2);
printf("\r\nduty cycle degeri 1 :%u",servo1_duty);
printf("\r\nduty cycle degeri 2 :%u",servo2_duty);
set_pwm1_duty(servo1_duty);
set_pwm2_duty(servo2_duty);
}
}
void main()
{
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,255,1);
enable_interrupts(GLOBAL);
set_tris_c(0x80);
kontrol=1;
set_pwm1_duty(0);
set_pwm2_duty(0);
while(1)
{
enable_interrupts(int_rda);
}
}
#include <16f877.h>
#include <stdlib.h>
#include <math.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=4915200)
#use rs232(baud=9600, xmit=pin_c6, rcv=pin_c7, parity = N, stop =1)
#use fast_io(c)
unsigned int16 servo1=0;
unsigned int16 servo2=0;
unsigned int8 servo1_duty;
unsigned int8 servo2_duty;
unsigned int8 aci;
int8 kontrol;
int aci_hesapla(int16 x)
{
float temp2;
printf("\r\nfonksiyonun icine giren deger :%Ld",x);
temp2=floor(76.5 + (x* ( 76.5 / 180 ) ) );
printf("\n\rtemp2 :%f",temp2);
aci=(unsigned int8)temp2;
printf("\r\n int sonuc :%u",aci);
return aci;
}
#int_rda
void seri_haberlesme_kesmesi()
{
char pozisyon[5];
disable_interrupts(int_rda);
switch (kontrol)
{
case 1:
gets(pozisyon);
servo1=atol(pozisyon);
printf("\n\rbirinci servonun acisi %Ld",servo1);
kontrol=2;
case 2:
gets(pozisyon);
servo2=atol(pozisyon);
printf("\n\rikinci servonun acisi %Ld",servo2);
kontrol=1;
}
if (kontrol=1)
{
servo1_duty=aci_hesapla(servo1);
servo2_duty=aci_hesapla(servo2);
printf("\r\nduty cycle degeri 1 :%u",servo1_duty);
printf("\r\nduty cycle degeri 2 :%u",servo2_duty);
set_pwm1_duty(servo1_duty);
set_pwm2_duty(servo2_duty);
}
}
void main()
{
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,255,1);
enable_interrupts(GLOBAL);
set_tris_c(0x80);
kontrol=1;
set_pwm1_duty(0);
set_pwm2_duty(0);
while(1)
{
enable_interrupts(int_rda);
}
}