- 33
- 0
- 约5.43千字
- 约 9页
- 2016-11-27 发布于重庆
- 举报
基于stc89c51單片机的1602液晶简易万年历
基于stc89c51单片机的简易万年历//基于stc89c51单片机的简易万年历设计//zzuli-wuzhipeng#includereg52.h#define uchar unsigned char#define uint unsigned intuchar shi=0,fen=0,miao=0,ri=7,yue=1,Z=1,Y=1,i,K1num; uint nian=2015;uchar count_10ms,K1num;sbit rs=P2^0;sbit rw=P2^1;sbit lcden=P2^2;sbit K1=P3^0;sbit K2=P3^1;sbit K3=P3^2;sbit BEEP=P3^7;void delay(uint x) // 简单延时程序{ uint a,b; for(a=x;a0;a--) for(b=10;b0;b--); }bi(uint t)// 控制响铃时间程序{ int c,n; for(c=0;ct;c++) { for(n=0;n50;n++); BEEP=~BEEP; } return(t);}void write_com(uchar com)// 1602液晶写指令{ P0=com; rs=0; rw=0; lcden=0; delay(10); lcden=1; delay(10); lcden=0; }void write_date(uchar date)//1602液晶写数据{ P0=date; rs=1; rw=0; lcden=0; delay(10); lcden=1; delay(10); lcden=0; }void beep()// 喇叭{ BEEP=0; delay(100); BEEP=1; delay(100);}void naozhong()// 闹钟{ if((Z==shi)(Y==fen)(miao10)) { bi(500); }} void shijian(uint t,add ){ if (t100) { uchar a,b,c,d; a=t/1000+0x30; b=t/100%10+0x30; c=t/10%10+0x30; d=t%10+0x30; write_com(add); write_date( a); write_date( b); write_date( c); write_date( d); } else { uchar m=0,n=0; m=t/10+0x30; n=t%10+0x30; write_com(add); write_date( m); write_date( n); }}void LCD_disp(){ shijian(shi,0x80+0 ); write_com(0x80+2); write_date(0x3a); shijian(fen,0x80+3 ); write_date(0x3a); shijian(miao,0x80+6 ); write_date( 0x2d); write_date( 0x2d); write_date( 0x2d); shijian(Z,0x80+11 ); write_date(0x3a); shijian(Y,0x80+14 ); shijian(nian,0xc0+0 ); write_date( 0x2d); shijian(yue,0xc0+5 ); write_date( 0x2d); shijian(ri,0xc0+8 );}void init()// 1602液晶初始化{ write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); }void timer1_init()// 定时器初始化{ TMOD=0x01; TH0=0x4c;TL0=0x00; EA=1;ET0=1; TR0=1; } void timer0() interrupt 1 using 0// 中断程序{ TH0=0x4c;TL0=0x00; count_10ms++; if (count_10ms==20 ) { count_10ms=0; miao++; if ( miao==60) { miao=0; fen++; if ( fen==60) { fen=0; shi++; if (shi==24)
原创力文档

文档评论(0)