Quantcast
Channel: Microcontrollers
Viewing all articles
Browse latest Browse all 4928

Pic16f877a servo motor control by Timer0

$
0
0
Hi! I am trying for 3 days to control basic servo motor (sg90) by using Pic16f877a by Timer0 in Mplab XC8 compiler.
Code (Text):
  1.  
  2. #include <xc.h>
  3. #include <stdint.h>
  4. #include "config.h"
  5.  
  6. #define _XTAL_FREQ 6000000
  7.  
  8. uint16_t counter = 0;
  9. uint16_t on_time = 281, pwm_period_time = 3750;
  10.  
  11. void main(void) {
  12.     TRISD = 0x00;
  13.     PORTD = 0x00;
  14.    
  15.     PSA = 0;
  16.     TMR0 = 252;
  17.     T0CS = 0;
  18.     //Prescaler
  19.     PS0 = 0;
  20.     PS1 = 0;
  21.     PS2 = 0;
  22.        
  23.     TMR0IE = 1;
  24.     TMR0IF = 0;
  25.     PEIE = 1;...
Pic16f877a servo motor control by Timer0

Viewing all articles
Browse latest Browse all 4928

Trending Articles