㈠ 基于51单片机的万年历课程设计
你好:
这是我用定时器的方式写出来的万年历程序,LCD1602显示,51单片机控制,能显示日期和时间,并可通过按键调整时间。
参考参考吧,希望我的回答能帮助到你。
㈡ 单片机LCD1602万年历仿真正确,但实际显示不正确,会发生混乱
我看了你说放置有问题,没有看到你的源代码,肯定是程序那里写错了,我也现场仿真了一下看没有问题。
我程序是安装模块化写的,发上来有点乱,想要可以加下QQ370670734我发你参考一下。
这是主程序:
/*****************************************
*
* LCD1602电子钟DS1302
*
*
*
******************************************/
#include"REG52.H"
#include"DS1302.H"
#include"LCD1602.H"sbit Key_out1=P1^3;
sbit Key_out2=P1^4;
sbit Key_out3=P1^5;
sbit Key_out4=P1^6;
sbit LED_out4=P2^2;unsignedcharvalue_mum=0;
unsignedcharVata_Time1[7]={00,29,10,00,00,0,00};
unsignedcharVata_Time2[7];
unsignedcharVata_Time3[3]={00,00,00};
unsignedcharVata_Time4[] ={"QQ:370670734"};
unsignedcharVata_Time5[] ={"158888609310"};unsignedcharcodeTable_out[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};unsignedcharClock_Xtnm;
voidScank_key(void)
{
unsignedcharkey;
unsignedchartemp;P3=0xFE;
temp=P3;
temp=temp&0xF0;
if(temp!=0xF0)
{
Delay_1ms(10);
temp=P3;
temp=temp&0xF0;
if(temp!=0xF0)
{
temp=P3;
switch(temp)
{
case0xEE:key=7;break;
case0xDE:key=8;break;
case0xBE:key=9;break;
case0x7E:key=6;break;
default:break;
}
while(temp!=0xF0)
{
temp=P3;
temp=temp&0xF0;
}
LCD_crye_Pritf(0,4);
Write_LCDcrys_DataCmd(Table_out[key]);
}
}
}voidShuax_ds1302_ReadtemCmd(void)
{
if(Vata_Time1[0]!=Vata_Time2[0])
{
Vata_Time2[0]=Vata_Time1[0];
}
if(Vata_Time1[1]!=Vata_Time2[1])
{
Vata_Time2[1]=Vata_Time1[1];
}
if(Vata_Time1[2]!=Vata_Time2[2])
{
Vata_Time2[2]=Vata_Time1[2];
}LCD_crye_Pritf(0,0);
LCD_Tank_lingCmd(Vata_Time1[2]);
LCD_Pritf(":");
LCD_Tank_lingCmd(Vata_Time1[1]);
LCD_Pritf(":");
LCD_Tank_lingCmd(Vata_Time1[0]);
}
/*
voidLCD_fanyelunx_temkCmd(void)
{
}
*/
voidGont_Caindan_KeyCmd(void)
{
if(Key_out4==0)
{
Delay_1ms(10);
if(Key_out4==0)
{
LED_out4=~LED_out4;
value_mum++;
if(value_mum==4)
value_mum=0;
while(Key_out4==0);
}
}
}voidLCD_Tiaokefanye_Cmd(void)
{
if(value_mum==0)
{
Write_LCDcrys_ByteCmd(0x01);
do
{
Gont_Caindan_KeyCmd();
Read__ds1302_ReadtimeCmd(Vata_Time1);
Shuax_ds1302_ReadtemCmd();
}while(value_mum==0);
}
elseif(value_mum==1)
{
Write_LCDcrys_ByteCmd(0x01);
do
{
Gont_Caindan_KeyCmd();
LCD_crye_Pritf(0,3);
LCD_Tank_lingCmd(Vata_Time3[0]);
LCD_Pritf(":");
LCD_Tank_lingCmd(Vata_Time3[1]);
LCD_Pritf(":");
LCD_Tank_lingCmd(Vata_Time3[2]);
}while(value_mum==1);
}elseif(value_mum==2)
{
Write_LCDcrys_ByteCmd(0x01);
do
{
Gont_Caindan_KeyCmd();
LCD_crye_Pritf(0,1);
LCD_Pritf(Vata_Time4);
}while(value_mum==2);
}elseif(value_mum==3)
{
Write_LCDcrys_ByteCmd(0x01);
do
{
Gont_Caindan_KeyCmd();
LCD_crye_Pritf(0,1);
LCD_Pritf(Vata_Time5);
}while(value_mum==3);
}
}intmain(void)
{
Init_LCDcrysRst();
LCD_crye_Pritf(0,0);
Setup_ds1302_ReadtimeCmd(Vata_Time1);
while(1)
{
//Scank_key();
Gont_Caindan_KeyCmd();
LCD_Tiaokefanye_Cmd();
}
}㈢ 求用单片机+DS1302+LCD1602实现万年历的c语言程序(主要是农历转换)
基于单片机的数字钟(电子万年历)
http://hi..com/dsu5566/blog/item/7cfe0fa480cd14fe9152eec8.html
㈣ 基于单片机的万年历怎么做啊只要求显示日期和时间电路图、程序有谁懂的支援下哇.拜托了!
#include <reg52.h>
#include<stddef.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD1602_FLAG
#define LCD1602_PORT P0
sbit lcd1602_rs=P2^0;
sbit lcd1602_e=P2^2;
sbit lcd1602_rw=P2^1;
sbit lcd1602_busy=P0^7;
sbit key_ch=P3^5;
sbit key_add=P3^6;
sbit key_minus=P3^7;
uchar i,sec,min,h,date,month,flag;
uint year;
uchar *chgstr[7]={" ","sec","min","hour","date","min","year"};
uchar j,k,m,n,o,p;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar timestr[10],datestr[10];
void init();
void delay(uint);
void time_display();
void date_display();
void control();
void time();
/*
************************************
* 函数名称:lcd1602_CheckBusy()
* 函数功能:状态查询
************************************
*/
void lcd1602_CheckBusy()
{
do
{
lcd1602_busy=1;
lcd1602_rs=0;
lcd1602_rw=1;
lcd1602_e=0;
lcd1602_e=1;
}
while(lcd1602_busy);
}
/*
***************************************
* 函数名称: lcd1602_WriteCmd()
* 函数功能:写命令
* 入口参数:命令字
* 出口参数:无
***************************************
*/
void lcd1602_WriteCmd(const uchar cmd)
{
lcd1602_CheckBusy();
lcd1602_rs=0;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=cmd;
lcd1602_e=0;
}
/*
*******************************************
* 函数名称:lcd1602_WriteData()
* 函数功能:写数据
* 入口参数:c--待写数据
* 出口参数:无
*********************************************
*/
void lcd1602_WriteData(const uchar c)
{
lcd1602_CheckBusy();
lcd1602_rs=1;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=c;
lcd1602_e=0;
}
/*
***********************************************
* 函数名称:lcd1602_Init()
* 函数功能:初始化LCD
* 入口参数:无
* 出口参数:无
***********************************************
*/
void lcd1602_Init()
{
lcd1602_WriteCmd(0x38); //显示模式为8位2行5*7点阵
lcd1602_WriteCmd(0x0c); //display enable,flag enable,flash enable,
lcd1602_WriteCmd(0x06); //flag move to right,screen don't move
lcd1602_WriteCmd(0x01); //clear screen
}
/*
************************************************
* 函数名称:lcd1602_Display()
* 函数功能: 字符显示
* 入口参数:ptr--字符或字符串指针
* 出口参数:无
* 说 明:用户可通过以下方式来调用:
* 1)lcd1602_Display("Hello,world!");
* 2) INT8U 存储类型 txt[]="要显示的字符串";
* 或者 INT8U 存储类型 txt[]={'t','x','t',..,'\0'};
* INT8U *ptr;
* ptr=&txt;
* lcd1602_Display(ptr);
* 或 lcd1602_Display(txt);
* 或 lcd1602_Display(&txt);
************************************************
*/
void lcd1602_Display(const uchar *ptr,uchar line,uchar xaddr)
{
uchar data i=0;
uchar *data q;
q=ptr;
switch(line)
{
case 0:
lcd1602_WriteCmd(0x80+xaddr);
while(q!=NULL && (*q!='\0') && i<16)
{
lcd1602_WriteData(*q);
q++;
i++;
}
break;
case 1:
lcd1602_WriteCmd(0xc0+xaddr);
while(q!=NULL && (*q!='\0') && i<16)
{
lcd1602_WriteData(*q);
q++;
i++;
}
break;
}
}
void main()
{
lcd1602_Init();
init();
while(1)
{
time_display();
date_display();
control();
}
}
void init()
{
i=0;
sec=0;
min=30;
h=7;
date=17;
month=10;
year=2017;
flag=0;
EA=1;
ET0=1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void time_display()
{
timestr[7]=0x30+sec%10;
timestr[6]=0x30+sec/10;
timestr[5]=':';
timestr[4]=0x30+min%10;
timestr[3]=0x30+min/10;
timestr[2]=':';
timestr[1]=0x30+h%10;
timestr[0]=0x30+h/10;
timestr[8]=0;
lcd1602_Display(timestr,1,3);
}
void date_display()
{
datestr[9]=0x30+date%10;
datestr[8]=0x30+date/10;
datestr[7]=':';
datestr[6]=0x30+month%10;
datestr[5]=0x30+month/10;
datestr[4]=':';
datestr[3]=0x30+year%10;
datestr[2]=0x30+year/10%10;
datestr[1]=0x30+year/100%10;
datestr[0]=0x30+year/1000;
lcd1602_Display(datestr,0,2);
}
void control()
{
if(!key_ch)
{
delay(5);
if(!key_ch)
{
flag++;
TR0=0;
if(flag==7)
{flag=0;TR0=1;lcd1602_Init();}
lcd1602_Display(chgstr[flag],1,12);
}
}
while(!key_ch);
if(flag==1&&key_add==0)
{
while(!key_add);
sec++;
if(sec==60)
sec=0;
}
if(flag==1&&key_minus==0)
{
while(!key_minus);
sec--;
if(sec==-1)
sec=59;
}
if(flag==2&&key_add==0)
{
while(!key_add);
min++;
if(min==60)
min=0;
}
if(flag==2&&key_minus==0)
{
while(!key_minus);
min--;
if(min==-1)
min=59;
}
if(flag==3&&key_add==0)
{
while(!key_add);
h++;
if(h==24)
h=0;
}
if(flag==3&&key_minus==0)
{
while(!key_minus);
h--;
if(h==-1)
h=23;
}
if(flag==4&&key_add==0)
{
while(!key_add);
date++;
if(date==29)
if((year%4!=0)&&(month==2))
date=1;
if(date==30)
if((year%4==0)&&(month==2))
date=1;
if(date==31)
if((month==4)||(month==6)||(month==9)||(month==11))
date=1;
if(date==32)
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
date=1;
}
if(flag==4&&key_minus==0)
{
while(!key_minus);
if(date>1)date--;
}
if(flag==5&&key_add==0)
{
while(!key_add);
month++;
if(month==13)
month=1;
}
if(flag==5&&key_minus==0)
{
while(!key_minus);
month--;
if(month==0)
month=12;
}
if(flag==6&&key_add==0)
{
while(!key_add);
year++;
if(year==99)
year=1;
}
if(flag==6&&key_minus==0)
{
while(!key_minus);
year--;
if(year==0)
year=99;
}
}
void T0_rpt() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
i++;
time();
}
void time()
{
if(i==20)
{
i=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
h++;
if(h==24)
{
h=0;
min=0;
sec=0;
date++;
if(date==29)
if((year%4!=0)&&(month==2))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==30)
if((year%4==0)&&(month==2))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==31)
if((month==4)||(month==6)||(month==9)||(month==11))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==32)
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
}
}
}
}
}
㈤ 单片机课程设计万年历方案论证怎么写
方案论证主要是写你做设计时有几种可选的方案比如用stc51单片机还是lpc51或者用pic还有时钟芯片选择还有显示用1284还是1602等等
说说各自的优缺点最后经过对比选择较合适的那一种,比如从成本的对比,控制的对比,性能的对比还有就是可行性,希望帮到你
㈥ 51单片机+DS1302+LCD1602+DS18B20实现年月日星期时分秒和温度图像显示名字缩写(带按键调节)
这是一个标准的由51单片机设计的万年历的配置,液晶屏换成12864,配置为LCD12864+DS1302+DS18B20,而这种题目适合用proteus仿真实现,又适合作毕业设计题目,上网络文库搜索,有现成的论文,又有代码,下面的仿真图可参考。
㈦ 万年历51单片机LCD1602不显示是什么原因
给你一个显示的例程,你看看你自己的程序或硬件错在何处。
#defineLCD1602_FLAG
#defineLCD1602_PORTP0
#include<reg51.h>
#include<stddef.h>
#defineucharunsignedchar
sbitlcd1602_rs=P2^0;
sbitlcd1602_e=P2^2;
sbitlcd1602_rw=P2^1;
sbitlcd1602_busy=P0^7;
ucharstr[]="ThisisKeyTest";
ucharkeyval,keystr[16];
voiddelay(uchara)
{
uchari;
while(a--)for(i=0;i<120;i++);
}
/*
************************************
*函数名称:lcd1602_CheckBusy()
*函数功能:状态查询
************************************
*/
voidlcd1602_CheckBusy()
{
do
{
lcd1602_busy=1;
lcd1602_rs=0;
lcd1602_rw=1;
lcd1602_e=0;
lcd1602_e=1;
}
while(lcd1602_busy);
}
/*
***************************************
*函数名称:lcd1602_WriteCmd()
*函数功能:写命令
*入口参数:命令字
*出口参数:无
***************************************
*/
voidlcd1602_WriteCmd(constucharcmd)
{
lcd1602_CheckBusy();
lcd1602_rs=0;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=cmd;
lcd1602_e=0;
}
/*
*******************************************
*函数名称:lcd1602_WriteData()
*函数功能:写数据
*入口参数:c--待写数据
*出口参数:无
*********************************************
*/
voidlcd1602_WriteData(constucharc)
{
lcd1602_CheckBusy();
lcd1602_rs=1;
lcd1602_rw=0;
lcd1602_e=1;
LCD1602_PORT=c;
lcd1602_e=0;
}
/*
***********************************************
*函数名称:lcd1602_Init()
*函数功能:初始化LCD
*入口参数:无
*出口参数:无
***********************************************
*/
voidlcd1602_Init()
{
lcd1602_WriteCmd(0x38); //显示模式为8位2行5*7点阵
lcd1602_WriteCmd(0x0c);//displayenable,flagenable,flashenable,
lcd1602_WriteCmd(0x06);//flagmovetoright,screendon'tmove
lcd1602_WriteCmd(0x01);//clearscreen
}
/*
************************************************
*函数名称:lcd1602_Display()
*函数功能:字符显示
*入口参数:ptr--字符或字符串指针
*出口参数:无
*说明:用户可通过以下方式来调用:
*1)lcd1602_Display("Hello,world!");
*2)INT8U存储类型txt[]="要显示的字符串";
*或者INT8U存储类型txt[]={'t','x','t',..,'