30 Ağustos 2019 Cuma

PIC16F84A Mikrodenetleyici ile DC Motor Hız Kontrol ve Devir Yönü Değiştirme Uygulama Devresi ve Program Kodu



Yukarıdaki devrede PIC16F84A Mikrodenetleyici ile yapılan DC Motor Hız Kontrol ve Devir Yönü Değiştirme Uygulama Devresi görülmektedir.

Bu devrede Speed UP yazan butona basıldığında motor devri artarak hızlanmaktadır. Speed DOWN yazan butona basıldığında motor devri azalarak yavaşlamaktadır. Bu butonlara basarak motorun hızını istediğimiz gibi artırıp yavaşlatmak mümkündür. Motor maksimum hızına geldiğinde LED3 lambası yanmaktadır.

Direction1 ve Direction2 butonları devir yönünü değiştirmektedir. Değişen devir yönünde de Speed UP ve Speed DOWN butonları ile hız kontrolü yapılabilir. Devir yönüne göre LED1 ve LED2lambaları yanmaktadır.

PIC16F84A Mikrodenetleyici CCS C kodu

1  // DC motor speed and direction control using PIC16F84A CCS C code
2  // http://elektrikelektronikegitimi.blogspot.com
3  #include <16F84A.h>
4  #fuses HS,NOWDT,PUT,NOPROTECT
5  #use delay(clock = 8000000)
6  #use fast_io(B)
7  #use fast_io(A)
8  #use pwm(output = pin_a0, output = pin_a1, timer = 0, frequency= 500Hz, duty = 0)
9
10  unsigned int8 i = 1;
11  void main() {
12  port_b_pullups(TRUE); // Enable PORTB pull-ups
13  output_a(0); // PORTA initial state
14  set_tris_a(0); // All PORTA pins are configured as outputs
15  output_b(0); // PORTB initial state
16  set_tris_b(0x1F); // Configure RB0 to RB4 as inputs
17  pwm_off(); // Turn off all pwm outputs
18  while(TRUE) {
19  if(input(PIN_B0) == 0){ // If RB0 button pressed
20  i++; // Increment i by 1 (i = i + 1)
21  if(i > 99){
22  i = 100;
23  output_high(PIN_B7);} // RB7 LED ON
24  pwm_set_duty_percent(i * 10UL); // Duty cycle change in tenths %
25  delay_ms(100); } // Wait 100ms
26  if(input(PIN_B1) == 0){ // If RB1 button pressed
27  output_low(PIN_B7); // RB7 LED OFF
28  i--; // Decrement i by 1 (i = i - 1)
29  if(i < 1)
30  i = 1;
31  pwm_set_duty_percent(i * 10UL); // Duty cycle change in tenths %
32  delay_ms(100); } // Wait 100ms
33  if(input(PIN_B2) == 0){ // If RB2 button pressed
34  if(input(PIN_B5) == 0){
35  output_low(PIN_B6); // RB6 LED OFF
36  pwm_off(); // Turn off pwm for both outputs
37  output_a(0); // PORTA pins low
38  delay_ms(100); // Wait 100ms
39  pwm_on(PIN_A0); // Turn pwm on at RA0
40  output_high(PIN_B5); // RB5 LED ON
41  if(i > 99)
42  output_high(PIN_B7);}}
43  if(input(PIN_B3) == 0){ // If RB3 button pressed
44  if(input(PIN_B6) == 0){
45  output_low(PIN_B5); // RB5 LED OFF
46  pwm_off(); // Turn off pwm for both outputs
47  output_a(0); // PORTA pins low
48  delay_ms(100); // Wait 100ms
49  pwm_on(PIN_A1); // Turn PWM on at RA1
50  output_high(PIN_B6);
51  if(i > 99)
52  output_high(PIN_B7);}}
53  if(input(PIN_B4) == 0){ // If RB4 button pressed
54  pwm_off(); // Turn off pwm for both outputs
55  output_a(0); // PORTA pins low
56  output_b(0);} // PORTB pins low
57  }
58  }

1 yorum:

Postayla Gelen Deniz Kabuğu (Behiç Ak) Kitabının Özeti, Konusu ve Kitap Hakkında Bilgi

Kitabın Adı: Postayla Gelen Deniz Kabuğu Kitabın Yazarı:  Behiç Ak Kitap Hakkında Bilgi: Dijital dünyanın labirentlerinden çıkış mümkün mü?...