⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keydisplay.txt

📁 按键 对应灯亮PIC 汇编程序 已经通过硬件调试 放心使用
💻 TXT
字号:
title  "hd7279 test"
list  p=PIC16f877
include"p16f877.inc"
key equ  1  
cs  equ  2
clk equ  3 
dat equ  5
data_in    equ   20h   
dat_out    equ   21h
x          equ   22h
bit_count  equ   23h
timer      equ   24h
timer1     equ   25h
TEMP1      equ   26h
count3     equ   27h
y          equ   28h

org  000h
goto  start
org  005h

send   movwf  dat_out   ;发送命令到HD7279
       movlw   08h
       movwf   bit_count   
       bcf   portc,cs
       call dey1 
s_loop   bsf  status,rp0
         bcf  status,rp1
         bcf   trisc,5
        bcf  status,rp0 
         bcf  status,c
         rlf   dat_out 
         bcf    portc,5        
         btfsc  status,c
         bsf  portc,5
         bsf  portc,clk       ;clk上升沿发送数据
         call dey2
         bcf  portc,clk
         call  dey2
         decfsz  bit_count
         goto   s_loop
         bsf  status,rp0
        bcf  status,rp1
        bsf   trisc,5
        bcf  status,rp0
        return

receive   movlw  8h        ;接收HD7279的返回值
          movwf  bit_count
          bsf  status,rp0
         bcf  status,rp1
         bsf   trisc,5
         bcf  status,rp0
         call dey1
r_loop    bsf   portc,clk 
          call  dey2
          bcf  portc,clk        ;clk下降沿接收数据
          call  dey2
          bsf  status,c                            
          btfss  portc,5
          bcf  status,c
          rlf   data_in
          decfsz  bit_count
          goto  r_loop
          bsf  status,rp0
          bcf  status,rp1
          bcf   trisc,5
          bcf  status,rp0
         return
DELAY
       MOVLW 0aH           ;将外层参数值06H经过W
       MOVWF 29H           ;送入用作外循环变量
LOOP1
       MOVLW 0EBH          ;将中循环参数之经过W
       MOVWF 2aH            ;送入用作中循环变量
LOOP2
       MOVLW 0ECH          ;将内循环参数值经过W
       MOVWF 2bH            ;送入用作内循环变量
LOOP3
       DECFSZ 2bH             ;变量递减,若为0跳过
       GOTO LOOP3           ;跳转到LOOP3
       DECFSZ 2aH             ;变量递减,若为0跳过
       GOTO LOOP2           ;跳转到LOOP2
       DECFSZ 29H             ;变量递减,若为0跳过
       GOTO LOOP1           ;跳转到LOOP1
       RETURN                    ;返回主程序
 
dey3   movlw  19h           ; 延时25ms
       movwf  timer
delay_loop3  movlw  0ffh
             movwf  timer1
delay_loop4  decfsz  timer1,1
             goto  delay_loop4
             decfsz  timer,1
             goto  delay_loop3
             return
dey1         movlw  10h        ;延时50us
             movwf  timer
delay_loop1  decfsz  timer
             goto  delay_loop1
             return
dey2   movlw 3h                      ;延时8us
       movwf timer
delay_loop2  decfsz  timer
             goto  delay_loop2 
             return  

re_read                                  ;若按下10+键(7键)则读第二次键值
       btfss  portc,key
       goto  re_read
 re    btfsc  portc,key
       goto  re 
       movlw  15H          
       call   send
       call   receive
       bsf     portc,cs
       movlw  0Ah
       addwf data_in,1
       return
       

display   movlw   0x0e0             ;段点亮
          call   send
          movf   data_in,w
      movwf  x
          call    send
          bsf  portc,cs
          return
display2   movlw   0x0c0           ;段熄灭
          call   send
          movf   x,w
          call    send
          bsf  portc,cs
          return
start  
       bsf  status,rp0                 ;hd7279初始化
       bcf  status,rp1
       movlw   0d3h
       movwf    trisc
       bcf  status,rp0
       movlw   0d7h
       movwf   portc
       call    dey3
       movlw   0a4h
       movwf   dat_out
       call    send
       bsf     portc,cs             
main   nop                           ;主程序
       btfsc  portc,key
       goto  main 
       movlw  15H
       call   send
       call   receive
       bsf     portc,cs
       movlw  07h
       subwf data_in,0
       btfsc  status,Z            ;7为"1—"位
       call  re_read
       call  display 
       call   delay
       call   display2  ;延时一段时间  灯自动熄灭
wait    btfss  portc,key
        goto  wait
        goto main
        end 




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -