📄 main.lst
字号:
1: /*
2: The main for uC pic16f688
3: */
4: #include <htc.h>
5: #include <pic16f688.h>
6: #include "IntServ.h"
7: #include "AD.H"
8: #include "Type.h"
9:
10: //#define PMC5 RC4=1////PMC=5;/
11: //#define PMC(1) RC4=1////PMC=Z;
12: //#define PMC(0) RC4=0////PMC=0;
13:
14: #pragma inline(PMC)
15: //void PMC(unsigned char V) {if(V) {RC4=0;} else {RC4=1;}}////PMC=Z;PMC=0;
16: #pragma inline(VP)
17:
18: int VP_I,VP_U,PMC_I,PMC_U;//VP_I,VP_U: CURRENT & VOLTAGE VALUE OF PIN7 SUPPLY FOR RJ485 TERMINAL
19: //PMC_I,PMC_U: CURRENT & VOLTAGE VALUE OF PIN1&3 RETURN FROM RJ485 TERMINAL
20: unsigned int Time10ms;//10ms timer1
21:
22: extern int adc[5];
23: extern bit bShortCurrent;
24: //extern bit bSC_first;
25:
26: //ADCs adc[5]; //5 adc channels
27: void PMC(unsigned char V)
28: {
29: if(V) {RC4=0;}
30: else {RC4=1;}
31: }////PMC=Z;PMC=0;
32: void VP(unsigned char V)
33: {
34: if(V==1) {RA5=1;RC5=0;}
35: else if(V==5) {RA5=0;RC5=0;}
36: else if(V==10) {RA5=0;RC5=1;}
37: else if(!V) {RA5=1;RC5=0;}
38: }//VP=0
39:
40: void main(void)
41: {
42: char Status=0;
43: unsigned int n;
44: // bSC_first=0;
45:
46: bShortCurrent=0;
47: Time10ms=0;
48:
49: VP_I=0;
50: VP_U=0;
51: PMC_I=0;
52: PMC_U=0;
53: // ini_variable();
54: ini_chip();
55: // PMC(0);VP(5); //to test
56: PMC(Z);
57: VP(Z); //Initial state of pin1,3,7 on rj45 terminal
58: // PMC(Z);VP(10); //to test
59: n=30000;
60: while(n--){;}
61: n=30000;
62: while(n--){;}
63: //wait for 2 seconds, to test
64:
65: SWDTEN=1; //start WDT
66: // RA4=0;
67: Status=S0_0; //State machine starts from state0_0
68: while(1)
69: {
70:
71: /* Arith_AD();
72: if(VP_I)
73: {
74: PMC(Z);VP(Z);
75:
76: }*/ //to test short current
77:
78: asm("CLRWDT");//clear WDT each while
79: // PMC(Z);VP(5);Arith_AD();//VP(10);
80: /*
81: if(!pin1 && !pin2)
82: {
83: PMC(0);VP(10);//Supply 10V
84: Status=S0_0;
85: Stop_Timer1();
86: }
87: else if(!pin1 && pin2)
88: {
89: PMC(0);VP(5);//Supply 5V
90: Status=S0_0;
91: Stop_Timer1();
92: }
93: else if(pin1 && !pin2)
94: {
95: PMC(0);VP(0);//Supply 0V
96: Status=S0_0;
97: Stop_Timer1();
98:
99: }
100: else if(pin1 && pin2) //enter auto Detect
101: {
102: //switch(Status)
103: }
104: */ //auto detection section: not tested
105: switch(Status) //auto Detect state machine
106: {
107:
108: case S0_0:
109: Start_Timer1();
110: Status=S0;
111: break;
112:
113: case S0:
114:
115: PMC(V0);VP(Z);Arith_AD();//sample confitions and adc
116: if(bShortCurrent) //Adjust if short current occur
117: {
118: Status=Soff; //Enter status nerver restored
119: break;
120: }
121: if(Time10ms<=100) //S0: WAIT FOR 1S
122: {
123: //RA4=1;; ////(!PMC_I && !VP_U)
124: //VP_U=VP_U-5;
125: //if(VP_U==5)
126: if(!PMC_I && !VP_U)
127: {
128: Status=S0;
129:
130: }
131: else
132: {
133: Status=S7;
134: Stop_Timer1();
135:
136: }
137: }
138: else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -