tarjina
Junior Member level 3
Hello guys,
I'm new here. Please help me out. I'm trying to connect PIC18F452 to android phone via bluetooth HC-05 module (can work as master and slave). I'm trying to send the data but it's not working. I'm coding in mikroC and UART library. Does anyone here can help me please???
Here's my code:
char uart_rd;
void main() {
TRISA=0X00;
TRISD=0X00;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while(1){
if (UART1_Data_Ready()) { // If data is received,
PORTD=0XFF;
uart_rd = UART1_Read(); // read the received data,
if(uart_rd=='1'){
PORTA=0X05;
delay_ms(5000);
PORTD=0X0F;
delay_ms(1000);
}
else if(uart_rd=='2'){
PORTA=0X0C;
delay_ms(5000);
PORTD=0X0F;
delay_ms(1000);
}
else if(uart_rd=='3'){
PORTA=0X24;
delay_ms(5000);
PORTD=0X0F;
delay_ms(1000);
}
else if(uart_rd=='4'){
PORTA=0X06;
delay_ms(5000);
PORTD=0X0F;
delay_ms(1000);
}
}
else
{PORTA=0X00;}
}
}
I'm new here. Please help me out. I'm trying to connect PIC18F452 to android phone via bluetooth HC-05 module (can work as master and slave). I'm trying to send the data but it's not working. I'm coding in mikroC and UART library. Does anyone here can help me please???
Here's my code:
char uart_rd;
void main() {
TRISA=0X00;
TRISD=0X00;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
while(1){
if (UART1_Data_Ready()) { // If data is received,
PORTD=0XFF;
uart_rd = UART1_Read(); // read the received data,
if(uart_rd=='1'){
PORTA=0X05;
delay_ms(5000);
PORTD=0X0F;
delay_ms(1000);
}
else if(uart_rd=='2'){
PORTA=0X0C;
delay_ms(5000);
PORTD=0X0F;
delay_ms(1000);
}
else if(uart_rd=='3'){
PORTA=0X24;
delay_ms(5000);
PORTD=0X0F;
delay_ms(1000);
}
else if(uart_rd=='4'){
PORTA=0X06;
delay_ms(5000);
PORTD=0X0F;
delay_ms(1000);
}
}
else
{PORTA=0X00;}
}
}