㈠ 基於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',..,'