PIC16F877A dynamic digital clock display experiment reference program

Publisher:CuriousTravelerLatest update time:2017-12-07 Source: eefocusKeywords:PIC16F877A Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;Dynamic digital clock display experiment reference program


;Use resources:

;1, TMRO timer. Determine the displayed bit and display delay.

;2, TMR1 timer. Second signal is generated.

;3, PORTA port. The bit selection signal of the six common anode digital tubes, low level is effective

;4, PORTC port. The seven segments of the digital tube are not used by RC7.


;Function Description:

;1. The six-digit digital tube dynamically scans and displays the time (format: HHMMSS, 24-hour system).

;2.The clock signal is generated by programming the internal timer hardware unit of the microcontroller.


The purpose of this practical exercise is to make everyone more familiar with the programming of timers and the programming of dynamic scanning displays of multi-digit digital tubes.


;Hardware connection:

;1. All positions of the dip switches S4 and S5 on the experimental board must be set to ON, and the others can be turned off.

;2. It is best to remove the 93C46 and 24CXX memories from the board.


;Original provider of this example: pic16 forum member leef728, thanks to leef728 for sharing this example.

;Verified, edited and annotated by Zhong Guitian (engineer) (forum username: zhongruntian) of the Technical Department of Shenzhen Qianlongsheng Electronic Technology Co., Ltd.

;Website: PIC Microcontroller Learning Network http://www.pic16.com Discussion Forum: http://pic16.com/bbs/

;All rights reserved. Please indicate the source when reprinting. The description text in the file cannot be removed or changed.

;Program file name “TIME.ASM"

;The program list is as follows:

;************************************

   LIST P=16F877A

   INCLUDE "P16F877A.INC"     

   ERRORLEVEL -302

;******************************************

__CONFIG _DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC;

;***************File register definition**************

    CBLOCK 0X20

   WAW

   YW   

   BAW

   QUR

   GEW

   SHW 

   TEMP

   COUNTER

   S3

   DAA    

   STATUS_TMP

   W_TMP 

    ENDC

;********************Program starts****************

   ORG 0000H

   NOP ; Reset address

   GOTO MAIN        

   ORG 0004H


;********************Interrupt handler***********

   MOVWF W_TMP

   SWAPF STATUS,W

   CLRF STATUS

   MOVWF STATUS_TMP; The above 4 instructions are interrupt scene protection

   BCF INTCON,2 ; Clear TMRO interrupt flag

   MOVF TEMP,W ; Address of time storage unit

   MOVWF FSR

   MOVF INDF,W ; Get the time value of a certain bit

   CALL BMA ; Display code of the time obtained by looking up the table

   MOVWF PORTC ; send digital tube display

   COMF DAA,W ; Bit code inversion

   MOVWF PORTA ; Light up the corresponding digital tube

   RLF DAA,F ; ready to light up the next one

   INCF TEMP,F ; Next time storage unit address

   BTFSS DAA,6 ; Whether to display all six digits

   GOTO RT

   MOVLW 01H ;Yes, restart a new round of display

   MOVWF DAA                                    

   MOVLW 20H ; Re-acquire the address of the time unit

   MOVWF TEMP 

RT   

   SWAPF STATUS_TMP,W ; interrupt scene recovery   

   MOVWF STATUS

   SWAPF W_TMP,F

   SWAPF W_TMP,W

   MOVLW 0XE0 ; assign initial value to timer

   MOVWF TMR0

   RETFIE   

 

;*******************Main program starts****************  

MAIN   

   BANKSEL TRISA ;Selector 1

   MOVLW 00H

   MOVWF TRISA; PORTA is set to output

   MOVWF TRISC; PORTC is set to output

   MOVLW 06H 

   MOVWF ADCON1; Set port A to a normal digital port

   BANKSEL INTCON

   MOVLW 00H

   MOVWF YIW 

   MOVWF WAW

   MOVWF QIW

   MOVWF BAW

   MOVWF SHW

   MOVWF GEW ; The above 7 instructions clear the time

   MOVWF DAA

   MOVLW 20H

   MOVWF TEMP ; time storage unit address


   BSF STATUS,RP0

   MOVLW 0X05

   MOVWF OPTION_REG ; The divider is used for timing TMR0, and the division ratio is 1:4

   BCF STATUS,RP0

   BSF INTCON,7 ; Enable interrupt enable bit GIE

   BSF INTCON,5 ; Enable TMRO interrupt enable bit

   BCF INTCON,2 ; Clear TMRO interrupt flag

   MOVLW 0XE0 ; assign initial value to TMRO 

   MOVWF TMR0


   CLRF DAA                                     

   INCF DAA,F ;Display bit setting

;****************************************************** *************

