18F4550 usb INTERRUPTED BY tmr0 and usart

Status
Not open for further replies.

ayhampic

Member level 1
Joined
Aug 3, 2011
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,599
HI guys,

I have a small project which controls some leds by PC , the program is interrupted every 43ms by tmr0 in order to send some information to my PC , the program can also be interrupted by the serial com to stop or resume the program , the Problem is how can I use the usb to interrupt the program ? I mean : how can I use Usb instead of Serial to interrupt the program ?

the code is : for pic18f4550 using easyhid


Code Visual Basic - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Output PORTB
Dim x As Byte
Dim times As Byte
Dim nCounter As Byte
Dim i As Byte
Dim Work_Status As boolean
times = 0
Work_status = 1
GoSub AttachToUSB
GIE_GIEH=1
PEIE_GIEL=1
TMR0IE= 1
RCIE= 1
 
USBBuffer=""  
On_Interrupt GoTo jingle
 
ProgramLoop:
   USBIn 1, USBBuffer, USBBufferSizeRX, ProgramLoop
 
   If work_status = 1 Then
       times = USBBuffer[1]
       'SOME USB WORK ......
       For i = 1 To times
        PORTB = PORTB +1
        If work_status = 0 Then GoTo ProgramLoop
        USBOut 1, USBBuffer, USBBufferSizeTX
        DelayMS 2
       Next i
       
   End If
GoTo ProgramLoop
  
 
AttachToUSB:
   Repeat                               
      USBPoll       
   Until PP0 = ATTACHED_STATE
   Return   
   
   
jingle:
    'INTERRUPT EVERY 43 ms
    TMR0IF=0
    nCounter = ncounter+1
    If nCounter = 8 Then
        nCounter = 0
        USBBuffer = "i = " + Str$(Dec3 i) + "  "
    End If
    'interrupt by serial . how can I use the usb to interrupt instead ?    
If RCIF =1 Then  
      HSerIn 10,err,[x]
      If x = "s" Then
        work_status = 0
      ElseIf x= "c" Then
        work_status = 1
      End If
      RCIF=0
err:  RCREG=0
End If
 
Context Restore



please how can I detect the usb interrupt ?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…