Page 1 of 1
PIC18F4685 and Soft_UART
Posted: 28 Nov 2010 20:05
by hocavr
PIC18F4685 I use to connect to the PC via Soft_UART protocol (PIN2 (RA0) - TX, PIN3 (RA1) - RX), I write code as follows:
Code: Select all
void main(){
CMCON |= 0x07; // turn off comparators
Soft_UART_Init(&PORTA, 3, 2, 9600, 0);
while(1){
Soft_UART_Write(i);
i++;
Delay_ms(1000);
}
}
But it does not work
please, help me
Re: PIC18F4685 and Soft_UART
Posted: 29 Nov 2010 09:37
by Sobrietytest
1. Make sure the PORTA pins are set to digital.
2. Add a small delay after the Soft_UART_Init (e.g. Delay_ms(100);)
3. Check your PC connections (Rx -> Tx, Tx -> Rx, GND -> GND), the GND connection is absolutely necessary.
4. The UART communicates using ASCII characters, therefore you will not see any activity until variable 'i' has passed the control character set (i.e. i = 33). Try declaring i like this: char i = 33;, then you will see the ASCII characters being sent starting with '!'.
Re: PIC18F4685 and Soft_UART
Posted: 29 Nov 2010 15:40
by ranko.rankovic
Hello
hocavr,
Looking at your code, I see that you didn't define variable
i. So here is what I've changed and code is working just fine. I connected to RA3 RX pin and to RA2 TX pin of RS232 interface. Also take care that you didn't connect anything else to those pins.
Code: Select all
short i = 0;
void main() {
CMCON |= 0x07; // turn off comparators
Soft_UART_Init(&PORTA, 3, 2, 9600, 0);
while(1) {
Soft_UART_Write(i);
i++;
Delay_ms(1000);
}
}
I used 8MHz crystal, our Development system
EasyPIC6 and selected
Software_UART in Library Manager of our
mikroC PRO for PIC software bundle.
Best regards