Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Home work?I have to implement a software UART in PIC24HJ128GP310A ......any one please give me the related code either in C or in Assembly language
Let's see. A search for your topic yields thousands of hits. I'm assuming one has code. Or perhaps you could add the word code to your search terms. And get thousands of hits.
The question is, will you be able to understand the code well enough to use it?
What is it that you really need? I suspect it is more than code even though that's what you think now...
I'll explain what I actually need...I have to transfer a data from PIC24H to a external device through UART. The UART in the PIC is already used. So the option available is, by using the I/O port I have to transfer the file. for that it is necessary to implement a software UART. can you help me to do this?
MPLAB XC16Okay! What compiler are you using???...
not transmit only.. it has to receive acknowledgement signal back.. baud rate is 9600bps..So it's transmit-only, right? And you do realize that there are 2 UART modules on your PIC and both are already used, correct?
What baud rate do you need? At what speed your PIC is running?
not transmit only.. it has to receive acknowledgement signal back.. baud rate is 9600bps..
void SendUART() {
static int state = 0;
static char mask = 0;
static char data = 0;
switch (state) {
case 0: if (has_byte_to_send()) { // replace the call according to your needs; must be quick
OUTPUT = 0; // start bit
data = get_byte_to_send(); // replace the call according to your needs
state = 1;
mask = 1;
}
break;
case 1: OUTPUT = (data & mask) != 0; // data bit
mask <<= 1;
if (mask == 0) {
state = 2;
}
break;
case 2: OUTPUT = 1; // stop bit
state = 0;
break;
}
}
can you please give me the code of "sw_uart.h" defined in the code you given.Software uart can work here, but you'll have to sit and wait for the acknowledge.... Software uarts can have interrupts but the take up different I/O resources..
These are for the Pic18 but just need adjusting to suit Pic24... They are from the Plib library bundled with XC8
thank you so much....Yep!
Remember you must write the delay routines... One for Full bi and one for half bit!!
thank you...Create a timer interrupt which happens once every 104us. Make it relatively high priority.
During startup, intitalize the output pin for digital output and drive it high
From inside the interrupt call this:
C:void SendUART() { static int state = 0; static char mask = 0; static char data = 0; switch (state) { case 0: if (has_byte_to_send()) { // replace the call according to your needs; must be quick OUTPUT = 0; // start bit data = get_byte_to_send(); // replace the call according to your needs state = 1; mask = 1; } break; case 1: OUTPUT = (data & mask) != 0; // data bit mask <<= 1; if (mask == 0) { state = 2; } break; case 2: OUTPUT = 1; // stop bit state = 0; break; } }