Hardware Reference
In-Depth Information
MainLoop
; check bus activity
btfsc UIR,IDLEIF
bra MainLoop_suspend
call DEVICE ;this is the test and measurement device's main routine
goto MainLoop
; Set USB interface to suspend state
MainLoop_suspend
bsf UCON,SUSPND ;set suspend mode for the USB module
movff PORTD,PORTD_RESUME
;save conditions
movlw 0x00
movwf PORTD
bsf
UIE,ACTVIE
;enable bus activity interrupt
sleep
bra
MainLoop
Mit dem vorstehenden Listing ist bereits die komplette Hauptprogrammschleife der
Firmware dargestellt. Das Unterprogramm DEVICE umfasst alle gerätespezifischen
Funktionen des Beispielgeräts. Alle USB-Funktionen der Software werden per Inter-
rupt ausgeführt und sind deshalb nicht in der Hauptprogrammschleife MainLoop
zu finden. Dazu zählt auch die im Folgenden dargestellte Interrupt Service Routine,
die beim Aufwachen durchlaufen wird.
;******************************************************************************
; USB Resume Interrupt Service Routine
;******************************************************************************
USBresumeInterrupt
call clearACTVIF
; set oscillator to primary clock source
bcf
OSCCON,SCS1
bcf
OSCCON,SCS0
bsf
OSCCON,IDLEN
bcf
UIE,ACTVIE
;disable bus activity interrupt
bcf UIR,IDLEIF
movff PORTD_RESUME,PORTD
return
Der Schaltzustand aller LEDs und Relais wird wiederhergestellt und CPU und Peri-
pherie werden wieder vom Primäroszillator getaktet. Zuvor wird jedoch das den Inter-
rupt verursachende Flag ACTVIF gelöscht. Dazu ist die folgende Prozedur nötig:
;******************************************************************************
; Clear Bus Activity Detect Interrupt Bit, reference: DS39632C Section 17.5.1.1
;******************************************************************************
clearACTVIF
bcf UCON,SUSPND
clrACTVIFloop
btfss UIR,ACTVIF
bra
clrACTVIFdone
Search WWH ::




Custom Search