G:\HPamp-2\program\protector.X\main.c |
1 /**
2 Generated Main Source File
3
4 Company:
5 Microchip Technology Inc.
6
7 File Name:
8 main.c
9
10 Summary:
11 This is the main file generated using MPLAB(c) Code Configurator
12
13 Description:
14 This header file provides implementations for driver APIs for all modules
15 selected in the GUI.
16 Generation Information :
17 Product Revision : MPLAB(c) Code Configurator - 3.15.0
18 Device : PIC16F1823
19 Driver Version : 2.00
20 The generated drivers are tested against the following:
21 Compiler : XC8 1.35
22 MPLAB : MPLAB X 3.20
23 */
24
25 /*
26 (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
27 software and any derivatives exclusively with Microchip products.
28
29 THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
30 EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
31 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
32 PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
33 WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
34
35 IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
36 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
37 WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
38 BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
39 FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
40 ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
41 THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
42
43 MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
44 TERMS.
45 */
46
47 #include "mcc_generated_files/mcc.h"
48
49 /*
50 Main application
51 */
52
53 // User Define
54 #define U_MINPSV 0x290 //Minimam Power supply voltage 10V
55 #define U_MAXOFFSETV 0x290 //Max Output offset +0.2V
56 #define U_MINOFFSETV 0x270 //Min Output offset -0.2V
57
58 unsigned int Pflg ;
59 unsigned int offsetv ;
60 unsigned int ttt ;
61
62 void main(void)
63 {
64 // initialize the device
65 SYSTEM_Initialize();
66
67 // Cut Output
68 RC4 = 0x0; //Cut Output
69 RC5 = 0x1; //Power LED ON
70
71 // enable all interrupts
72 ei() ;
73
74 // Wait 5 sec for startup
75 __delay_ms(5000) ;
76
77 while (1)
78 {
79 // Add your application code
80 Pflg = 0;
81 //sense Power supply voltage
82 ttt = ADC_GetConversion( channel_AN2 ) ;
83 if( ttt < U_MINPSV ) Pflg = 1;
84 // if( ADC_GetConversion( channel_AN2 ) < U_MINPSV ) Pflg = 1;
85
86 //sense Lout- offset
87 offsetv = ADC_GetConversion( channel_AN4 ) ;
88 if( offsetv > U_MAXOFFSETV ) Pflg = 1;
89 if( offsetv < U_MINOFFSETV ) Pflg = 1;
90
91 //sense Lout+ offset
92 offsetv = ADC_GetConversion( channel_AN5 ) ;
93 if( offsetv > U_MAXOFFSETV ) Pflg = 1;
94 if( offsetv < U_MINOFFSETV ) Pflg = 1;
95
96 //sense Rout- offset
97 offsetv = ADC_GetConversion( channel_AN6 ) ;
98 if( offsetv > U_MAXOFFSETV ) Pflg = 1;
99 if( offsetv < U_MINOFFSETV ) Pflg = 1;
100
101 //sense Rout+ offset
102 offsetv = ADC_GetConversion( channel_AN7 ) ;
103 if( offsetv > U_MAXOFFSETV ) Pflg = 1;
104 if( offsetv < U_MINOFFSETV ) Pflg = 1;
105
106 if( Pflg == 1 ) {
107 RC4 = 0x0 ; //Cut Output
108 __delay_ms( 2000 ) ;
109 }
110 else {
111 RC4 = 0x1 ; //Connect Output
112 RC5 = 0x1 ; //Power LED ON
113 __delay_ms( 100 ) ;
114 }
115 }
116 }
117 /**
118 End of File
119 */