Basic, cdc, hid and Vega Multi(Basic,Advance)

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello
There is example1(from 10) from basic code, in whille i will send here code for CDC and HID USB comunication. (For fun) . You can see what can you do with 1 led , 1 button and USB comunication. For USB communication related source you have to have USB add on and Bascom licence.
Used dewelop board is VEGA MINI, with picture and scheme added. All axamples have downloadable worked file. You only need bascom(Free or licenced) and FLIP programmer. That examples are used in school and on VEGA MINI board. It is efective and tested way to develop your ovn softvare.
http://www.mcselec.com/index.php... - link to BASCOM AVR compiler, you can DL demo FREE version to free compile up to 2kByte long bin programm

'---------------------------------------- 
'Vega Mini - Develop board 
'Test button on HWB(PE.2) and led diode (PE.3) 
'---------------------------------------- 
$regfile = "usb1287.dat" 
$crystal = 16000000 
Porte = &B00000000 
Ddre = &B00001000 
Do 
If Pine.2 = 0 Then 
Reset Porte.3 
Waitms 50 
Set Porte.3 
Waitms 50 
Else 
Reset Porte.3 
Waitms 100 
Set Porte.3 
Waitms 100 
End If 
Loop

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Wed. Dec 29, 2010 - 01:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting program. After you press the button , led light for 800mS and than bootloadar is starting. So you don't need to press Reset+HWD, HWD sequence. Be careful, that Bootloader my not work with interupt routine, so befor jump to bootloader, must disable all interrupts.

'---------------------------------------- 
'Mini Vega 
'Leawe program with jump on bootloader when press Button 
'---------------------------------------- 
$regfile = "usb1287.dat" 
$crystal = 16000000 
Porte = &B00000000 : Ddre = &B00001000 
Do 
If Pine.2 = 0 Then 
Set Porte.3 
Waitms 800 
Reset Porte.3 
Goto &H1F000 
Else 
Reset Porte.3 
Waitms 50 
Set Porte.3 
Waitms 50 
End If 
Loop

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Mon. Dec 27, 2010 - 06:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All exsamples work with free edition Bascom
That Example is interesting, because led blink faster after you release button, for as many time as buton was pressed!

'---------------------------------------- 
'Mini Vega 
'Uporaba prekinitev, časovnika 
'---------------------------------------- 
$regfile = "usb1287.dat" 
$crystal = 16000000 
Porte = &B00000000 : Ddre = &B00001000 
Config Timer0 = Timer , Prescale = 1024 
On Timer0 Prekinitev 
Enable Interrupts 
Enable Timer0 
Dim Tipka As Byte : Tipka = 0 

Do 
If Tipka = 0 Then 
Reset Porte.3 
Waitms 100 
Set Porte.3 
Waitms 100 
Else 
Reset Porte.3 
Waitms 40 
Set Porte.3 
Waitms 40 
End If 
Loop 

Prekinitev: 
If Pine.2 = 0 Then 
If Tipka < 255 Then Tipka = Tipka + 1 
Else 
If Tipka > 0 Then Tipka = Tipka - 1 
End If 
Return

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Mon. Dec 27, 2010 - 01:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Time delay. Your press sequence seeing on led after eeg 4,2 sec.

'---------------------------------------- 
'Mini Vega 
'Use of Interrupts and timer
'---------------------------------------- 
$regfile = "usb1287.dat" 
$crystal = 16000000 
Porte = &B00000000 : Ddre = &B00001000 
Config Timer0 = Timer , Prescale = 1024 
On Timer0 Prekinitev 
Enable Interrupts 
Enable Timer0 
Dim Vrsta(256) As Byte : Dim I As Byte 
For I = 0 To 255 : Vrsta(i) = 0 : Next I : I = 0 
Dim Tipka As Byte : Tipka = 0 

Do 
Loop 

Prekinitev: 
If Vrsta(i) = 0 Then 
Reset Porte.3 
Else 
Set Porte.3 
End If 
If Pine.2 = 0 Then 
Vrsta(i) = 1 
Else 
Vrsta(i) = 0 
End If 
I = I + 1 
Return

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Mon. Dec 27, 2010 - 02:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
'----------------------------------------
'Mini Vega
'Uporaba prekinitev, časovnika
'----------------------------------------
$regfile = "usb1287.dat"
$crystal = 16000000
Porte = &B00000000 : Ddre = &B00001000
Config Timer0 = Timer , Prescale = 1024
On Timer0 Prekinitev
Enable Interrupts
Enable Timer0
Dim I As Byte : I = 0 : Dim V As Byte
'Dim Tipka As Byte : Tipka = 0

