$NOMOD51 ;der Modus fuer 8051 wird abgeschaltet $debug $nolist ;es wird kein Listing fuer reg535 erstellt $include(C8051F340.inc) ;die C8051F340-spezifischen Daten $list ;es wird ein Listing erstellt $title (P05_MCWS08.A51) ;------------------------------------------------------------------------ ;Programmbeschreibung ;------------------------------------------------------------------------ ;Programm: ;Grundstellung - irgendwo zwischen auf und ab ;T2 Duty Cycle auf ;T3 Duty Cycle ab ; ; ;Erstellt am: Freitag, 10. August 2007 09:36:16 ;Programmiert: ; ;Verwendete Einspruenge: keine ; ;Verwendete Unterprogramme: keine ; ; ;Verwendete Register und Variable: ;Registerbank(0) ;R2 ; ;Kommentar: ; ;Aenderungen: ;Geaendert am: Freitag, 10. August 2007 09:36:16 ; ; ;------------------------------------------------------------------------ ;Initialisierungsteil fuer allgemeine Konstanten ;------------------------------------------------------------------------ INC_DUTY EQU 128 CSEG AT 0H ;Legt absolute Codesegmentadresse auf 0h jmp INIT ; ;------------------------------------------------------------------------ ;Interrupt-Vektoren ;------------------------------------------------------------------------ ORG 05Bh clr CF ;Counter Flag quittieren call ISR_PCA ;Interrupt Service Routine aufrufen reti ;------------------------------------------------------------------------ ;Initialisierungsteil fuer On-Chip Peripherie ;------------------------------------------------------------------------ ORG 100H ;Programmstart bei 100H INIT: call Init_Device ;Aufruf der Initialisierung ;------------------------------------------------------------------------ ;Programmschleife ;------------------------------------------------------------------------ ABFRAGE: mov C,P1.1 ;Kopieren des Ausgangsports mov P3.2,C mov P3.3,C mov P3.4,C jmp ABFRAGE ;Warteschleife ISR_PCA: jnb P1.2,DUTY_CYCLE_AUF ;Flanke spaeter jnb P1.3,DUTY_CYCLE_AB ;Flanke frueher ret ;Aus der ISR_PCA DUTY_CYCLE_AUF: mov A,PCA0CPL1 ;Compare P1.1 Low Byte in Akku clr C add A,#INC_DUTY ;Addieren mit Carry mov PCA0CPL1,A ;wieder zurueck mov A,PCA0CPH1 ;HB addc A,#0 ;Carry addieren mov PCA0CPH1,A ;wieder zurueck ret DUTY_CYCLE_AB: mov A,PCA0CPL1 ;Compare P1.1 Low Byte in Akku clr C subb A,#INC_DUTY ;Addieren mit Carry mov PCA0CPL1,A ;wieder zurueck mov A,PCA0CPH1 ;HB subb A,#0 ;Carry subtrahieren mov PCA0CPH1,A ;wieder zurueck ret ; Peripheral specific initialization functions, ; Called from the Init_Device label ; ;PCA-Clck 3 MHz --> 1/3 MHz*65536=21,8453 ms Periodendauer PCA_Init: mov PCA0CN, #040h ; PCA0 control anl PCA0MD, #0BFh ; PCA0 mode mov PCA0MD, #003h mov PCA0CPM1, #0C2h mov PCA0L, #018h mov PCA0H, #0F3h mov PCA0CPL1, #018h mov PCA0CPH1, #0F3h ret Timer_Init: mov TMOD, #011h mov CKCON, #002h ret Port_IO_Init: ; P0.0 - Skipped, Push-Pull, Digital ; P0.1 - Skipped, Push-Pull, Digital ; P0.2 - Skipped, Push-Pull, Digital ; P0.3 - Skipped, Push-Pull, Digital ; P0.4 - Skipped, Push-Pull, Digital ; P0.5 - Skipped, Push-Pull, Digital ; P0.6 - Skipped, Push-Pull, Digital ; P0.7 - Skipped, Push-Pull, Digital ; P1.0 - CEX0 (PCA), Push-Pull, Digital ; P1.1 - CEX1 (PCA), Push-Pull, Digital ; P1.2 - CEX2 (PCA), Push-Pull, Digital ; P1.3 - CEX3 (PCA), Push-Pull, Digital ; P1.4 - CEX4 (PCA), Push-Pull, Digital ; P1.5 - T0 (Timr0), Push-Pull, Digital ; P1.6 - T1 (Timr1), Push-Pull, Digital ; P1.7 - Unassigned, Push-Pull, Digital ; P2.0 - Unassigned, Open-Drain, Digital ; P2.1 - Unassigned, Open-Drain, Digital ; P2.2 - Unassigned, Open-Drain, Digital ; P2.3 - Unassigned, Open-Drain, Digital ; P2.4 - Unassigned, Open-Drain, Digital ; P2.5 - Unassigned, Open-Drain, Digital ; P2.6 - Unassigned, Open-Drain, Digital ; P2.7 - Unassigned, Open-Drain, Digital ; P3.0 - Unassigned, Open-Drain, Digital ; P3.1 - Unassigned, Open-Drain, Digital ; P3.2 - Unassigned, Open-Drain, Digital ; P3.3 - Unassigned, Open-Drain, Digital ; P3.4 - Unassigned, Open-Drain, Digital ; P3.5 - Unassigned, Open-Drain, Digital ; P3.6 - Unassigned, Open-Drain, Digital ; P3.7 - Unassigned, Open-Drain, Digital mov P0MDOUT, #0FFh mov P1MDOUT, #0FFh mov P0SKIP, #0FFh mov XBR1, #075h ret Oscillator_Init: mov OSCICN, #083h mov CLKMUL, #080h clr A ; Wait 5us for initialization djnz ACC, $ orl CLKMUL, #0C0h Osc_Wait2: mov A, CLKMUL jnb ACC.5, Osc_Wait2 ret Interrupts_Init: mov EIE1, #010h mov IT01CF, #010h mov IE, #080h ret ; Initialization function for device, ; Call Init_Device from your main program Init_Device: lcall PCA_Init lcall Timer_Init lcall Port_IO_Init lcall Oscillator_Init lcall Interrupts_Init ret end