am using pic18f2550 (full code in attachment)
successful read data to controll pwm brightness
but i need to (write) data from mcu ( send from mikrocontroller ) but not working
i try this code but not working
when portb fo pressed counter will increase and send value from mcu this is all
if (portb.f0==0){ counter++; }
sprintf(write_buffer,"senddata=") ;
{
strcpy(process, strtok(write_buffer, "="));
strcpy(process, strtok(0, "s"));
counter=atoi(process);
while(!HID_Write(&write_buffer,64)) ;
}
_____________________________________________
_______________________________________
_______________________________________
code : file available also
_________________________________________________________________________
char read_buffer[64] absolute 0x500;
char write_buffer[64] absolute 0x540;
char process[30];
char dato=0;
char incvalue=0;
char cuenta=0;
char kk;
char state1;
int counter=0;
int i = 0;
void interrupt()
{
usb_interrupt_proc();
}
void main() {
OSCCON = 0b01001110;
INTCON.GIE = 1;
INTCON.TMR0IE = 1;
T0CON = 0x82;
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==0){ counter++; }
sprintf(write_buffer,"senddata=") ;
{
strcpy(process, strtok(write_buffer, "="));
strcpy(process, strtok(0, "s"));
counter=atoi(process);
while(!HID_Write(&write_buffer,64)) ;
}
kk = HID_Read();
if (kk != 0) {
cuenta++;
if (cuenta>=30)
{
cuenta=0;
}
if ( strstr(read_buffer,"M1pwm=" ))
{
strcpy(process, strtok(read_buffer, "="));
strcpy(process, strtok(0, "M"));
dato=atoi(process);
PWM1_Set_Duty(dato);
}
memset(read_buffer,0,30);
cuenta=0;
}
}
}
successful read data to controll pwm brightness
but i need to (write) data from mcu ( send from mikrocontroller ) but not working
i try this code but not working
when portb fo pressed counter will increase and send value from mcu this is all
if (portb.f0==0){ counter++; }
sprintf(write_buffer,"senddata=") ;
{
strcpy(process, strtok(write_buffer, "="));
strcpy(process, strtok(0, "s"));
counter=atoi(process);
while(!HID_Write(&write_buffer,64)) ;
}
_____________________________________________
_______________________________________
_______________________________________
code : file available also
_________________________________________________________________________
char read_buffer[64] absolute 0x500;
char write_buffer[64] absolute 0x540;
char process[30];
char dato=0;
char incvalue=0;
char cuenta=0;
char kk;
char state1;
int counter=0;
int i = 0;
void interrupt()
{
usb_interrupt_proc();
}
void main() {
OSCCON = 0b01001110;
INTCON.GIE = 1;
INTCON.TMR0IE = 1;
T0CON = 0x82;
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==0){ counter++; }
sprintf(write_buffer,"senddata=") ;
{
strcpy(process, strtok(write_buffer, "="));
strcpy(process, strtok(0, "s"));
counter=atoi(process);
while(!HID_Write(&write_buffer,64)) ;
}
kk = HID_Read();
if (kk != 0) {
cuenta++;
if (cuenta>=30)
{
cuenta=0;
}
if ( strstr(read_buffer,"M1pwm=" ))
{
strcpy(process, strtok(read_buffer, "="));
strcpy(process, strtok(0, "M"));
dato=atoi(process);
PWM1_Set_Duty(dato);
}
memset(read_buffer,0,30);
cuenta=0;
}
}
}
Attachments
-
162.2 KB Views: 1