Do
Loop

Prekinitev:
V = Lookup(i , Vrsta )
If V = 1 Then
  Reset Porte.3
Else
  Set Porte.3
End If
'If Pine.2 = 0 Then
'Else                                                        'Tikpa ni pritisnjena
'End If
I = I + 1
Return

Vrsta:
Data 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1
Data 1 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 0
Data 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1
Data 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
Data 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Mon. Dec 27, 2010 - 05:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is a little complicated PWM with use off interrupt source timer2. Timer 2 have two compare interrupt source, one is use for set led on, other is used for set led on. Now with press button you change set off point, and leds PWM rate. Nice for many aplication.

'----------------------------------------
'Vega Mini
'Uporaba prekinitev, èasovnika
'----------------------------------------
$regfile = "usb1287.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 24
Porte = &B00000000                                          'Port E na 0
Ddre = &B00001000                                           'Port E vsi vhod razen PE3 je izhod
Config Watchdog = 2048 : Start Watchdog
Tccr2a = &B00000010 : Tccr2b = &B00000101
Ocr2a = 249 : On Oc2a Oc2a : Enable Oc2a                    'Frekvenca 16000000/128/(249+1), T=2mS
Ocr2b = 49 : On Oc2b Oc2b : Enable Oc2b                     'T=2mS*(49+1)/(249+1)=400uS
Enable Interrupts

Do
  Reset Watchdog                                            'Resetiraj nadzorni stevec
If Pine.2 = 0 Then                                          'Tipka pritisnjena
  Ocr2b = 149                                               'T=2mS*(149+1)/(249+1)=1.2mS
Else                                                        'Tikpa ni pritisnjena
  Ocr2b = 49                                                'T=2mS*(49+1)/(249+1)=400uS
End If                                                      'Vrni se na start
Loop

Oc2a:
  Set Porte.3
Return

Oc2b:
  Reset Porte.3
Return

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Mon. Dec 27, 2010 - 05:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The same work with use build in PWM
There is 3 more basic example, then I show you how to comunicate thru USB. There will be two main aplication class cdc(virtual com port) and hid (Human interface device). There will be two hid aplication interest keyboard and comunication with c#. With this acnowlage you can start write your aplication. For USB aplication you need licence Bascom and USB add on.

Sorry for teaching, but I am a teacher:), and a big avr fun too!!

'----------------------------------------
'Vega Mini
'PWM(Pulse width modulation)
'----------------------------------------
$regfile = "usb1287.dat"
$crystal = 16000000
Porte = &B00000000                      'Port E na 0
Ddre = &B00001000                       'Port E vsi vhod razen PE3 je izhod
Config Watchdog = 2048 : Start Watchdog
Tccr0a = &B10000011 : Tccr0b = &B00000011       'Fast PWM na PB7(A)
Portb = &B00000000 : Ddrb = &B11100000  'F=16000000/64/256= 976,5625Hz
Ocr0a = 63                              'PWM=(63+1)/256=1/4
                                        'PWM na Port B.7
Do
  Reset Watchdog                        'Pobozaj psa
If Pine.2 = 0 Then                      'Tipka pritisnjena
  Ocr0a = 127                           'PWM=(127+1)/256=1/2
  Set Porte.3                           'Led ne sveti
Else                                    'Tikpa ni pritisnjena
  Ocr0a = 63                            'PWM=(63+1)/256=1/4
  Reset Porte.3                         'Led ne sveti
End If                                  'Vrni se na start
Loop

For look PWM signal you need oscilloscope. VEGA MULTI is one of the many.

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Happy new year to all :D
Clock output is generated with devided crystal frequency.
Output clock is on PB5. With 16MHz crystal can generate output from mHz to up to 8MHz.
That clock is generated with hardwere so main program is not strain.
Main program betwen do/loop, change output clock frequency when you press PE2 button.
After we have 2 more so call basic example witch include all you need for fun programming. After that we are gooing on cdc and hid comunication. All together open us a field off unlimited application. Mybe you need kcnovlage to connect standard I2C or 1Wire senzors and some displays and that is almost all. HID comunications will be between c#(2010) and Bascom. That all is school examples that is in use for years, and is most usable way to write own application, tested.

