您当前的位置:首页 > 自动化 > 单片机

Pic16f877 七段数码管显示电路

发布时间:2010-03-01 18:37:15  来源:资料室  作者:  更新20200708 193351

                                         电路图

程序范例:
1。七段数码管显示器显示1234循环
2。七段显示器显示0000~9999(自动加1)循环

七段显示器显示1234循环:

范例一:7seg1.*      
LIST P=16F877,R=DEC ;  
#INCLUDE <P16F877.INC>  MOVFDB1,0
CBLOCK H'20'  CALLTABLE
DB0,DB1    MOVWFPORTSEG
ENDC    MOVLWH'FB'
;    MOVWFPORTCA
PORTSEG EQU PORTD  CALLDELAY25
TRISEG EQU TRISD  BSFPORTCA,2
PORTCA EQU PORTB ;  
TRICA EQU TRISB  SWAPFDB1,0
;    CALLTABLE
ORG 0  MOVWF PORTSEG
NOP   MOVLWH'F7'
BANKSELTRICA  MOVWFPORTCA
MOVLW 0  CALLDELAY25
MOVWFTRICA  BSFPORTCA,3
MOVWFTRISEG  GOTOMAIN
BANKSELPORTCA ;  
MOVLW 0XFF TABLE: ANDLW H'0F'
MOVWFPORTCA  ADDWFPCL
  MOVLW H'12' T1: RETLW H'C0' ;’0’
  MOVWF DB1   RETLW H'F9' ;’1’
  MOVLW H'34'   RETLW H'A4' ;’2’
  MOVWF DB0   RETLW H'B0' ;’3’
MAIN: MOVF DB0,0   RETLW H'99' ;’4’
  CALL TABLE   RETLW H'92' ;’5’
  MOVWF PORTSEG   RETLW H'82' ;’6’
  MOVLW H'FE'   RETLW H'F8' ;’7’
  MOVWF PORTCA   RETLW H'80' ;’8’
  CALL DELAY25   RETLW H'90' ;’9’
  BSF PORTCA,0   RETLW H'88' ;’A’
;       RETLW H'83' ;’B’
  SWAPF DB0,0   RETLW H'C6' ;’C’
  CALL TABLE   RETLW H'A1' ;’D’
  MOVWF PORTSEG   RETLW H'86' ;’E’
  MOVLW H'FD'   RETLW H'8E' ;’F’
  MOVWF PORTCA ;
CALLDELAY25 #INCLUDE <DELAY25.INC>
BSFPORTCA,1 END

 

范例二:7seg11.*
LIST P=16F877,R=DEC
#INCLUDE <P16F877.INC>
CBLOCK H'20'
ENDC
;
PORTSEG EQU PORTD
TRISEG EQU TRISD
PORTCA EQU PORTB
TRICA EQU TRISB
;
ORG 0
NOP
BANKSEL TRICA
MOVLW 0
MOVWF TRICA
MOVWF TRISEG
BANKSEL PORTCA
MOVLW 0XFF
MOVWF PORTCA
MAIN: MOVLW H'99'
MOVWF PORTSEG
MOVLW H'FE'
MOVWF PORTCA
CALL DELAY25
BSF PORTCA,0
;
MOVLW H'B0'
MOVWF PORTSEG
MOVLW H'FD'
MOVWF PORTCA
CALL DELAY25
BSF PORTCA,1
;
MOVLW H'A4'
MOVWF PORTSEG
MOVLW H'FB'
MOVWF PORTCA
CALL DELAY25
BSF PORTCA,2
;
MOVLW H'F9
MOVWF PORTSEG
MOVLW H'F7'
MOVWF PORTCA
CALL DELAY25
BSF PORTCA,3
GOTO MAIN
;
#INCLUDE <DELAY25.INC>
END
 

