#include ;------------------------------------------------ ; Reservierung des Stack-Bereichs ?STACK SEGMENT IDATA RSEG ?STACK DS 10H ;------------------------------------------------------------------------------ ; Auf Adresse 0 im Code-Speicher muss ein LJMP zum Programmanfang stehen CSEG AT 0 ;absolutes Code-Segment bei Adresse 0 ljmp start ;Springe zur Marke start ;------------------------------------------------------------------------------ ; Hier folgt Programmcode (Code-Beginn ueber Linker festgelegt) program_code SEGMENT CODE RSEG program_code ;waehle Code-Segment USING 0 ;Zeige Benuetzung von Registerbank 0 fuer den folgenden Programmcode an ;------------------------------------------------------------------------------ ;Initialisierung Stack und I/O-Karte start: mov sp,#?stack-1 ;STACK-Definition ;------------------------------------------------------------------------------ phase_a equ p3.2 phase_b equ p3.3 led_port equ p0 dseg at 30h enc_delta: ds 1 enc_last: ds 1 cseg main: call poll_encoder call read_encoder2 add a, led_port mov led_port, a jmp main poll_encoder: clr a mov c, phase_a ; input phase_a rlc a jnb phase_b, _poen1 ; input phase_b xrl a, #3 ; convert gray to binary _poen1: xch a, enc_last ; store new as next last subb a, enc_last ; difference last - new jnb acc.0, _poen3 ; bit 0 = value (1) jnb acc.1, _poen2 ; bit 1 = direction (+/-) inc enc_delta ret _poen2: dec enc_delta _poen3: ret read_encoder2: ; read two phase encoder mov a, enc_delta ; read delta counts anl enc_delta, #1 ; clear all bits except debouncing bit mov c, acc.7 ; copy sign bit rrc a ; / 2 ret end