![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
respected
Joined: 16 May 2006 Posts: 95
|
where is mistake? (sleep and usb)(SOLVED) |
Posted: Mon Sep 19, 2011 8:25 am |
|
|
my code is:
led is blinking. (4 sec)
but usb 1 times enumerated. Last led blink usb is not enumerated.
compiler version 4.119
thanks.
Code: |
#include <18F14K50.h>
#fuses HS,NOWDT,NOLVP,NODEBUG,CPUDIV4,NOMCLR,NOPUT,NOBROWNOUT,USBDIV1
#use delay(clock=12000000)
#define USB_CONFIG_HID_TX_SIZE 8
#define USB_CONFIG_HID_RX_SIZE 8
#include <pic18_usb.h>
#include <usb_log_hid.h>
#include <usb.c>
#define led1 PIN_C3
#define usb_sense PIN_C1
int8 ticks=0;
int8 usbstate=0;
int8 x;
int8 in_data[8];
#int_TIMER1
void timer1_isr()
{
}
void usb_debug_task(void)
{
int8 new_connected;
int8 new_enumerated;
new_connected=usb_attached();
new_enumerated=usb_enumerated();
if (new_enumerated) output_high(led1);
else output_low(led1);
}
void main(void)
{
setup_timer_1(T1_EXTERNAL| T1_DIV_BY_1 | T1_CLK_OUT);
set_timer1(0);
enable_interrupts(INT_TIMER1);
usb_init_cs();
in_data[0]=0;
while (TRUE)
{
ticks=0;
output_high(pin_c3);
delay_ms(50);
output_low(pin_c3);
if(input(usb_sense)) usbstate=1;
else usbstate=0;
switch(usbstate)
{
case 1: usb_task();
usb_debug_task();
if (usb_enumerated())
{
if (usb_kbhit(1))
{
usb_get_packet(1, in_data, 8);
x= in_data[0];
}
}
break;
case 0:do { sleep();
delay_cycles(1); //Instruction pre-fetched - NOP
clear_interrupt(INT_TIMER1);
} while(++ticks<2); //4
break;
}// switch
}//while
}//main
|
Last edited by respected on Mon Sep 19, 2011 1:48 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Mon Sep 19, 2011 8:59 am |
|
|
Use the drivers....
Code: |
#include <18F14K50.h>
#fuses HS,NOWDT,NOLVP,NODEBUG,CPUDIV4,NOMCLR,NOPUT,NOBROWNOUT,USBDIV1
#use delay(clock=12000000)
#define USB_CONFIG_HID_TX_SIZE 8
#define USB_CONFIG_HID_RX_SIZE 8
#define USB_CON_SENSE_PIN PIN_C1 //Must be done before USB.C
#include <pic18_usb.h>
#include <usb_log_hid.h>
#include <usb.c>
#define led1 PIN_C3
int8 ticks=0;
int8 x;
int8 in_data[8];
#int_TIMER1
void timer1_isr(void) {
}
void usb_debug_task(void) {
int8 new_connected;
int8 new_enumerated;
new_connected=usb_attached();
new_enumerated=usb_enumerated();
if (new_enumerated)
output_high(led1);
else
output_low(led1);
}
void main(void) {
setup_timer_1(T1_EXTERNAL| T1_DIV_BY_1 | T1_CLK_OUT);
set_timer1(0);
enable_interrupts(INT_TIMER1);
usb_init_cs();
in_data[0]=0;
while (TRUE) {
ticks=0;
output_high(pin_c3);
delay_ms(50);
output_low(pin_c3);
switch(USB_CABLE_IS_ATTACHED()) {
case TRUE:
usb_task();
usb_debug_task();
if (usb_enumerated()) {
if (usb_kbhit(1)) {
usb_get_packet(1, in_data, 8);
x= in_data[0];
}
}
break;
case FALSE:
do {
sleep();
delay_cycles(1); //Instruction pre-fetched - NOP
clear_interrupt(INT_TIMER1);
} while(++ticks<2); //4
break;
}// switch
}//while
}//main
|
Using usb_init_cs, _requires_ 'USB_CABLE_IS_ATTACHED' to be available as a macro, saying if the cable it present. It'll be defined for you automatically, if you define 'USB_CON_SENSE_PIN', but this needs to be done before you load usb.c. You have called the pin 'usb_sense' instead, and done it after loading usb.c, so the connection sense ability in the functions is basically turned off....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Mon Sep 19, 2011 10:03 am |
|
|
Code: |
#if defined(USB_CON_SENSE_PIN)
// #undef USB_CABLE_IS_ATTACHED
#define USB_CABLE_IS_ATTACHED() input(USB_CON_SENSE_PIN)
#endif
|
usb.c file will be like this? |
|
![](templates/subSilver/images/spacer.gif) |
respected
Joined: 16 May 2006 Posts: 95
|
|
Posted: Mon Sep 19, 2011 1:29 pm |
|
|
I did correction. But if the LED blinking coincides usb is working.
Also this correction file usb.h
mine connection
.....................4k7
VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
...............|
...............+---/\/\/\/\/\-----GND
................... 100k
actually connection
.....................100K
VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
...............|
...............+---/\/\/\/\/\-----GND
................... 100k |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|