七段显示器显示0000~9999(自动加1)循环
范例一:7seg2.*
LIST P=16F877,R=DEC
#INCLUDE <P16F877.INC>
CBLOCK H'20'
R0,DB0,DB1
ENDC
;
PORTSEG EQU PORTD
TRISEG EQU TRISD
PORTCA EQU PORTB
TRICA EQU TRISB
;
ORG 0
NOP
BANKSEL TRICA
MOVLW 0
MOVWF TRICA
MOVWF TRISEG
BANKSEL PORTCA
MOVLW 0XFF
MOVWF PORTCA
ST: MOVLW 10
MOVWF R0
MOVLW 0
MOVWF DB0
MOVWF DB1
MAIN: MOVF DB0,0
CALL TABLE
MOVWF PORTSEG
MOVLW H'FE'
MOVWF PORTCA
CALL DELAY25
BSF PORTCA,0
;
SWAPF DB0,0
CALL TABLE
MOVWF PORTSEG
MOVLW H'FD'
MOVWF PORTCA
CALL DELAY25
MOVF DB1,0
ADDLW H'6'
BTFSS STATUS,1
GOTO MAIN
BCF STATUS,1
MOVF DB1,0
ANDLW H'F0'
ADDLW H'10'
MOVWF DB1
XORLW H'A0'
BTFSS STATUS,2
GOTO MAIN
GOTO ST
;
TABLE: ANDLW H'0F'
ADDWF PCL
T1: RETLW H'C0'
RETLW H'F9'
RETLW H'A4'
RETLW H'B0'
RETLW H'99'
RETLW H'92'
RETLW H'82'
RETLW H'F8'
RETLW H'80'
RETLW H'90'
;
#INCLUDE <DELAY25.INC>
END
BSF PORTCA,1
;
MOVF DB1,0
CALL TABLE
MOVWF PORTSEG
MOVLW H'FB'
MOVWF PORTCA
CALL DELAY25
BSF PORTCA,2
;
SWAPF DB1,0
CALL TABLE
MOVWF PORTSEG
MOVLW H'F7'
MOVWF PORTCA
CALL DELAY25
BSF PORTCA,3
;
DECFSZ R0,1
GOTO MAIN
MOVLW 10
MOVWF R0
INCFSZ DB0,1
MOVF DB0,0
ADDLW H'6'
BTFSS STATUS,1
GOTO MAIN
BCF STATUS,1
MOVF DB0,0
ANDLW H'F0'
ADDLW H'10'
MOVWF DB0
XORLW H'A0'
BTFSS STATUS,2
GOTO MAIN
MOVLW 0
MOVWF DB0
INCFSZ DB1,1
 

 

范例二:7seg22.*
LIST P=16F877,R=DEC
#INCLUDE <P16F877.INC>
CBLOCK 0X20
R0,DB0,DB1
ENDC
;
PORTSEG EQU PORTD
TRISEG  EQU TRISD
PORTCA  EQU PORTB
TRICA   EQU TRISB
;
ORG 0
NOP
BANKSEL TRICA
MOVLW 0
MOVWF   TRICA
MOVWF   TRISEG
BANKSEL PORTCA
MOVLW   0XFF
MOVWF   PORTCA
ST: MOVLW 10
MOVWF  R0
MOVLW  0
MOVWF  DB0
MOVWF  DB1
AGAIN: CALL FOURSEG
INCFSZ DB0,1
MOVF   DB0,0
ADDLW  H'6'
BTFSS  STATUS,1
GOTO   AGAIN
BCF    STATUS,1
MOVF   DB0,0
ANDLW  H'F0'
ADDLW  H'10'
MOVWF  DB0
XORLW  H'A0'
BTFSS  STATUS,2
GOTO   AGAIN
MOVLW 0
MOVWF DB0
INCFSZ DB1,1
MOVF DB1,0
ADDLW H'6'
BTFSS STATUS,1
GOTO AGAIN
BCF STATUS,1
MOVF DB1,0
ANDLW H'F0'
ADDLW H'10'
MOVWF DB1
XORLW H'A0'
BTFSS STATUS,2
GOTO AGAIN
GOTO ST
;
#INCLUDE <FOURSEG.INC>
#INCLUDE <DELAY25.INC>
END
 
 


来顶一下
返回首页
返回首页
分享到:
发表评论

 共有人参与,请您也说几句看法

 
   验证码: 看不清楚,点击刷新 看不清楚,点击刷新
最新评论
  • 已经被转载无数次了     稳定么这个电路 匿名 于2020-06-29 08:34:59发布
  • 好好好 谢谢 郑旺旺 于2020-06-28 13:21:24发布
  • 这下客户的机器能修了。下载成功 匿名 于2020-06-25 22:12:08发布
  • 01354 匿名 于2020-06-20 14:02:17发布
  • 核和 匿名 于2020-06-19 10:46:43发布
  • 谢谢提供资料 匿名 于2020-06-18 20:12:02发布
  •  匿名 于2020-06-13 19:55:54发布