I'm trying to build a PIC based circuit to control a device (optical filter wheel) via a RS-232 connection. A description of the device can be found here: http://www.flicamera.com/pdf/HSFW_RevB_print.pdf. In short, if I want to select filter #1 I just send character "1", filter #1 character "2" and so on. If I connect the device to the computer and use the MikroElektronika Usart Terminal, I can control the device easily by sending the ascii values.
I have built a circuit identical to the one shown in the MikroC compiler help file in the Uart Library page, except for the PIC model - I use a PIC18F4620 (internal clock running at 8MHz) and a led connected to pin RA0. Here is the code:
Code: Select all
void main() {
char uart_rd, i;
OSCCON = 0b01110000;
ADCON1 = 0x0F; // PORTA digital
CMCON = 0x07; // disable comparators
TRISA = 0x00; // PORTA: output
TRISB = 0xFF; // PORTB: input
TRISC = 0x00;
TRISD = 0x00;
// This loop is used just to make sure the PIC is ok (a led is on pin RA0)
for ( i = 0; i < 5; i++ ){
Delay_1sec();
PORTA.F0 = 1;
Delay_1sec();
PORTA.F0 = 0;
}
UART1_Init(9600);
Delay_ms(100); // Wait for UART module to stabilize
for ( i = 0; i < 6; i++ ){
UART1_Write(i + '0');
UART1_Write(0x0D);
Delay_1sec();
}
}
Do you have any idea of the difference of the signal sent from the computer (using the mE usart terminal) and the one sent from my circuit? I noticed that when I compile the program, I get this warning: "Generated baud rate is 9615 bps (error=0.16 percent)". Could this be the problem?If you need further precisions, it will be a pleasure to inform you.
Thanks in advance and have a nice day,
Marc