第一篇:数字钟课程设计程序
#include
void chuanshu(void);
void shuchu(void);
void saomiao(void);
void delay(void);
unsigned int t;
unsigned char m;
unsigned char shi,fen,miao;
unsigned char code duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};unsigned char code wei[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned charxianshi[8]={0,0,0,0,0,0,0,0};
sbit DS=P2^2;
sbit ST_CP=P2^3;
sbit SH_CP=P2^4;
sbit key1=P3^2;
sbit key2=P3^3;
sbit key3=P3^4;
sbit key4=P3^5;
sbit niaoling=P1^0;
sbit dingshi=P1^1;
void delay(void)
{
char i,j;
for(i=0;i<50;i++)
for(j=0;j<100;j++);
}
void chuanshu(void)
{
unsigned char b,c,num;
if(b==0)
{
b++;
num=wei[m];//把位选放在第二个74hc595芯片上
for(c=0;c<8;c++)
{SH_CP=0;
DS=num&0x80;
num=num<<1;
SH_CP=1;//上升沿发生移位
}
}
if(b==1)
{
b--;
if(m==2||m==5)
{num=0xbf;}
else
{
num=duan[xianshi[m]];}
for(c=0;c<8;c++)
{SH_CP=0;
DS=num&0x80;
num=num<<1;
SH_CP=1;//数据在SH_CP的上升沿输入}
}
m++;
if(m==8)
{m=0;
}
}
void shuchu(void)
{ ST_CP=0;
ST_CP=1;//上升沿将数据送到输出锁存器
}
void saomiao(void)
{
if(key1==0)
{
delay();
if(key1==0)
{
miao=0;
while(key1==0);
}
}
xianshi[0]=miao%10;xianshi[1]=miao/10;
if(key2==0){
delay();
if(key2==0){
fen++;
while(key2==0);if(fen==60){
fen=0;}
}
}
xianshi[3]=fen%10;xianshi[4]=fen/10;
if(key3==0){
delay();
if(key3==0){
shi++;
while(key3==0);if(shi==24){
shi=0;}
}
}
xianshi[6]=shi%10;xianshi[7]=shi/10;
if(key4==0){
delay();
if(key4==0){
miao=0;fen=0;shi=0;}
}
}
void main(void)
{
TMOD=0X01;
TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;
ET0=1;
TR0=1;
while(1)
{
saomiao();
chuanshu();shuchu();
}
}
void time0()interrupt 1{
t++;
if(t==20)
{t=0;
miao++;
if(miao==60){miao=0;fen++;
if(fen==60){fen=0;shi++;
if(shi==24){shi=0;}}}
}
}
第二篇:C语言课程设计数字钟程序
C语言数字钟程序
#include“stdio.h” void clock(int t);void main(){ int t,i,j,n;for(t=0;t<10;t++){ clock(t);sound(590);for(n=0;n<4;n++){ delay(100000000);} nosound();for(n=0;n<6;n++){ delay(100000000);} for(j=8;j<=18;j++){ for(i=1;i<=80;i++){ gotoxy(i,j);putchar(0);} } } } void clock(int t){ int i,j;textcolor(11);if(t==0){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<11;i++){ gotoxy(51,8+i);cprintf(“%c”,14);} for(j=0;j<11;j+=10){ for(i=0;i<8;i++){ gotoxy(59-i,8+j);cprintf(“%c”,14);} } } if(t==1){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} } if(t==2){ for(j=0;j<2;j++){ for(i=0;i<6;i++){ gotoxy(60-j*8,8+i+j*5);cprintf(“%c”,14);} } for(j=0;j<11;j+=5){ for(i=0;i<9;i++){ gotoxy(60-i,8+j);cprintf(“%c”,14);} } } if(t==3){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(j=0;j<11;j+=5){ for(i=0;i<8;i++){ gotoxy(59-i,8+j);cprintf(“%c”,14);} } } if(t==4){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<6;i++){ gotoxy(52,8+i);cprintf(“%c”,14);} for(i=0;i<8;i++){ gotoxy(59-i,13);cprintf(“%c”,14);} } if(t==5){ for(j=0;j<2;j++){ for(i=0;i<6;i++){ gotoxy(52+j*8,8+i+j*5);cprintf(“%c”,14);} } for(j=0;j<11;j+=5){ for(i=0;i<9;i++){ gotoxy(60-i,8+j);cprintf(“%c”,14);} } } if(t==6){ for(j=0;j<2;j++){ for(i=0;i<6;i++){ gotoxy(52+j*8,8+i+j*5);cprintf(“%c”,14);} } for(i=0;i<6;i++){ gotoxy(52,13+i);cprintf(“%c”,14);} for(j=0;j<11;j+=5){ for(i=0;i<9;i++){ gotoxy(60-i,8+j);cprintf(“%c”,14);} } } if(t==7){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<8;i++){ gotoxy(59-i,8);cprintf(“%c”,14);} } if(t==8){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<11;i++){ gotoxy(52,8+i);cprintf(“%c”,14);} for(j=0;j<11;j+=5){ for(i=0;i<8;i++){ gotoxy(59-i,8+j);cprintf(“%c”,14);} } } if(t==9){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<6;i++){ gotoxy(52,8+i);cprintf(“%c”,14);} for(j=0;j<2;j++){ for(i=0;i<8;i++){ gotoxy(59-i,8+j*5);cprintf(“%c”,14);} } } }
第三篇:数字钟程序-c语言课程设计
#include“stdio.h” void clock(int t);void main(){ int t,i,j,n;for(t=0;t<10;t++){ clock(t);sound(590);for(n=0;n<4;n++){ delay(100000000);} nosound();for(n=0;n<6;n++){ delay(100000000);} for(j=8;j<=18;j++){ for(i=1;i<=80;i++){ gotoxy(i,j);putchar(0);} } } } void clock(int t){ int i,j;textcolor(11);if(t==0){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<11;i++){ gotoxy(51,8+i);cprintf(“%c”,14);} for(j=0;j<11;j+=10){ for(i=0;i<8;i++){ gotoxy(59-i,8+j);cprintf(“%c”,14);} } } if(t==1){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} } if(t==2){ for(j=0;j<2;j++){ for(i=0;i<6;i++){ gotoxy(60-j*8,8+i+j*5);cprintf(“%c”,14);} } for(j=0;j<11;j+=5){ for(i=0;i<9;i++){ gotoxy(60-i,8+j);cprintf(“%c”,14);} } } if(t==3){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(j=0;j<11;j+=5){ for(i=0;i<8;i++){ gotoxy(59-i,8+j);cprintf(“%c”,14);} } } if(t==4){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<6;i++){ gotoxy(52,8+i);cprintf(“%c”,14);} for(i=0;i<8;i++){ gotoxy(59-i,13);cprintf(“%c”,14);} } if(t==5){ for(j=0;j<2;j++){ for(i=0;i<6;i++){ gotoxy(52+j*8,8+i+j*5);cprintf(“%c”,14);} } for(j=0;j<11;j+=5){ for(i=0;i<9;i++){ gotoxy(60-i,8+j);cprintf(“%c”,14);} } } if(t==6){ for(j=0;j<2;j++){ for(i=0;i<6;i++){ gotoxy(52+j*8,8+i+j*5);cprintf(“%c”,14);} } for(i=0;i<6;i++){ gotoxy(52,13+i);cprintf(“%c”,14);} for(j=0;j<11;j+=5){ for(i=0;i<9;i++){ gotoxy(60-i,8+j);cprintf(“%c”,14);} } } if(t==7){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<8;i++){ gotoxy(59-i,8);cprintf(“%c”,14);} } if(t==8){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<11;i++){ gotoxy(52,8+i);cprintf(“%c”,14);} for(j=0;j<11;j+=5){ for(i=0;i<8;i++){ gotoxy(59-i,8+j);cprintf(“%c”,14);} } } if(t==9){ for(i=0;i<11;i++){ gotoxy(60,8+i);cprintf(“%c”,14);} for(i=0;i<6;i++){ gotoxy(52,8+i);cprintf(“%c”,14);} for(j=0;j<2;j++){ for(i=0;i<8;i++){ gotoxy(59-i,8+j*5);cprintf(“%c”,14);} } } }
第四篇:基于单片机的数字钟课程设计程序
#include
uchar num;
void delayms(uint z){ uint x,y;for(x=z;x>0;x--)
for(y=110;y>0;y--);}
void write_com(uchar com){ lcdrs=0;P0=com;delayms(5);lcden=0;}
void write_data(uchar date){ lcdrs=1;P0=date;delayms(5);lcden=1;delayms(5);lcden=0;}
void init(){ lcden=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);}
void main()
//定义使能端、命令选择端
//延时函数
//写入命令函数
//写入数据 //初始化LCD
{
} init();write_com(0x80);for(num=0;num<11;num++){ write_data(table[num]);delayms(5);} write_com(0x80+0x40);for(num=0;num<13;num++){ write_data(table[num]);delayms(5);} while(1);
第五篇:基于单片机的数字钟课程设计程序
#include
#define uchar unsigned char #define uint unsigned int
uchar code table[]=“I LOVE YOU!”;uchar code table1[]=“2014:06:14”;sbit lcden=P3^5;
sbit lcdrs=P3^4;uchar num;
void delayms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);}
void write_com(uchar com){
lcdrs=0;
P0=com;
delayms(5);
lcden=0;
}
void write_data(uchar date){
lcdrs=1;
P0=date;
delayms(5);
lcden=1;
delayms(5);
lcden=0;
}
void init()
{
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void main()//定义使能端、命令选择端//延时函数//写入命令函数//写入数据 //初始化LCD
{}init();write_com(0x80);for(num=0;num<11;num++){write_data(table[num]);delayms(5);} write_com(0x80+0x40);for(num=0;num<13;num++){write_data(table[num]);delayms(5);} while(1);