brucelee2
Member level 2
Im trying to control my Velleman K8056 Relay Board using a microcontroller. The board works fine when connected to the PC using the Velleman program.
Im using a MAX232 level converter between the MCU and PC/Relay Board
Im using a MikroC USART library for my PIC18F4550. The code is below. Ive checked the data coming from the microcontroller by using the PC terminal it is correct. With the USART function i can only send one byte at a time; i have to wait for the byte to be sent before sending the next.
Im sending:
0D 01 53 31 6E (which turns on relay one of card adressed one). Sending this by the PC using a terminal makes the board work, but using the MCU i cant get it to work.
There i a delay between bytes, is this a problem?
Is it ok to send bytes one at a time with the start/stop bit every time or should there be one start/stop bit for the whole command frame?
Added after 2 hours 54 minutes:
A video of the setup
Im using a MAX232 level converter between the MCU and PC/Relay Board
Im using a MikroC USART library for my PIC18F4550. The code is below. Ive checked the data coming from the microcontroller by using the PC terminal it is correct. With the USART function i can only send one byte at a time; i have to wait for the byte to be sent before sending the next.
Im sending:
0D 01 53 31 6E (which turns on relay one of card adressed one). Sending this by the PC using a terminal makes the board work, but using the MCU i cant get it to work.
There i a delay between bytes, is this a problem?
Is it ok to send bytes one at a time with the start/stop bit every time or should there be one start/stop bit for the whole command frame?
Code:
char UART_temp;
unsigned char data_send [50];
int num = 0;
int count=0;
void ledblink()
{
PORTD=0x00;
Delay_ms(100);
PORTD=0xFF;
Delay_ms(100);
PORTD=0x00;
Delay_ms(100);
PORTD=0xFF;
}
void main() {
ADCON1=0x0F;
TRISD=0x00;
PORTD=0xFF; //LED INDICATOR ON portD
UART1_Init(2400); // Initialize UART module
Delay_ms(1000); // Wait for UART module to stabilize
data_send[0] = 0x0D;
data_send[1] = 0x01;
data_send[2] = 0x53;
data_send[3] = 0x31;
data_send[4] = 0x6E;
ledblink();
while (1) {
if((UART1_Tx_Idle() == 1) && (num<5))
{
UART1_Write(data_send[num]);
num=num+1;
}
}
}
Added after 2 hours 54 minutes:
A video of the setup