|
|
View previous topic :: View next topic |
Author |
Message |
JohnLook Guest
|
Problem with USB |
Posted: Thu Nov 16, 2006 4:23 pm |
|
|
Hi, I'm having a problem when I connect the board with PIC18F4550 on USB port. I would like to know why when I connect the cable there isn't no power and windows shows a message of error indicating that the device wasn't recognized. |
|
|
TARUN GUPTA
Joined: 20 Nov 2006 Posts: 2 Location: mumbai
|
first time i have written code for USB |
Posted: Tue Nov 21, 2006 12:15 am |
|
|
hi, i have written time code for USB in 16c745(OTP) using example from ccs c compiler , but i m not 100% sure it works, and i have programmer which burn code in this 16c745/765 family chip. I cant programme the 18f4550 due to probem of programmer....so help me ,how i can write code in ccs c compiler _________________ hi.....
i wud join this for getting knowledge and for discusssion |
|
|
TARUN GUPTA
Joined: 20 Nov 2006 Posts: 2 Location: mumbai
|
first time i have written code for USB |
Posted: Tue Nov 21, 2006 12:17 am |
|
|
hi, i have written time code for USB in 16c745(OTP) using example from ccs c compiler , but i m not 100% sure it works, and i have programmer which burn code in this 16c745/765 family chip. I cant programme the 18f4550 due to probem of programmer....so help me ,how i can write code in ccs c compiler Code: |
this programm for testing ...just switch i connected to microcontroller abd transmitting particular data through usb to computer.......
#define USB_PIC16C745 1 //set to 1 to use a PIC16c765 USB Peripheral
//set to 0 to use a National USBN960x peripheral
#include <16C745.h>
#device *=16
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=24000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#DEFINE LED_4 PIN_B1 //SENSOR STATUS
#define SENSOR PIN_B2 // IR SENSOR...
#DEFINE LED_3 PIN_B3 // led connected on pin b3 for initial status & button2
#DEFINE LED_2 PIN_B4 // led connected on pin b4 for initial status & button1
#DEFINE LED_1 PIN_B5 // led connected on pin b5
#DEFINE BUTTON1 PIN_B6 // switch connected to pin a4
#DEFINE BUTTON2 PIN_B7 // switch connected to pin a5
#byte port_b=6
//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE TRUE
//Set this to FALSE if you only want to test enumeration. Some USB test programs,
//such as USBCHECK, crash if you are trying to test enumeration and the device
//starts sending data once configured.
#DEFINE USB_RUN_WHEN_CONFIGURED TRUE
//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
#define USB_EP1_TX_ENABLE 1 //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 2 //if you change this, be sure to change the hid descriptor
//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
#define USB_EP1_RX_ENABLE 1 //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 2 //if you change this, be sure to change the hid descriptor
#if USB_PIC16C745
#include <pic_usb.h> //Microchip PIC16C765 hardware layer for usb.c
#else
#include <usbn960x.c> //National 960x hardware layer for usb.c
#endif
#include <usb.c> //handles usb setup tokens and get descriptor reports
//////////////////////////// MAIN PROGRAM //////////////////////////////////////
void main() {
int8 out_data[USB_EP1_TX_SIZE];
int8 in_data[USB_EP1_RX_SIZE];
int8 out1;
output_b(0xff);
set_tris_b(0x23);
#ifdef __PCH__
printf("\r\n\r\nPCH: v");
printf(__PCH__);
#else
printf("\r\n\r\nPCM: v");
printf(__PCM__);
#endif
// setup_adc(ADC_CLOCK_INTERNAL);
// setup_adc_ports(RA0_RA1_RA3_ANALOG);
// set_adc_channel(1);
usb_init(); // usb initialise function
#if !(USB_PIC16C745)
printf("\r\nUSBN: 0x%X\r\n", usbn_get_version());
bit_clear(port_b, LED_1);
bit_clear(port_b, LED_2);
bit_clear(port_b, LED_3);
delay_ms(1000);
bit_set(port_b, LED_1);
bit_set(port_b, LED_2);
#else
printf("\r\n");
#ENDIF
printf("\r\n\r\nWaiting for enumeration...");
while (TRUE) {
usb_wait_for_enumeration();
printf("\r\n\r\n***Enumerated***\r\n");
while(usb_enumerated()) {
#IF USB_RUN_WHEN_CONFIGURED
if (usb_kbhit(1)) {
usb_gets(1, in_data, USB_EP1_RX_SIZE);
printf("\r\n--> Received 2 bytes: 0x%X 0x%X",in_data[0],in_data[1]);
if (in_data[0]) {bit_clear(port_b, LED_1);} else {bit_set(port_b, LED_1);}
if (in_data[1]) {bit_clear(port_b, LED_2);} else {bit_set(port_b, LED_2);}
}
if (PIN_B2==1){
out1 = 1 ;
bit_set(port_b, LED_4);
delay_ms(5);
}
else
{
out1 = 0 ;
bit_clear(port_b, LED_4);
delay_ms(5);
}
out_data[0] = out1;
if (BUTTON1==0 && BUTTON2==0)
{
out_data[1]=2;
bit_clear(port_b, LED_2);
bit_clear(port_b, LED_3);
delay_ms(5);
}
if (BUTTON1==0 && BUTTON2==1)
{
out_data[1]=3;
bit_clear(port_b, LED_2);
bit_set(port_b, LED_3);
delay_ms(5);
}
if (BUTTON1==1 && BUTTON2==0)
{
out_data[1]=4;
bit_set(port_b, LED_2);
bit_clear(port_b, LED_3);
delay_ms(5);
}
if (BUTTON1==1 && BUTTON2==1)
{
out_data[1]=5;
bit_set(port_b, LED_2);
bit_set(port_b, LED_3);
delay_ms(5);
}
if (usb_put_packet(1, out_data, USB_EP1_TX_SIZE, TOGGLE)) {
printf("\r\n<-- Sending 2 bytes: 0x%X 0x%X", out_data[0], out_data[1]);
}
delay_ms(500);
#ENDIF
}
printf("\r\n\r\nDevice Un-configured.r\n");
}
}
|
_________________ hi.....
i wud join this for getting knowledge and for discusssion |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 21, 2006 12:57 am |
|
|
Quote: |
bit_clear(port_b, LED_1);
bit_clear(port_b, LED_2);
bit_clear(port_b, LED_3);
bit_set(port_b, LED_1);
bit_set(port_b, LED_2);
|
The statements above are incorrect and will not generate any code.
Change them to this:
Code: |
output_low(LED_1);
output_low(LED_2);
output_low(LED_3);
output_high(LED_1);
output_high(LED_2); |
There are at least 10 more lines in your program that are similar,
and they should be fixed in the same way.
Quote: | if (BUTTON1==0 && BUTTON2==0) |
The statement above is incorrect. Change it to this:
Code: | if (input(BUTTON1)==0 && input(BUTTON2)==0) |
There are many similar lines in your program. They must all be
fixed in the same way. |
|
|
|
|
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
|