andi_
Newbie level 6
There are already tons of threads similar to this, I'm sorry for posting a new one. But what I seek is advice, should I use methods such as IC2 or I can just program my own method. What I did for my project is using programming instead of IC2, by directly connecting both PIC pins and create a simple pulse by enabling and disabling a pin, and take readings during pulse is high. My question is, is this a good practice, or should really use IC2 to connect them?
p/s: Usart is unavailabe since I use it to connect to my PC.
Example of my code
p/s: Usart is unavailabe since I use it to connect to my PC.
Example of my code
Code:
void main() {
...
...
while (1) {
cache = PORTB & 0x0f;
if (RW == 0 && EN == 1 && data_in == 0) {
/* Write */
while (EN != 0)
continue;
while (data_in < 4) {
while (EN != 1)
continue;
cache |= DT << data_in;
while (EN != 0)
continue;
data_in++;
}
data_in = 0;
}
if (RW == 1 && data_in == 0) {
/* Read */
TRISA = TRISA_R; //set to read config
// Generate 1 pulse
EN = 1;
EN = 0;
//Start sending data
while (data_in < 4) {
EN = 1;
DT = PORTB >> (4 + data_in);
EN = 0;
data_in++;
}
data_in = 0;
TRISA = TRISA_W; //reset to write config
}
...
...
}