C语言秒表程序

C语言秒表程序,第1张

下面程序你试毁散下,延时函数自己加一下,几毫秒到几十毫秒#include"reg51.h"unsigned char i,j,m,xa[4];unsigned char table1[]={0x01,0x02,0x04,0x08};unsigned char table2[]={0x3fev0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};main(){TMOD=0x01;TF0=1;TR0=1;IE=0x82; EX0=1;m=0;while(1) { for(j=0;j<4;j++) {P0=table1[j];x=a[j];P1=table2[x];拍余渣 delay(); //这里加个几袭悄毫秒的延时,函数体自己写下 }} }timer1() interrupt 1{TH0=0x3C; TL0=0xB0; i++; if(i==20) {i=0;m++;a[3]=m/1000;a[2]=m/100%10;a[1]=m/10%10;a[0]=m%10;}}

直接发给你把

PROCESSOR 16C74

INCLUDE "P16C74B.INC "

SECEQU 0X23

MSEC EQU 0x24

TEMP1 EQU 0X22

FLAG2 EQU 0X28

ORG 0x00

GOTO START

ORG 0x04设定中断向量

BCF STATUS,RP0

BTFSC INTCON,T0IF 判断TIER0中断标志位是否被设置

GOTO TMR0_ISR 若是,则去执行TIMER0中断子程序

RETFIE

START:

CALL PIC_INIT 去设置端口、TIMER0工作滑消模式

BSF INTCON,GIE

BSF INTCON,T0IE

MAIN_LOOP:

程序的主体是个无限循环

BTFSC FLAG2,7

CALL DISPLAY

GOTO MAIN_LOOP

PIC_INIT:

CLRF INTCON

BCF INTCON,T0IE

BSF STATUS,RP0

MOVLW B'00000000'梁掘B’XXXXXXXX’表示单引号中橡让核的数是二

MOVWF TRISB

MOVLW B'00000000'

MOVWF TRISC

BCF STATUS,RP0

MOVLW B'11000000'B’XXXXXXXX’表示单引号中的数是二

MOVWF PORTB

MOVLW B'11000000'

MOVWF PORTC

BSF STATUS,RP0

MOVLW B'11000100'

MOVWF OPTION_REG 对TIMER0工作模式进行设置,32分频

BCF STATUS,RP0

MOVLW 0X06

MOVWF TMR0

CLRF SEC

CLRF MSEC

CLRF TEMP1

CLRF FLAG2

RETURN

TMR0_ISR:

CLRWDT

BSF FLAG2,7

BCF INTCON,T0IF

MOVLW 0X06

MOVWF TMR0

CLRWDT

INCF TEMP1,1

MOVF TEMP1,0

SUBLW .125 125-TEMP

BTFSS STATUS,2

RETFIE

CLRWDT

CLRF TEMP1

INCF MSEC,1

RETFIE

DISPLAY:

MOVF MSEC,0

SUBLW .10

BTFSS STATUS,2

GOTO NEXT_1

CLRWDT

CLRF MSEC

INCF SEC,1

MOVF SEC,0

SUBLW .6

BTFSS STATUS,2

GOTO NEXT_1

CLRF SEC

NEXT_1:

CLRWDT

MOVF MSEC,W

CALL CHAR_CODE

MOVWF PORTC

MOVF SEC,W

CALL CHAR_CODE

MOVWF PORTB

BCF FLAG2,7

RETURN

CHAR_CODE:

ADDWF PCL,1PCL+=W

RETLW B'11000000' Code for 0

RETLW B'11111001' Code for 1

RETLW B'10100100' Code for 2

RETLW B'10110000' Code for 3

RETLW B'10011001' Code for 4

RETLW B'10010010' Code for 5

RETLW B'10000010' Code for 6

RETLW B'11111000' Code for 7

RETLW B'10000000' Code for 8

RETLW B'10010000' Code for 9

END


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12527374.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存