Aguijón Software Libraries  1.0
Documentation for the included Libraries
 All Files Functions Variables Typedefs Enumerations Enumerator Macros
outputs.c
Go to the documentation of this file.
1 /********************************************************************
2  FileName: outputs.c
3  Dependencies: See INCLUDES section
4  Hardware: Aguijón rev3.0
5  Complier: Microchip XC16(for PIC24), C30(for PIC24)
6  Company: Vinagrón Digital
7 
8  Software License Agreement:
9 
10  blah blah blah
11 
12 ********************************************************************
13  File Description:
14  Includes output control functions.
15 
16 
17  Change History:
18  Rev Description
19  ---- -----------------------------------------
20  1.0 Initial release
21 ********************************************************************/
22 
23 #include <p24FJ128GB106.h>
24 #include "GenericTypeDefs.h" //for BOOL
25 
26 #define USE_AND_OR
27 #define ocmp_v2_3
28 #include "outcompare.h"
29 #include "GenericTypeDefs.h"
30 #include "definitions.h"
31 #include "outputs.h"
32 
33 
34 #define PWM_CONV_FACTOR 8
35 
36 
48 void LEDport(unsigned char lednum, char state)
49 {
50  switch(lednum)
51  {
52  case 1:
53  if(state){ LED1 = 1;} //lo apaga
54  else { LED1 = 0;} //lo prende
55  break;
56  case 2:
57  if(state){ LED2 = 1;}
58  else { LED2 = 0;}
59  break;
60  case 3:
61  if(state){ LED3 = 1;}
62  else { LED3 = 0;}
63  break;
64  case 4:
65  if(state){ LED4 = 1;}
66  else { LED4 = 0;}
67  break;
68  case 5:
69  if(state){ LED5 = 1;}
70  else { LED5 = 0;}
71  break;
72  case 6:
73  if(state){ LED6 = 1;}
74  else { LED6 = 0;}
75  break;
76  case 7:
77  if(state){ LED7 = 1;}
78  else { LED7 = 0;}
79  break;
80  case 8:
81  if(state){ LED8 = 1;}
82  else { LED8 = 0;}
83  break;
84  }
85 }
86 
98 void RLYport(unsigned char rlynum, char state)
99 {
100  switch(rlynum)
101  {
102  case 1:
103  if(state){ RLY1 = 0;} //lo prende
104  else { RLY1 = 1;} //lo apaga
105  break;
106  case 2:
107  if(state){ RLY2 = 0;}
108  else { RLY2 = 1;}
109  break;
110  case 3:
111  if(state){ RLY3 = 0;}
112  else { RLY3 = 1;}
113  break;
114  case 4:
115  if(state){ RLY4 = 0;}
116  else { RLY4 = 1;}
117  break;
118  }
119 }
120 
132 void OCport(unsigned char ocnum, char state)
133 {
134  switch(ocnum)
135  {
136  case 1:
137  if(state){ OC1 = 0;} //lo prende
138  else { OC1 = 1;} //lo apaga
139  break;
140  case 2:
141  if(state){ OC2 = 0;}
142  else { OC2 = 1;}
143  break;
144  case 3:
145  if(state){ OC3 = 0;}
146  else { OC3 = 1;}
147  break;
148  case 4:
149  if(state){ OC4 = 0;}
150  else { OC4 = 1;}
151  break;
152  }
153 }
154 
155 
167 void buzzer(unsigned int period_uS, unsigned int duty_div)
168 {
169  UINT32 duty = 0;
170  unsigned int fixed_period = 0;
171 
172  if(period_uS < 8000){ //rango del registro 65535
173  fixed_period = (period_uS * PWM_CONV_FACTOR);
174  }else{
175  fixed_period = 1000;
176  }
177 
178  CloseOC2();
179  if(duty_div && fixed_period){
180  duty = fixed_period;
181  duty *= duty_div;
182  duty /= 100;
183  OpenOC2(OC_SYSCLK_SRC | OC_CONTINUE_PULSE, OC_SYNC_TRIG_IN_CURR_OC, fixed_period, duty);
184  }
185 }
186 
198 void backlight(unsigned int value)
199 {
200  CloseOC1();
201  if(value){
202  OpenOC1(OC_SYSCLK_SRC | OC_CONTINUE_PULSE, OC_SYNC_TRIG_IN_CURR_OC, 3200, value);
203  }
204 }
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217