'----------------------------------------
'Vega Mini
'Clock out
'----------------------------------------
$regfile = "usb1287.dat"
$crystal = 16000000
Porte = &B00000000                      'Port E na 0
Ddre = &B00001000                       'Port E vsi vhod razen PE3 je izhod
Config Watchdog = 2048 : Start Watchdog
Portb = &B00000000 : Ddrb = &B00100000  'CLK output
Tccr1a = &B01000000 : Tccr1b = &B00001011 : Ocr1a = 500
'F=16000000/2/64/500=250Hz
Do
  Reset Watchdog                        'Pobozaj psa
If Pine.2 = 0 Then                      'Tipka pritisnjena
  Ocr1a = 249                           'F=16000000/2/64/(1+249)=500Hz
  Set Porte.3                           'Led ne sveti
Else                                    'Tikpa ni pritisnjena
  Ocr1a = 499                           'F=16000000/2/64/(1+499)=250Hz
  Reset Porte.3                         'Led ne sveti
End If                                  'Vrni se na start
Loop

To wiew clock output and frequency count you can use VEGA MULTI or similar instrument.
http://suhel.homeip.net/projects... - link to program
It is easy , cheap and very useful USB multi instrument.

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Wed. Dec 29, 2010 - 07:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok - so you're obviously coming on here and writing a bunch of stuff to entice us to go to your website.

So I take the bait and go there.

Lets keep in mind you are writing these things on an ENGLISH-language board.

But lo and behold, your website is in some "furrin" language!!!

Huh????

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, I will change language on my web site to english, I am working on that toooooo long, I know that.

Nineth example is how to configre timer as counter with input on port.
That is useful for eeg frequency counter and many other application.

That example configure Timer 3 as counter with input on PC3.
We use button on PE2 to change PC3. Timer 3 count that change.
Other section monitor Timer 3 when it reach 4
Than softver reset of Timer 3 and led state switch done.

'----------------------------------------
'Vega Mini
'Digital counter
'----------------------------------------
$regfile = "usb1287.dat"
$crystal = 16000000
Porte = &B00000000                      'Port E on 0
Ddre = &B00001000                       'Port E all but PE3 is output
Config Watchdog = 2048 : Start Watchdog
Tccr3a = &B00000000 : Tccr3b = &B10000111       'Timer3    as counter
Ucsr1b = &B00000000                  
Portc = &B00000000                      'Port C all on 0
Ddrc = &B00001000                       'Port C all but PE3 is output

Do
  Reset Watchdog                    
If Tcnt3 > 4 Then
  Porte.3 = Not Pine.3
  Tcnt3 = 0
End If
If Pine.2 = 0 Then                      'Button pressed
  Set Portc.3                           
Else                                    'Button not pressed
  Reset Portc.3                     
End If                                  
Loop

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If buuton on PE2 is pressed then
led on PE3 blinking with constant frequency.
If button on PE2 not pressed then
led on PE3 blinking with frequency dependet on voltge on CH1(8 bit value).
We make voltage to frequency converter.

We finish "Basic example", now we can go on USB comunication.

'----------------------------------------
'Vega Mini
'ADC , Voltage to frequencq converter
'----------------------------------------
$regfile = "usb1287.dat"
$crystal = 16000000
Porte = &B00000000
Ddre = &B00001000
Config Watchdog = 2048 : Start Watchdog
Admux = &B01100000 : Adcsra = &B10010011 : Adcsrb = &B10000000 : Didr0 = &B00000000       'ADC
Dim Uvhodna As Byte
Do
Reset Watchdog
Uvhodna = Adch
Adcsra = Adcsra Or &B01000000                               'ADC converter start on Ch1
If Pine.2 = 0 Then                                       
  Waitms 100
  Set Porte.3                                               'Led on
  Waitms 100
  Reset Porte.3                                             'Led off
Else                                                        
  Waitms Uvhodna
  Set Porte.3                                               'Led on
  Waitms Uvhodna
  Reset Porte.3                                             'Led off
End If                                                      
Loop

It is good to have wave generator and oscilloscope to see what happend on ports. VEGA MULTI is one off the solution:)
http://www.youtube.com/watch?v=t... - youtube movie of VegaMulti

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Mon. Jan 3, 2011 - 02:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello and happy new year 2011
Here is example in USB HID classe comunication.
That working example need licence BASCOM and USB add on

