hii..
My PIC18 has problem to receive a character from PC. I'm using Visual Basic 6 in PC to give command to PIC to read current temperature. I'm also using zigbee to transmit and receive data between PC and PIC. The coding in VB6 is to send a character 'a' when button command is clicked. So my PIC18 should receive the character and execute the next line of instruction where to measure temperature. How to read the character in PIC and proceed the next line using soft_uart? I'm using mikroC compiler version 8.2.0.0.
I've tried this coding but the PIC seems like not receive the character..
Soft_UART_Read(inputr);
if (inputr == 'a')
{
measure temperature
}
I'm not sure on this coding..Plz help me
do {
data = Soft_Uart_Read(rec); // Receive data
} while (!*rec);
Problem to receive character in PIC18
Re: Problem to receive character in PIC18
Hi;
have a look to mC pro library;
hope this helps;
have a look to mC pro library;
Code: Select all
char i, error, byte_read; // Auxiliary variables
void main(){
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
TRISB = 0x00; // Set PORTB as output (error signalization)
PORTB = 0; // No error
error = Soft_UART_Init(&PORTC, 7, 6, 14400, 0); // Initialize Soft UART at 14400 bps
if (error > 0) {
PORTB = error; // Signalize Init error
while(1) ; // Stop program
}
Delay_ms(100);
for (i = 'z'; i >= 'A'; i--) { // Send bytes from 'z' downto 'A'
Soft_UART_Write(i);
Delay_ms(100);
}
while(1) { // Endless loop
byte_read = Soft_UART_Read(&error); // Read byte, then test error flag
if (error) // If error was detected
PORTB = error; // signal it on PORTB
else
Soft_UART_Write(byte_read); // If error was not detected, return byte read
}
}
Re: Problem to receive character in PIC18
Tq MR2010 for your reply..but my problem is i want to receive the character 'a' and proceed with the next line..Actually my program starts when i click the command button in VB6. When i click command button, it automatically send out character 'aaaa' non-stop. So can i assume to receive 'a' in PIC? I don't know how to program in PIC. I've tried the coding below for PIC using mikroC to turn on LED just for testing but it doesn't work. Where should i include to receive the 'a' in the coding? Plz help me..
do
{
data = Soft_Uart_Read(rec);
} while (!*rec);
if (data)
{
PORTB = 0x80;
}
do
{
data = Soft_Uart_Read(rec);
} while (!*rec);
if (data)
{
PORTB = 0x80;
}