PIC18F4685 and Soft_UART

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
hocavr
Posts: 28
Joined: 22 Nov 2010 21:34

PIC18F4685 and Soft_UART

#1 Post by hocavr » 28 Nov 2010 20:05

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

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

Re: PIC18F4685 and Soft_UART

#2 Post by Sobrietytest » 29 Nov 2010 09:37

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 '!'.

User avatar
ranko.rankovic
Posts: 433
Joined: 11 Jun 2010 09:22

Re: PIC18F4685 and Soft_UART

#3 Post by ranko.rankovic » 29 Nov 2010 15:40

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
Ranko Rankovic
mikroElektronika [Support Department]

Post Reply

Return to “mikroC PRO for PIC General”