That example is keyboard. Just plug in and computer will recognize keyboard. Program "type" "hwd tipka" that mean hwd button, when we press button PE2

Hid drivers are in all OS. That is main advantage. If you try to comunicate on old way true cdc(virtual com port) you must finding signed drivers first.

Key board is off course one way comunication. In wille i will show you how to comunicate in boath direction. You will need c# compiler(Visual studio 2010).

'----------------------------------------
'Mini Vega
'Vaja3
'----------------------------------------
$regfile = "usb1287.dat"
$crystal = 16000000                                         'crystal used
$baud = 19200                                               ' baud rate


$hwstack = 64
$swstack = 64
$framesize = 64

Const Mdbg = 0                                              ' add print to see what is happening
Const Chiddevice = 1                                        'this is a HID device

Config Clockdiv = 1                                         'clock division is 1 so we get 8 Mhz
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Print "USB test"


'User specific declarations
Declare Sub Usb_user_endpoint_init                          'since no param is passed in the atmel code the param is removed
Declare Sub Kbd_test_hit()
Declare Sub Kbd_task()

Const Usb_remote_wakeup = 0
Const Usb_config_attributes_reserved = &H80
Const Usb_config_buspowered = Usb_config_attributes_reserved
Const Usb_config_selfpowered = Usb_config_attributes_reserved Or &H40
Const Usb_config_remotewakeup = Usb_config_attributes_reserved Or &H20

Const Nb_interface = 1
Const Conf_nb = 1
Const Conf_index = 0
Const Conf_attributes = Usb_config_buspowered + Usb_config_remotewakeup
Const Max_power = 50                                        ' 100 mA

Const Interface_nb_mouse = 0
Const Alternate_mouse = 0
Const Nb_endpoint_mouse = 1
Const Interface_class_mouse = 3                             '  HID Class
Const Interface_sub_class_mouse = 1                         '  Sub Class is Mouse
Const Interface_protocol_mouse = 2                          '  Mouse
Const Interface_index_mouse = 0

Const Ep_control_length = 32
Const User_conf_size = 34                                   ' total user size
Const Size_of_report = 59                                   ' HID report size
Const Vendor_id = &H16D0                                    ' vendor ID
Const Product_id = &H2000                                   ' product ID
Const Release_number = &H1000                               ' product release
Const Device_class = 0
Const Device_sub_class = 0
Const Nb_endpoints = 2                                      ' number of endpoints in the application including control endpoint


Const Ep_kbd_in = 1                                         ' Number of the mouse interrupt IN endpoint

Const Endpoint_nb_1 = Ep_kbd_in Or &H80
Const Ep_attributes_1 = 3                                   ' BULK = 0x02, INTERUPT = 0x03
Const Ep_in_length_1 = 8
Const Ep_size_1 = Ep_in_length_1
Const Ep_interval_1 = 2                                     'Interrupt polling interval from host

Config Usb = Device , Language = &H0409 , Manufact = "MCS" , Product = "MCSUSB162" , Serial = "MC000"


Dim Usb_kbd_state As Byte , Usb_key As Byte , Usb_data_to_send As Byte
Dim Key_hit As Bit , Transmit_no_key As Bit

Config Pine.2 = Input : Porte.2 = 1                         ' Tipka HWD

Print "init usb task"
Usb_task_init
Do
  Usb_task
  Kbd_task
  'call your other code here
Loop

