谁能告诉我51单片机简单的led数码管时钟程序 24小时制的(c语言版的)

谁能告诉我51单片机简单的led数码管时钟程序 24小时制的(c语言版的),第1张

#include "reg52.h"

#define uint unsigned int

#define uchar unsigned char

uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}

uchar shi,fen,miao

uchar time

void delay(uint x)

{

uint y

for(x>0x--)

{

for(y=0y<124y++)

}

}

void display(uchar shi,uchar fen,uchar miao)

{

P2=0 //位码

P0=(tab[shi/10]) //段码

delay(2)

P2=1

P0=(tab[shi%10])

delay(2)

P2=2 //位码

P0=0x40 //段码

delay(2)

P2=3 //位码

P0=(tab[fen/10]) //段码

delay(2)

P2=4

P0=(tab[fen%10])

delay(2)

P2=5 //位码

P0=0x40 //段码

delay(2)

P2=6 //位码

P0=(tab[miao/10]) //段码

delay(2)

P2=7

P0=(tab[miao%10])

delay(2)

}

void main()

{

TMOD=0x01

TH0=(65536-50000)/256

TL0=(65536-50000)%256

EA=1

ET0=1

TR0=1

while(1)

{

if(time==20)

{

time=0

miao++

if(miao==60)

{

miao=0

fen++

if(fen==60)

{

fen=0

shi++

if(shi==24)

shi=0

}

}

}

display(shi,fen,miao)

}

}

void timer0() interrupt 1

{

TH0=(65536-50000)/256

TL0=(65536-50000)%256

time++

}

/*还有什么不明白继续追加*/

