hi
i have this code ( mikroc with pic18f2550 ) usb
how can i add delimiter to it
mean if data coming end with 255 /255 /255 then mikro will do the code
for example my code to control duty cycle (( M1pwm= )) any value after = it will change duty cycle
i need to add 255/255/255
it will be like that
M1pwm= 44 255 255 255
if i receive data without delimiter 255/ 255/ 255
mcu will not response
how to make it
i have this code ( mikroc with pic18f2550 ) usb
how can i add delimiter to it
mean if data coming end with 255 /255 /255 then mikro will do the code
for example my code to control duty cycle (( M1pwm= )) any value after = it will change duty cycle
i need to add 255/255/255
it will be like that
M1pwm= 44 255 255 255
if i receive data without delimiter 255/ 255/ 255
mcu will not response
how to make it
Code:
char read_buffer[64] absolute 0x500;
char write_buffer[64] absolute 0x540;
char procesa[30];
char dato=0;
char cuenta=0;
char kk;
void interrupt()
{
usb_interrupt_proc();
}
void main() {
trisb.f0=1;
HID_Enable(&read_buffer,&write_buffer);
PWM1_Init(3000);
PWM1_Set_Duty(0);
PWM1_Start();
read_buffer[cuenta]=dato;
while(1)
{
if (portb.f0==1){delay_ms(300);
sprintf(write_buffer, "start");
while(!HID_Write(&write_buffer,64)) ;
}
if (portb.f1==1){delay_ms(300);
sprintf(write_buffer, "stop");
while(!HID_Write(&write_buffer,64)) ;
}
kk = HID_Read();
if (kk != 0) {
cuenta++;
if (cuenta>=30)
{
cuenta=0;
}
if ( strstr(read_buffer,"START" )) { PWM1_Set_Duty(44); }
else if ( strstr(read_buffer,"STOP" )) { PWM1_Set_Duty(0);}
else if ( strstr(read_buffer,"M1pwm=" ))
{
strcpy(procesa, strtok(read_buffer, "="));
strcpy(procesa, strtok(0, "M"));
dato=atoi(procesa);
PWM1_Set_Duty(dato);
}
memset(read_buffer,0,30);
cuenta=0;
}
}
}