$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 (VC_2_Servo_LR.A51) ;------------------------------------------------------------------------ ;Programmbeschreibung ;------------------------------------------------------------------------ ;Programm: ;P1.1 Anschluss PCA - CEX1 ;T2 Servo Pulsweite groesser - Compare-Register wird erniedrigt ;T3 Servo Oulsweite kleiner ;Sysclk 3 MHz PCA0 Periode 21,845ms - Interrupt-Periode ;PCA_Interrupt ;VORSICHT: Der 16-BIT-COmparator arbeitet nur wenn LOW und HIGH Byte ;geschrieben wird ; ; ;Erstellt am: Sonntag, 18. Januar 2009 14:17:53 ;Programmiert: Juergen Walter ; ;Verwendete Einspruenge: keine ; ;Verwendete Unterprogramme: keine ; ; ;Verwendete Register und Variable: ;Registerbank(0) ;R2 ; ;Kommentar: ; ;Aenderungen: ;Geaendert am: Sonntag, 18. Januar 2009 14:17:53 ; ; ;------------------------------------------------------------------------ ;Initialisierungsteil fuer allgemeine Konstanten ;------------------------------------------------------------------------ PCA0_INT EQU 1 ;Fuer extrem langsame Fahrt INCDEC EQU 2 CSEG AT 0H ;Legt absolute Codesegmentadresse auf 0h jmp INIT ; ;------------------------------------------------------------------------ ;Interrupt-Vektoren ;------------------------------------------------------------------------ ORG 5BH clr CF ;Interrupt Flag PCA erkannt call ISR_PCA ; RETI ;------------------------------------------------------------------------ ;Initialisierungsteil fuer On-Chip Peripherie ;------------------------------------------------------------------------ ORG 100H ;Programmstart bei 100H INIT: call Init_Device ;Aufruf zur Initialisierung der Controller Funktionen mov R2,#PCA0_INT ;Zaehlregister fuer Interrupts ;------------------------------------------------------------------------ ;Programmschleife ;------------------------------------------------------------------------ ABFRAGE: jmp ABFRAGE ISR_PCA: djnz R2,ISRENDE ;Sind bereits n Interrupts aufgetreten? mov R2,#PCA0_INT jb P1.2,TASTE3 ;T2 abwaerts nicht betaetigt clr C mov A,PCA0CPL1 ;Inhalt von Low-Byte PCA0 Modul 1 Low Byte subb A,#INCDEC ;um INCDEC erniedrigen mov PCA0CPL1,A ;Neuer Comparewert LB mov A,PCA0CPH1 ;Inhalt von Low-Byte PCA0 Modul 1 High Byte jnc KEINUEBERTRAG1 ; dec A ;Inhalt um 1 erniedrigen KEINUEBERTRAG1: mov PCA0CPH1,A ;Neuer Comparewert HB TASTE3: ;Flanke wird erhoeht - Duty Cycle kleiner jb P1.3,ISRENDE ;T3 aufwaerts nicht betaetigt clr C mov A,PCA0CPL1 ;Inhalt von CCL1 add A,#INCDEC ;um INCDEC érhoehen mov PCA0CPL1,A ;Neuer Comparewert LB mov A,PCA0CPH1 ;Inhalt von CCH1 jnc KEINUEBERTRAG2 ;High-Byte wird nicht veraendert inc A ;Inhalt um 1 erhoehen KEINUEBERTRAG2: mov PCA0CPH1,A ;Neuer Comparewert HB ISRENDE: ret ;------------------------------------------------------------------------ ; Peripheral specific initialization functions, ; Called from the Init_Device label ;------------------------------------------------------------------------ PCA_Init: mov PCA0CN, #040h anl PCA0MD, #0BFh mov PCA0MD, #009h mov PCA0CPM1, #0C2h mov PCA0CPL1, #033h mov PCA0CPH1, #0F3h ret ADC_Init: mov AMX0N, #01Fh mov ADC0CN, #004h ret Port_IO_Init: ; P0.0 - Skipped, Push-Pull, Digital ; P0.1 - Skipped, Push-Pull, Digital ; P0.2 - SDA (SMBus), Push-Pull, Digital ; P0.3 - SCL (SMBus), Push-Pull, Digital ; P0.4 - TX0 (UART0), Push-Pull, Digital ; P0.5 - RX0 (UART0), 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 - Skipped, Push-Pull, Digital ; P1.3 - Skipped, Push-Pull, Digital ; P1.4 - Skipped, Push-Pull, Digital ; P1.5 - Unassigned, Push-Pull, Digital ; P1.6 - Unassigned, Push-Pull, Digital ; P1.7 - Unassigned, Push-Pull, Digital ; P2.0 - Skipped, Push-Pull, Analog ; P2.1 - Unassigned, Push-Pull, Digital ; P2.2 - Unassigned, Push-Pull, Digital ; P2.3 - Unassigned, Push-Pull, Digital ; P2.4 - Unassigned, Push-Pull, Digital ; P2.5 - Unassigned, Push-Pull, Digital ; P2.6 - Unassigned, Push-Pull, Digital ; P2.7 - Unassigned, Push-Pull, Digital ; P3.0 - Unassigned, Push-Pull, Digital ; P3.1 - Unassigned, Push-Pull, Digital ; P3.2 - Skipped, Push-Pull, Digital ; P3.3 - Skipped, Push-Pull, Digital ; P3.4 - Skipped, Push-Pull, Digital ; P3.5 - Unassigned, Push-Pull, Digital ; P3.6 - Unassigned, Push-Pull, Digital ; P3.7 - Unassigned, Push-Pull, Digital mov P2MDIN, #0FEh mov P0MDOUT, #0FFh mov P1MDOUT, #0FFh mov P2MDOUT, #0FFh mov P3MDOUT, #0FFh mov P0SKIP, #0C3h mov P1SKIP, #01Ch mov P2SKIP, #001h mov P3SKIP, #01Ch mov XBR0, #005h mov XBR1, #042h ret Oscillator_Init: mov OSCICN, #081h 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 ADC_Init lcall Port_IO_Init lcall Oscillator_Init lcall Interrupts_Init ret end