;-----------------------------------------------------------------------; ; COUNTER.ASM 按S31,七段数码管增一,学习查表程序和按键处理范例程序 ; ; 硬件连接: ; ; 把PORTB一一对应接到7SEG上 ; ; 把PORTA的1号口的跳线接到KB的1号口 ; ;-----------------------------------------------------------------------; ;-----------------------------------------------------------------------; ; 作者:荣新华 BD6CR 2001年12月28日 ; ;-----------------------------------------------------------------------; LIST P=16F84 ; 告诉编译程序使用何种PIC单片机 INCLUDE "p16f84.inc" ; 定义了特殊寄存器等内容的头文件 ERRORLEVEL -224 __CONFIG _PWRTE_ON & _XT_OSC & _WDT_OFF ; 配置字 ;变量定义 #define temp 0x20 #define L1 0x21 #define L2 0x22 org 0 movlw B'00000001' ;PORTA.0为输入 tris PORTA movlw B'00000000' ;PORTB为输出 tris PORTB movlw .0 movwf temp ;初始化temp again btfss PORTA,0 ;S31释放? goto again ;没有释放 call delay ;释放,防止释放按键抖动 movlw .10 subwf temp,w btfsc STATUS,Z ;到10了吗? clrf temp ;是,清零 movfw temp call table ;把temp值放入W,查表 movwf PORTB ;把查表结果输出到PORTB(显示) t_agn btfsc PORTA,0 ;S31按下? goto t_agn ;没有按下 call delay ;按下,防止按下按键抖动 incf temp,f ;temp增一 goto again delay movlw .10 ;延时30us,防止按键抖动 movwf L1 loopw1 movlw .255 movwf L2 loopw2 decfsz L2, f goto loopw2 decfsz L1, f goto loopw1 return table addwf PCL,f ;二进制到七段数码显示的查表程序 retlw B'00111111' ;0 retlw B'00000110' ;1 retlw B'01011011' ;2 retlw B'01001111' ;3 retlw B'01100110' ;4 retlw B'01101101' ;5 retlw B'01111101' ;6 retlw B'00000111' ;7 retlw B'01111111' ;8 retlw B'01101111' ;9 end