-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.c
73 lines (66 loc) · 1.81 KB
/
io.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
/*
* File: io.c
* Author: Avell
*
* Created on 4 de Agosto de 2020, 21:39
*/
#include "bits.h"
#include "io.h"
#include <pic18f4520.h>
//PORTB e PORTD apenas para demonstrar o funcionamento
void digitalWrite(int pin, int value){
//porta
if(pin <8){
if (value){ bitSet(PORTA,pin);}
else{ bitClr(PORTA,pin);}
}else if(pin<16){
pin -=8;
if (value){ bitSet(PORTB,pin);}
else{ bitClr(PORTB,pin);}
}else if(pin<24){
pin -=16;
if (value){ bitSet(PORTC,pin);}
else{ bitClr(PORTC,pin);}
}else if(pin<32){
pin -=24;
if (value){ bitSet(PORTD,pin);}
else{ bitClr(PORTD,pin);}
}else if(pin<40){
pin -=32;
if (value){ bitSet(PORTE,pin);}
else{ bitClr(PORTE,pin);}
}
}
int digitalRead(int pin){
if(pin <8){
return bitTst(PORTA,pin);
}else if(pin<16){
return bitSet(PORTB,pin-8);
}else if(pin<24){
return bitSet(PORTC,pin-16);
}else if(pin<32){
return bitSet(PORTD,pin-24);
}else if(pin<40){
return bitSet(PORTE,pin-32);
}
return -1;
}
void pinMode(int pin, int type) {
//porta
if(pin <8){
if (type){ bitSet(TRISA,pin);}
else{ bitClr(TRISA,pin);}
}else if(pin<16){
if (type){ bitSet(TRISB,pin-8);}
else{ bitClr(TRISB,pin-8);}
}else if(pin<24){
if (type){ bitSet(TRISC,pin-16);}
else{ bitClr(TRISC,pin-16);}
}else if(pin<32){
if (type){ bitSet(TRISD,pin-24);}
else{ bitClr(TRISD,pin-24);}
}else if(pin<40){
if (type){ bitSet(TRISE,pin-32);}
else{ bitClr(TRISE,pin-32);}
}
}