KS   

   CALL DELAY; call 200ms timer program

   CALL DELAY

   CALL DELAY

   CALL DELAY

   CALL DELAY ; Call 5 times, exactly 1s

   INCF GEW,F

   MOVF GEW,W ; Check if the unit digit of the second is 10

   XORLW .10

   BTFSS STATUS,Z

   GOTO KS ; Yes, the ones digit of the second is cleared to 0, and the tens digit of the second is increased by 1

   INCF SHW,F                                    

   CLRF GEW

   CLRF STATUS

   MOVF SHW,W

   XORLW .6 ; Check if the tens digit of the second is 6 (1 minute and 60 seconds)

   BTFSS STATUS,Z 

   GOTO KS

   INCF BAW,F ; Yes, the tens digit of seconds is cleared to 0, and the ones digit of minutes is increased by 1

   CLRF SHW

   CLRF STATUS

   MOVF BAW,W

   XORLW .10 ; Check if the points are equal to 10

   BTFSS STATUS,Z

   GOTO KS

   INCF QIW,F ; Yes, the ones place of the minute is cleared to 0, and the tens place of the minute is increased by 1

   CLRF BAW

   CLRF STATUS

   MOVF QIW,W

   XORLW .6 ; Check if the tens digit of the minute is 6 (1 hour and 60 minutes)

   BTFSS STATUS,Z

   GOTO KS

   INCF WAW,F ; Yes, clear the tens digit of the minute to 0, and add 1 to the ones digit of the hour

   CLRF QIW

   CLRF STATUS

   MOVF WAW,W

   XORLW .4 ; Check if the unit digit is 4 (24-hour system)

   BTFSS STATUS,Z

   GOTO KS

   INCF YIW,F ; Yes, the ones digit of the hour is cleared to 0, and the tens digit of the hour is increased by 1

   CLRF WAW

   CLRF STATUS

   MOVF YIW,W

   XORLW .2 ; Check whether the tens digit is 2 or not

   BTFSS STATUS,Z

   GOTO KS

   

   CLRF GEW ; Yes, set the time back to 00-00-00

   CLRF SHW

   CLRF BAW

   CLRF QIW

   CLRF WAW

   CLRF YIW

   GOTO KS ; Cycle display

;**************************200ms delay program************************

DELAY  

   NOP

   BANKSEL PIE1

   BCF PIE1,0 ; Disable TMR1 interrupt

   BANKSEL T1CON

   MOVLW 24H ;TMR1 frequency division 1:4

   MOVWF T1CON

   BCF PIR1,0

   MOVLW 0X3C

   MOVWF TMR1H

   MOVLW 0XB0

   MOVWF TMR1L ; Initialize TMR1 to 0X3CB0

   BSF T1CON,0 

LOP 

   BTFSS PIR1,0 ; Check whether the timing time is up

   GOTO LOP

   RETURN

  

;****************************************************** *********

BMA 

   ADDWF PCL,F ;Investigate the offset      

   RETLW 0XC0 ;"0" encoding

   RETLW 0XF9 ;"1" encoding

   RETLW 0XA4 ;"2" encoding

   RETLW 0XB0 ;"3" encoding

   RETLW 0X99 ;"4" encoding

   RETLW 0X92 ;"5" encoding

   RETLW 0X82 ;"6" encoding

   RETLW 0XF8 ;"7" encoding

   RETLW 0X80 ;"8" encoding

   RETLW 0X98 ;"9" encoding

   RETLW 0XFF


;****************************************************** *********

  END ; source program ends

;****************************************************** **********

; The process flow for entering this practical exercise is as follows:

; 1. Create source files and edit source files; Here we introduce a method of creating source files that is different from the previous method. Use the "Notepad" in Windows Accessories to create source files.

; This is a well-known and easy-to-use file editor, and it can easily add Chinese comments. However, there are two points to note. First, the comment before

; The semicolon ”” must be entered in half-width Western characters; secondly, it must be stored in a pre-created dedicated subdirectory with a ”.asm” extension.

; 2. Open MPLAB integrated development environment: First, in the WINDOWS environment, select Start>Programs>Microchip MPLAB>MPLAB command to start MPLAB

; and enter the MPLAB desktop.

; 3. Create a project: Select the menu File>New or Project>New Project, create a new project in a special subdirectory created in advance, and

; Source files created with Notepad are added to the project.

; 4. Build the target files in the project: Select the menu Project > Build All (project > build all files), MPLAB will automatically call MPASM to build the project

; Assemble the source file (.asm) under file management into a hexadecimal target file (.hex).


Keywords:PIC16F877A Reference address:PIC16F877A dynamic digital clock display experiment reference program

Previous article:Design of a real-time temperature and humidity measurement and control device based on PIC16F73 single chip
Next article:Temperature measurement program based on 16F877A and DS18B20

Recommended ReadingLatest update time:2024-11-16 13:29

PIC16F877A development board digital tube dynamic scanning experiment
//************************************************ *************************   #include pic.h #include "../head/config.h" __CONFIG(HS&WDTDIS&LVPDIS&PWRTEN);    //HS oscillation, disable watchdog, low voltage programming shutdown, start delay timer   #define srclk RC3 //Shift register clock (74595: pin 11) #define rcl
[Microcontroller]
PIC16F877A-SPI-TC77 (temperature sensor)
---------------------------------Reference, TCK (0-1024℃) resolution: 0.25℃   TC77: Resolution 0.0625°C         #include pic.h #define CS RC2 void initPORT(); void initMSSP(); void delay(unsigned char time); void display(float data); float ReadTC77(); const unsigned char disp ={0x3f,0
[Microcontroller]
PIC16F877A-SPI-TC77 (temperature sensor)
PIC16F877A - Timer 0
/****************************************************** ******* PIC16F877A_Timer0_Timer *************************************************** ******/ #include "pic.h" __CONFIG(0x3F71);   /****************************************************** ******* Timer 0 initialization function ************************
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号