-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpic.c
140 lines (114 loc) · 3.22 KB
/
pic.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*! \file pic.c
\brief Initialization functions
*/
#include "config.h"
#include "pic.h"
#include "serial.h"
#include "interrupts.h"
#include "timer.h"
_STATUS_ Status;
_ABORT Abort;
char STDERR;
void PIN0_ON(void) { PIN0 = 1; }
void PIN1_ON(void) { PIN1 = 1; }
void PIN2_ON(void) { PIN2 = 1; }
void PIN3_ON(void) { PIN3 = 1; }
void PIN4_ON(void) { PIN4 = 1; }
void PIN5_ON(void) { PIN5 = 1; }
void PIN6_ON(void) { PIN6 = 1; }
void PIN0_OFF(void) { PIN0 = 0; }
void PIN1_OFF(void) { PIN1 = 0; }
void PIN2_OFF(void) { PIN2 = 0; }
void PIN3_OFF(void) { PIN3 = 0; }
void PIN4_OFF(void) { PIN4 = 0; }
void PIN5_OFF(void) { PIN5 = 0; T1CONbits.TMR1ON = 0; }
void PIN6_OFF(void) { PIN6 = 0; }
void Initialize_PIC()
{
int t;
Interrupts_Init();
STDERR = -1; /// Set Standard Error an undefined serial port;
memset(&Status,0,sizeof(Status)); // Clear all the values
memset(&Abort,0,sizeof(Abort));
TRISB=0x00; // Set Direction of B
TRISC=0x00; // Set Direction of C
PORTC=0x00; // Set all port C to low
PORTB=0x00; // Setall port B to low
Delay1KTCYx(10);
}
/////////////////////////////////////////////////
/// Get the value of a bit in a char
/////////////////////////////////////////////////
char BIT_GET(unsigned char *data, char i)
{
return (*data >> i) & 0x01;
}
/////////////////////////////////////////////////
/// Set the value of a bit in a char
/////////////////////////////////////////////////
char BIT_SET(unsigned char *data, char i)
{
*data |= 1 << i;
}
/////////////////////////////////////////////////
/// Clear a bit in a char
/////////////////////////////////////////////////
char BIT_CLEAR(unsigned char *data, char i)
{
*data &= ~(1 << i);
}
void Log_Error(FARROM *string)
{
char t=0;
char c=0;
if(STDERR > -1) {
do {
c = string[t];
Serial_PutChar(STDERR,c);
t++;
} while(c!=0);
Serial_Send_Full_TX_Buffer(STDERR);
}
}
void CheckReset(char port)
{
////////////////////////////////////////////////////////////
// If the PIC had a reset find out what caused it
////////////////////////////////////////////////////////////
if(isBOR()) {
sprintf(szText,(FARROM*)"Brown Out=Yes\r\n");
Serial_Send_String(port,szText,SEND_NOW);
} else {
sprintf(szText,(FARROM*)"Brown Out=No \r\n");
Serial_Send_String(port,szText,SEND_NOW);
}
if(isLVD()) {
sprintf(szText,(FARROM*)"LVD=Yes\r\n");
Serial_Send_String(port,szText,SEND_NOW);
} else {
sprintf(szText,(FARROM*)"LVD=No \r\n");
Serial_Send_String(port,szText,SEND_NOW);
}
if(isMCLR()) {
sprintf(szText,(FARROM*)"MCLR=Yes\r\n");
Serial_Send_String(port,szText,SEND_NOW);
} else {
sprintf(szText,(FARROM*)"MCLR=No \r\n");
Serial_Send_String(port,szText,SEND_NOW);
}
if(isPOR()) {
sprintf(szText,(FARROM*)"POR=Yes\r\n");
Serial_Send_String(port,szText,SEND_NOW);
} else {
sprintf(szText,(FARROM*)"POR=No \r\n");
Serial_Send_String(port,szText,SEND_NOW);
}
if(isWDTTO()) {
sprintf(szText,(FARROM*)"WDT=Yes\r\n");
Serial_Send_String(port,szText,SEND_NOW);
} else {
sprintf(szText,(FARROM*)"WDT=No \r\n");
Serial_Send_String(port,szText,SEND_NOW);
}
Delay10KTCYx(255);
}