汇编可以么LED_1EQU30HLED_2EQU31HLED_3EQU32HLED_4EQU33HLED_5EQU34HLED_6EQU35HLED_7EQU36HLED_8EQU37HTIMEREQU38HMODEEQU39H模式判断FLASHEQU40H闪烁判断1亮0不亮BUTTON1EQU41H按钮开关BUTTON2EQU42H按钮开关BUTTON3EQU43H按钮开关BUTTON4EQU44H按钮灵敏CS1EQUP2.0CS2EQUP2.1WR_ONEQUP2.2-------------------------------按钮-------------------------------IN_SETEQUP2.3IN_GALEQUP2.4IN_SUBEQUP2.5-------------------------------主程序接口:D0-D7接P1.0-P1.7CS1P2.0CS2P2.1WRP2.2-------------------------------ORG0000HJMPMAINORG000BHJMPT0INTORG0030HMAIN:CALLSYSINIT-------------------------------START:JMPSTART-------------------------------计时器子程序-------------------------------T0INT:MOVTH0,#03CHMOVTL0,#0AFHCALLSHOWDJNZBUTTON4,T0INT1MOVBUTTON4,#10CALLAJ1CALLAJ3CALLAJ5T0INT1:DJNZTIMER,T0INTENDCALLMODE_PD1T0INTEND:RETI-------------------------------模式判断-------------------------------MODE_PD1:MOVA,MODECJNEA,#0,MODE_PD2MOVTIMER,#200CALLCADDJMPMODE_PDENDMODE_PD2:MOVA,MODECJNEA,#1,MODE_PD3MOVTIMER,#50CALLFLASH1JMPMODE_PDENDMODE_PD3:MOVA,MODECJNEA,#2,MODE_PD4MOVTIMER,#50CALLFLASH3JMPMODE_PDENDMODE_PD4:MOVA,MODECJNEA,#3,MODE_PDENDMOVTIMER,#50CALLFLASH5MODE_PDEND:RET-------------------------------按钮-------------------------------AJ1:MOVA,BUTTON1CJNEA,#1,AJ2JBIN_SET,AJENDMOVBUTTON1,#0CALLSAVE2MOVTIMER,#1INCMODEMOVA,MODECJNEA,#4,AJENDMOVMODE,#0MOVTIMER,#100JMPAJENDAJ2:MOVA,BUTTON1CJNEA,#0,AJ1JNBIN_SET,AJENDMOVBUTTON1,#1JMPAJENDAJ3:MOVA,BUTTON2CJNEA,#1,AJ4JBIN_GAL,AJENDMOVBUTTON2,#0CALLGAL1JMPAJENDAJ4:MOVA,BUTTON2CJNEA,#0,AJ3JNBIN_GAL,AJENDMOVBUTTON2,#1JMPAJENDAJ5:MOVA,BUTTON3CJNEA,#1,AJ6JBIN_SUB,AJENDMOVBUTTON3,#0CALLSUB1JMPAJENDAJ6:MOVA,BUTTON3CJNEA,#0,AJ5JNBIN_SUB,AJENDMOVBUTTON3,#1JMPAJENDAJEND:RET-------------------------------加法-------------------------------GAL1:MOVA,MODECJNEA,#3,GAL2INC58HMOVA,58HCJNEA,#10,GALENDMOV58H,#0INC57HMOVA,57HCJNEA,#6,GALENDMOV57H,#0GAL2:MOVA,MODECJNEA,#2,GAL3INC55HMOVA,55HCJNEA,#10,GALENDMOV55H,#0INC54HMOVA,54HCJNEA,#6,GALENDMOV54H,#0GAL3:MOVA,MODECJNEA,#1,GALENDINC52HMOVA,52HCJNEA,#10,GAL32MOV52H,#0INC51HGAL32:CJNEA,#4,GALENDMOVA,51HCJNEA,#2,GALENDMOV52H,#0MOV51H,#0GALEND:CALLSAVE2RET-------------------------------减法-------------------------------SUB1:MOVA,MODECJNEA,#3,SUB2DEC58HMOVA,58HCJNEA,#-1,SUBENDMOV58H,#9DEC57HMOVA,57HCJNEA,#-1,SUBENDMOV57H,#5SUB2:MOVA,MODECJNEA,#2,SUB3DEC55HMOVA,55HCJNEA,#-1,SUBENDMOV55H,#9DEC54HMOVA,54HCJNEA,#-1,SUBENDMOV54H,#5SUB3:MOVA,MODECJNEA,#1,SUBENDDEC52HMOVA,52HCJNEA,#-1,SUBENDMOV52H,#9DEC51HMOVA,51HCJNEA,#-1,GALENDMOV52H,#3MOV51H,#2SUBEND:CALLSAVE2RET-------------------------------闪烁-------------------------------FLASH1:MOVA,FLASHCJNEA,#0,FLASH2MOV51H,LED_1MOV52H,LED_2MOVLED_1,#11MOVLED_2,#11MOVFLASH,#1JMPFLASHENDFLASH2:MOVA,FLASHCJNEA,#1,FLASHENDMOVLED_1,51HMOVLED_2,52HMOVFLASH,#0JMPFLASHEND小时闪烁FLASH3:MOVA,FLASHCJNEA,#0,FLASH4MOV54H,LED_4MOV55H,LED_5MOVLED_4,#11MOVLED_5,#11MOVFLASH,#1JMPFLASHENDFLASH4:MOVA,FLASHCJNEA,#1,FLASHENDMOVLED_4,54HMOVLED_5,55HMOVFLASH,#0JMPFLASHEND分钟闪烁FLASH5:MOVA,FLASHCJNEA,#0,FLASH6MOV57H,LED_7MOV58H,LED_8MOVLED_7,#11MOVLED_8,#11MOVFLASH,#1JMPFLASHENDFLASH6:MOVA,FLASHCJNEA,#1,FLASHENDMOVLED_7,57HMOVLED_8,58HMOVFLASH,#0秒钟闪烁FLASHEND:RET-------------------------------数据加减-------------------------------CADD:INCLED_8MOVA,LED_8CJNEA,#10,CADDENDMOVLED_8,#0INCLED_7MOVA,LED_7CJNEA,#6,CADDENDMOVLED_7,#0INCLED_5MOVA,LED_5CJNEA,#10,CADDENDMOVLED_5,#0INCLED_4MOVA,LED_4CJNEA,#6,CADDENDMOVLED_4,#0INCLED_2MOVA,LED_2CJNEA,#10,CADD2MOVLED_2,#0INCLED_1CADD2:CJNEA,#4,CADDENDMOVA,LED_1CJNEA,#2,CADDENDCALLSYSINITCADDEND:CALLSAVE1RET-------------------------------数据显示-------------------------------SHOW:MOVR0,#30HMOVR1,#8MOVR2,#01111111BSHOW1:MOVA,R2MOVP0,ACALLCS2_ONRRAMOVR2,AMOVA,@R0MOVCA,@A+DPTRMOVP0,ACALLCS1_ONCALLDELAYMOVP0,#0FFHCALLCS1_ONCALLCS2_ONINCR0DJNZR1,SHOW1RETCS1_ON:CLRWR_ONCLRCS1SETBWR_ONSETBCS1RETCS2_ON:CLRWR_ONCLRCS2SETBWR_ONSETBCS2RET-------------------------------数据储存-------------------------------SAVE1:MOV51H,LED_1MOV52H,LED_2MOV54H,LED_4MOV55H,LED_5MOV57H,LED_7MOV58H,LED_8RETSAVE2:MOVLED_1,51HMOVLED_2,52HMOVLED_4,54HMOVLED_5,55HMOVLED_7,57HMOVLED_8,58HRET-------------------------------数据初始化-------------------------------SYSINIT:MOVLED_1,#0MOVLED_2,#0MOVLED_3,#10MOVLED_4,#0MOVLED_5,#0MOVLED_6,#10MOVLED_7,#0MOVLED_8,#0CALLSAVE1MOVTIMER,#200MOVMODE,#0MOVFLASH,#0MOVBUTTON1,#1MOVBUTTON2,#1MOVBUTTON3,#1MOVBUTTON4,#3MOVTH0,#03CHMOVTL0,#0AFHSETBTR0SETBET0SETBEAMOVDPTR,#TABRET-------------------------------延迟-------------------------------DELAY:MOVR6,#255DJNZR6,$RET-------------------------------段码-------------------------------TAB:DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0BFH,0FFH0-"0"1-"1"2-"2"9-"9"10-"-"11-""END


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存