首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

PIC单片机七段数码管接口电路图(含源程序)

PIC单片机七段数码管接口电路图(含源程序)



图 PIC单片机七段数码管接口电路图

基于PIC单片机的七段数码显示源程序

程序范例:

1。七段数码管显示器显示1234循环

2。七段显示器显示0000~9999(自动加1)循环

七段显示器显示1234循环:



范例一:7seg1.*      

LIST P=16F877,R=DEC ;  

#INCLUDE <P16F877.INC> MOVF DB1,0

CBLOCK H''20'' CALL TABLE

DB0,DB1   MOVWF PORTSEG

ENDC   MOVLW H''FB''

;   MOVWF PORTCA

PORTSEG EQU PORTD CALL DELAY25

TRISEG EQU TRISD BSF PORTCA,2

PORTCA EQU PORTB ;  

TRICA EQU TRISB SWAPF DB1,0

;   CALL TABLE

ORG 0 MOVWF PORTSEG

NOP   MOVLW H''F7''

BANKSEL TRICA MOVWF PORTCA

MOVLW 0 CALL DELAY25

MOVWF TRICA BSF PORTCA,3

MOVWF TRISEG GOTO MAIN

BANKSEL PORTCA ;  

MOVLW 0XFF TABLE: ANDLW H''0F''

MOVWF PORTCA ADDWF PCL

  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 ;

CALL DELAY25 #INCLUDE <DELAY25.INC>

BSF PORTCA,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
返回列表