Sub Kbd_task()
    Uenum = Ep_kbd_in
    If Ueintx.txini = 1 Then                                ' Is_usb_read_control_enabled ?
       Key_hit = 0
    End If
    If Key_hit = 0 And Usb_configuration_nb <> 0 Then
     Select Case Usb_kbd_state
       Case 0:                                              ' if we are not in the middle of sending data
                         If Pine.2 = 0 Then                 'Tipka HWD pritisnjena
                            Waitms 500
                            Usb_kbd_state = 1
                            Restore Keys
                            Usb_data_to_send = 11
                         End If
       Case 1:                                              ' we need to send data
                     If Usb_data_to_send <> 0 Then
                        If Key_hit = 0 And Transmit_no_key = 0 Then
                           Read Usb_key                     ' read data
                           Decr Usb_data_to_send
                           Key_hit = 1
                        End If
                     Else
                        Usb_kbd_state = 0
                     End If
     End Select
      Bitwait Ueintx.txini , Set
      If Key_hit = 1 Then                                   'wait for the data
      Transmit_no_key = 1
      Uenum = Ep_kbd_in
      Uedatx = Hid_modifier_none                            '  Byte0: Modifier use this to send shift,ctrl and alt keys
      Uedatx = 0                                            '  Byte1: Reserved
      Uedatx = Usb_key                                      '  Byte2: Keycode 0
      Uedatx = 0                                            '  Byte2: Keycode 1
      Uedatx = 0                                            '  Byte2: Keycode 2
      Uedatx = 0                                            '  Byte2: Keycode 3
      Uedatx = 0                                            '  Byte2: Keycode 4
      Uedatx = 0                                            '  Byte2: Keycode 5
      Usb_ack_in_ready
      Exit Sub
    End If
    If Transmit_no_key = 1 Then                             ' if this flag was set
      Key_hit = 1                                           'make it one so we can send the next key after we are done sending 0
      Transmit_no_key = 0
      Uenum = Ep_kbd_in
      Uedatx = 0
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Uedatx = 0                                            ' Usb write byte
      Usb_ack_in_ready
    End If
  End If
End Sub
'Preglej PS2-HID.pdf
Keys:
Data &H0B , &H1A , &H07 , &H2C , &H17 , &H0C , &H03 , &H13 , &H0E , &H04 , &H28 ,

'USER function
Sub Usb_user_endpoint_init()
   Call Usb_configure_endpoint(ep_kbd_in , Type_interrupt , Direction_in , Size_8 , One_bank , Nyet_enabled)
End Sub

Function Usb_user_read_request(type As Byte , Request As Byte)as Byte
  #if Mdbg
    Print "USB_USER_READ_REQ"
  #endif
  Usb_string_type = Uedatx                                  ' Usb read byte
  Usb_descriptor_type = Uedatx                              ' Usb read byte
  Usb_user_read_request = 0
  Select Case Request
     Case Get_descriptor:
        Select Case Usb_descriptor_type
           Case Report : Call Hid_get_report()
                         Usb_user_read_request = 1
           Case Hid : Call Hid_get_hid_descriptor()
                      Usb_user_read_request = 1
           Case Else
              Usb_user_read_request = 0
        End Select
    Case Set_configuration:
        Select Case Usb_descriptor_type
         Case Set_report : Call Hid_set_report()
                Usb_user_read_request = 1
         Case Else
               Usb_user_read_request = 0
        End Select
   Case Get_interface:
        '//      usb_hid_set_idle();
      Call Usb_hid_get_interface()
      Usb_user_read_request = 1
   Case Else
     Usb_user_read_request = 0
 End Select
End Function


'usb_init_device.
'This function initializes the USB device controller and
'configures the Default Control Endpoint.
Sub Usb_init_device()
   #if Usbhost
      Usb_select_device
   #endif
  #if _chip = 70 Or _chip = 71                              'if usb1287 or usb646
   If Usbsta.id = 1 Then                                    'is it an USB device?
   #endif
      Uenum = Ep_control                                    ' select USB endpoint
      If Ueconx.epen = 0 Then                               ' usb endpoint not enabled yet
         Call Usb_configure_endpoint(ep_control , Type_control , Direction_out , Size_32 , One_bank , Nyet_disabled)
      End If
  #if _chip = 70 Or _chip = 71                              'if usb1287 or usb646
     End If
 #endif
End Sub




Usb_dev_desc:
Data 18 , Device_descriptor                                 ' size and device_descriptor
Data 0 , 2                                                  ' Usb_write_word_enum_struc(USB_SPECIFICATION)
Data Device_class , Device_sub_class                        ' DEVICE_CLASS  and  DEVICE_SUB_CLASS
Data 0 , Ep_control_length                                  ' device protol and ep_control_length
Data Vendor_id%                                             ' Usb_write_word_enum_struc(VENDOR_ID)
Data Product_id%                                            ' Usb_write_word_enum_struc(PRODUCT_ID)
Data Release_number%                                        ' Usb_write_word_enum_struc(RELEASE_NUMBER)
Data Man_index , Prod_index                                 ' MAN_INDEX and  PROD_INDEX
Data Sn_index , Nb_configuration                            ' SN_INDEX     NB_CONFIGURATION


