Rev Author Line No. Line
3666 kaklik 1 #include "main.h"
2  
3 #define LED1 PIN_A1
4 #define LED2 PIN_A2
5  
6 int8 lsb, msb;
7 signed int16 pwm;
8  
9 #int_SSP
10 void SSP_isr(void)
11 {
12 int8 state;
13  
14 state = i2c_isr_state();
15 if (state == 0)
16 {
17 i2c_read();
18 }
19  
20 if (state == 1)
21 {
22 lsb = i2c_read();
23 }
24  
25 if (state == 2)
26 {
27 output_low(LED2);
28 msb = i2c_read();
29 pwm = MAKE16(msb,lsb);
30 if (pwm==0)
31 {
32 set_pwm1_duty(0);
33 set_pwm2_duty(0);
34 }
35 if (pwm>0)
36 {
37 set_pwm1_duty(pwm);
38 set_pwm2_duty(0);
39 }
40 if (pwm<0)
41 {
42 set_pwm1_duty(0);
43 set_pwm2_duty(abs(pwm));
44 }
45 }
46 }
47  
48  
49 void main()
50 {
51 setup_oscillator(OSC_8MHZ|OSC_INTRC);
52 setup_adc_ports(NO_ANALOGS|VSS_VDD);
53 setup_adc(ADC_CLOCK_DIV_2);
54 setup_psp(PSP_DISABLED);
55 //!!! setup_spi(SPI_SS_DISABLED);
56 setup_wdt(WDT_OFF);
57 setup_timer_0(RTCC_INTERNAL);
58 setup_timer_1(T1_DISABLED);
59 setup_timer_2(T2_DIV_BY_16,255,1);
60 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
61 // setup_ccp1(CCP_PWM_FULL_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
62 setup_ccp1(CCP_PWM);
63 setup_ccp2(CCP_PWM);
64 // set_pwm1_duty(512);
65 // set_pwm2_duty(512);
66 set_pwm1_duty(0);
67 set_pwm2_duty(0);
68 setup_comparator(NC_NC_NC_NC);
69 setup_vref(FALSE);
70 enable_interrupts(INT_SSP);
71 enable_interrupts(GLOBAL);
72  
73 printf("Cvak.\r\n");
74 pwm=0;
75 //Example blinking LED program
76 while(true){
77 printf("Hmm...%Ld\r\n",pwm);
78 output_low(LED1);
79 delay_ms(500);
80 output_high(LED1);
81 output_high(LED2);
82 delay_ms(500);
83 }
84  
85 }