-
Notifications
You must be signed in to change notification settings - Fork 1
/
PWM.c
47 lines (42 loc) · 1.46 KB
/
PWM.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "PWM.h"
void PWM_Init(){
INTCON = 0xA0; //HABILITA INT GLOBAL
//HABILITA A INT DO TIMER0
//TMR0IP = 1;
T0CON = 0xC1; //HABILITA TIMER0
//HABILITA TIMER0 COMO 8BIT'S
//HABILITA CONT. PELO CLOCK INTERNO
//HABILITA PRESCALER 1:4
TRISB = 0x03; //DEFINE PORT A COMO SAIDA
LATB = 0x03; //INICIA PORT A EM 1
TMR0L = freq; //CARGA INICIAL DO TIMER0
return;
}
void PWM_Execute(){
PWM_Counter++;
if(PWM_Counter == _pwm[0])
PORTB &= 0b11111011;
if(PWM_Counter == _pwm[1])
PORTB &= 0b11110111;
if(PWM_Counter == _pwm[2])
PORTB &= 0b11101111;
if(PWM_Counter == _pwm[3])
PORTB &= 0b11011111;
if(PWM_Counter == _pwm[4])
PORTB &= 0b10111111;
else if(PWM_Counter == 0)
PORTB |= 0b11111100;
else if(PWM_Counter == 256)
PORTB |= 0b11111100;
if(_pwm[0] == 0)
PORTB &= 0b11111011;
if(_pwm[1] == 0)
PORTB &= 0b11110111;
if(_pwm[2] == 0)
PORTB &= 0b11101111;
if(_pwm[3] == 0)
PORTB &= 0b11011111;
if(_pwm[4] == 0)
PORTB &= 0b10111111;
return;
}