Usb_conf_desc:
Data 9 , Configuration_descriptor                           ' length   , CONFIGURATION descriptor type
Data User_conf_size%                                        ' total length of data returned
Data Nb_interface , Conf_nb                                 '  number of interfaces for this conf. ,  value for SetConfiguration resquest
Data Conf_index , Conf_attributes                           ' index of string descriptor  , Configuration characteristics
Data Max_power                                              ' maximum power consumption

Data 9 , Interface_descriptor                               ' size of this descriptor ,INTERFACE descriptor
Data Interface_nb_mouse , Alternate_mouse                   ' Number of interface  , value to select alternate setting
Data Nb_endpoint_mouse , Interface_class_mouse              ' Number of EP except EP 0  ,Class code assigned by the USB
Data Interface_sub_class_mouse , Interface_protocol_mouse   ' Sub-class code assigned by the USB ,Protocol code assigned by the USB
Data Interface_index_mouse                                  ' Index of string descriptor

Data 9 , Hid_descriptor                                     ' Size of this descriptor  ,  HID descriptor type
Data &H01 , &H10 , Hid_country_code                         ' Binay Coded Decimal Spec. release   , Hardware target country
Data Hid_class_desc_nb , Hid_descriptor_type                ' number of HID class descriptors to follow , Report descriptor type
Data Size_of_report%                                        ' total length of report descriptor

Data 7 , Endpoint_descriptor                                ' Size Of This Descriptor In Bytes ,  ENDPOINT descriptor type
Data Endpoint_nb_1 , Ep_attributes_1                        ' Address of the endpoint  ,  Endpoint's attributes
Data Ep_size_1%                                             ' Maximum packet size for this EP
Data Ep_interval_1                                          ' Interval for polling EP in ms



Usb_hid_report:
Data &H05 , &H01                                            ' Usage Page (Generic Desktop)
Data &H09 , &H06                                            ' Usage (Keyboard)
Data &HA1 , &H01                                            ' Collection (Application)
Data &H05 , &H07                                            ' Usage Page (Keyboard)
Data &H19 , 224                                             ' Usage Minimum (224)
Data &H29 , 231                                             ' Usage Maximum (231)
Data &H15 , &H00                                            ' Logical Minimum (0)
Data &H25 , &H01                                            ' Logical Maximum (1)
Data &H75 , &H01                                            ' Report Size (1)
Data &H95 , &H08                                            ' Report Count (8)
Data &H81 , &H02                                            ' Input (Data, Variable, Absolute)
Data &H81 , &H01                                            ' Input (Constant)
Data &H19 , &H00                                            ' Usage Minimum (0)
Data &H29 , 101                                             ' Usage Maximum (101)
Data &H15 , &H00                                            ' Logical Minimum (0)
Data &H25 , 101                                             ' Logical Maximum (101)
Data &H75 , &H08                                            ' Report Size (8)
Data &H95 , &H06                                            ' Report Count (6)
Data &H81 , &H00                                            ' Input (Data, Array)
Data &H05 , &H08                                            ' Usage Page (LED)
Data &H19 , &H01                                            ' Usage Minimum (1)
Data &H29 , &H05                                            ' Usage Maximum (5)
Data &H15 , &H00                                            ' Logical Minimum (0)
Data &H25 , &H01                                            ' Logical Maximum (1)
Data &H75 , &H01                                            ' Report Size (1)
Data &H95 , &H05                                            ' Report Count (5)
Data &H91 , &H02                                            ' Output (Data, Variable, Absolute)
Data &H95 , &H03                                            ' Report Count(3)
Data &H91 , &H01                                            ' Output(constant)
Data &HC0                                                   ' End Collection

[/img][/i]

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

Some users sends me some questions about ADD-on and other links

http://www.mcselec.com/index.php... - that is link on mcselec.com(Mark's).
http://www.mcselec.com/index.php... - that is link from AVR BASCOM.

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

Last Edited: Mon. Jan 3, 2011 - 02:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a feeling this is bordering on spam now. If you want to advertise and sell you products then get an ad in the front page.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello
agree, will delete prices. Everybody can see it on links if he(or she want)

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see there is no interest on that theme, so have a fun.

Reguards from Slovenia

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

Have a look on new 3D prints:)

Attachment(s): 

Bostjan Suhel
Kajuhova 3
SI-3270 Slovenia
bostjan.suhel@gmail.com
+386 3 734 20 61
http://suhel.homeip.net