📄 encoder.asm
字号:
;+---------------------------------------------------------------------------+;| |;| Copyright (C) 2002, Tom De Rybel |;| on1dcd@hotmail.com |;| |;| This program is free software; you can redistribute it and/or |;| modify it under the terms of the GNU General Public License |;| as published by the Free Software Foundation; either version 2 |;| of the License, or any later version. |;| |;| This program is distributed in the hope that it will be useful, |;| but WITHOUT ANY WARRANTY; without even the implied warranty of |;| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |;| GNU General Public License for more details. |;| |;| You should have received a copy of the GNU General Public License |;| along with this program; if not, write to the Free Software |;| Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |;| |;| |;+---------------------------------------------------------------------------+; Interrupt test of the Cypress EZ-USB; Makes a LED connected to PB4 blink at a rate controllable by a rotary encoder; connected to PB6 (A-channel) and PB7 (B-channel);;+-------------------------------------+;| Declaration of the EZ-USB registers |;+-------------------------------------+.equ DPL1, 0x84.equ DPH1, 0x85.equ DPS, 0x86.equ CKCON, 0x8E.equ SPC_FNC, 0x8F.equ EXIF, 0x91.equ MPAGE, 0x92.equ SCON1, 0xC0.equ SBUF1, 0xC1.equ EICON, 0xD8.equ EIE, 0xE8.equ EIP, 0xF8 .equ CPUCS, 0x7F92 .equ PORTACFG, 0x7F93.equ PORTBCFG, 0x7F94.equ PORTCCFG, 0x7F95.equ OUTA, 0x7F96 .equ OUTB, 0x7F97.equ OUTC, 0x7F98.equ PINSA, 0x7F99.equ PINSB, 0x7F9A.equ PINSC, 0x7F9B.equ OEA, 0x7F9C.equ OEB, 0x7F9D.equ OEC, 0x7F9E;+-------------------+;| Interrupt vectors |;+-------------------+;;Reset Vector.org 0x00ljmp init ;#INT5 Vector.org 0x5B;ljmp int5 ;INT6 Vector.org 0x63ljmp int6 .org 0x0100;+-------------------------+;| Initialisation sequence |;+-------------------------+; init: ;;mov 0x92, #0x7F ; tc, allows movx Ri to access ez-usb memory mov dptr, #PORTBCFG ; All pins are standard PB pins mov a, #01000000b ; Besides PB6 -> INT6 movx @dptr, a mov dptr, #OEB ; Pin PB4 is an output pin mov a, #00010000b movx @dptr, a mov IE, #10000000b ; Enable interrupts mov a, EIE ; Enable INT6 the clean way. setb acc.4 ; Read, modify and write mov EIE, a mov r1,0 ;+--------------+;| Main program |;+--------------+ ;begin: mov a, r1 ; R1 contains the requested delay, as set by mov r0, a ; the interrupt routine lcall Wait1msec ; The interrupt routine manipulates R0, ; which is used by the delay loop. mov dptr, #OUTB mov a, #00000000b movx @dptr, a mov a, r1 mov r0, a lcall Wait1msec mov dptr, #OUTB mov a, #00010000b movx @dptr, a ljmp begin ;+-----------------------------+;| Interrupt 6 service routine |;+-----------------------------+;int6: mov dptr, #PINSB ; Read the status on PB movx a, @DPTR mov C, acc.7 ; Move the PB7 bit into the carry flag jc int6_increment ; If carry is 1, add 1 to the counter jnc int6_decrement ; If carry is 0, substract 1 form the counter int6_increment: mov a, r1 ; Move R1 into the accu add a, #0x01 ; Add 1 to A sjmp int6_end int6_decrement: mov a, r1 ; Move R1 into the accu subb a, #0x01 ; Substract 1 from A sjmp int6_end int6_end: mov r1, a ; Write the result into R1 mov a, EICON ; Clear the INT6 interrupt flag clr acc.3 mov EICON, a reti ;+----------------------------------------------------------------------+;| Timing loops taken from the buttons and lights example in USB Design |;| by Example. These are needed by the LCD routines. |;| |;| A, DPTR and R0 are used and modified. |;+----------------------------------------------------------------------+;Wait100msec: mov r0, #100Wait1msec: ; A delay loop mov dptr,#-1200More: inc dptr ; 3 cycles mov a,dpl ; + 2 orl a,dph ; + 2 jnz More ; + 3 = 10 cycles x 1200 = 1msec djnz r0, Wait1msec ; ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -