-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled.c
More file actions
44 lines (39 loc) · 954 Bytes
/
Copy pathled.c
File metadata and controls
44 lines (39 loc) · 954 Bytes
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
#include <p18cxxx.h>
#include "led.h"
void LED_Init()
{
/********************SPI Settings For LED controller********************/
TRISBbits.TRISB1 = 0; //SCK output
TRISCbits.TRISC7 = 0; //SDO output
TRISCbits.TRISC6 = 0; //LAT output
LED_LAT = 0;
SSPSTAT = 0;
SSPSTATbits.CKE = 0;
SSPCON1 = 0b00100010; //SPI Master mode enable, clock is FOSC/64
/********************PWM Setting for 8 bit********************/
T2CON = 0;
T2CONbits.TMR2ON = 1;
PR2 = 0xFF;
CCPR2L = 0x16;
CCP2CON = 0x0C; //PWM Mode ON
SetLed((unsigned int)0x0000);
}
void SetLed(unsigned int Leds)
{
static unsigned char dummy;
SSPBUF = Leds & 0b11111111;
while(!SSPSTATbits.BF);
dummy = SSPBUF;
dummy = SSPBUF;
SSPBUF = (Leds >> 8) & 0b11111111;
while(!SSPSTATbits.BF);
dummy = SSPBUF;
dummy = SSPBUF;
LED_LAT = 1;
Delay10KTCYx(1);
LED_LAT = 0;
}
void SetDutyCycle(unsigned char Duty)
{
CCPR2L = 255 - Duty;
}