基于51单片机万年历C语言程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

智芯锐电子:音乐文件#defineucharunsignedchar#defineuintunsignedint/*****************************************************************************///扬声器定义sbitbeep=P3^7;//扬声器/*****************************************************************************///温度传感器定义sbitDQ=P2^0;//ds18B20uinttvalue;//温度值uchartflag,flagdat,t,hh1;//温度正负标志/*****************************************************************************///键盘引脚定义//sbitKEY_1=P2^7;//左上,在音乐文件SoundPlay.h中已定义sbitKEY_2=P2^6;//左下sbitKEY_3=P2^5;//右上sbitKEY_4=P2^4;//右下/****************************************************************************///定义DS1302时钟接口sbitclock_clk=P2^1;//ds1302_clk(时钟线)sbitclock_dat=P2^2;//ds1302_dat(数据线)sbitclock_Rst=P2^3;//ds1302_Rst(复位线)//定义累加器A中的各位sbita0=ACC^0;sbita1=ACC^1;sbita2=ACC^2;sbita3=ACC^3;sbita4=ACC^4;sbita5=ACC^5;sbita6=ACC^6;sbita7=ACC^7;/****************************************************************************///定义全局变量unsignedcharyy,mo,dd,xq,hh,year,year1;//定义时间映射全局变量(专用寄存器)unsignedcharshi,ge,sec_temp,min_temp,hour_temp,secl,selx,e=0,hh1,mm1,k,n1,n2,mm,ss,n;bitw=0;//调时标志位staticunsignedcharmenu=0;//定义静态小时更新用数据变量staticunsignedcharkeys=0;//定义静态小时更新用数据变量staticunsignedchartimecount=0;//定义静态软件计数器变量/****************************************************************************///-----------------------------------------------智芯锐电子:并口相关设定//#defineBUSY_FLAGP0_7//液晶模块忙标志#defineMPU_RS_CHP1_5//寄存器选择输入#defineMPU_RW_CHP1_6//读写控制#defineMPU_ENABLEP1_7//使能控制#defineLCD_DATAP0//液晶数据口//-----------------------------------------------#defineLOW0//低电平#defineHIGH1//高电平#defineOFF0//逻辑关#defineON1//逻辑开//-----------------------------------------------//液晶模块指令集定义#definecClearDisplay0x01//清显示指令#definecEntryModeSet0x06//设置输入模式#definecDisplayOnCtrl0x0c//设置开显控制#definecFunctionSetB0x30//功能设定(基本指令)#definecFunctionSetE0x34//功能设定(扩充指令)#definecFuncDrawOn0x36//设置绘图功能//-----------------------------------------------ucharxdatalcdPosX,lcdPosY;//X,Y坐标ucharxdatahalfScr,halfLineCnt,basicBlock;//半屏,半屏行数,N*8块//-----------------------------------------------//子程序声明和用法bitscanKey1(void);//按键1检测voidprocKey(void);//按键处理子程序voidlcdInit(void);//初始化LCD子程序voidlcdClear(void);//清除LCD文本屏幕子程序voidlcdWriteCommand(ucharCommand);//写入控制命令到LCD子程序//输入参数:LCD控制指令voidlcdWriteData(ucharData);//写入显示数据到LCD子程序//输入参数:显示数据voidcheckLcdBusy(void);//检测LCD忙碌子程序voiddisplayPhoto(uchar*bmp,ucharbmpCls);//全屏显示图形子程序//输入参数:*bmp=图形数据//bmpCls=清除图形屏幕选项(OFF为不清屏,即显示图形,ON为清屏)智芯锐电子:(ucharCX,CY,width);//字符反白显示//输入参数:CX=要反白字符的行(0-3)//CY=要反白字符的列(0-7)//width=要反白字符的长度(1-16)voidwrPosition(void);//坐标写入子程序voiddispString(ucharX,Y,speed,uchar*msg);//显示字符串子程序//输入参数:X=行(0-3),Y=列(0-7),speed=显示速度(毫秒),msg=字符数据voidbeepBl(void);//蜂鸣器响一声子程序voiddelayMs(ucharms);//延时(毫秒)子程序//输入参数:毫秒数voiddelaySec(ucharsec);//延时(秒)子程序//输入参数:秒数voidinit_dz();voidclear_img();//===============================================//===============================================voidlcdInit(void){lcdWriteCommand(cFunctionSetE);lcdWriteCommand(cFunctionSetB);lcdClear();lcdWriteCommand(cEntryModeSet);lcdWriteCommand(cDisplayOnCtrl);if(k==1){clear_img();lcdClear();}if(k==0){lcdClear();clear_img();init_dz();}}//===============================================voidlcdClear(void){lcdWriteCommand(cClearDisplay);}//===============================================voidlcdWriteCommand(ucharCommand){checkLcdBusy();MPU_RS_CH=LOW;智芯锐电子:=LOW;LCD_DATA=Command;MPU_ENABLE=HIGH;delayMs(1);MPU_ENABLE=LOW;}//===============================================voidlcdWriteData(ucharData){checkLcdBusy();MPU_RS_CH=HIGH;MPU_RW_CH=LOW;LCD_DATA=Data;MPU_ENABLE=HIGH;delayMs(1);MPU_ENABLE=LOW;}//===============================================voidcheckLcdBusy(void){LCD_DATA=0xff;MPU_RS_CH=LOW;MPU_RW_CH=HIGH;MPU_ENABLE=HIGH;while(BUSY_FLAG);MPU_ENABLE=LOW;}//===============================================voiddisplayPhoto(uchar*bmp,ucharbmpCls){lcdPosX=0x80;halfScr=2;for(;halfScr!=0;halfScr--){lcdPosY=0x80;halfLineCnt=32;for(;halfLineCnt!=0;halfLineCnt--){basicBlock=16;wrPosition();智芯锐电子:(;basicBlock!=0;basicBlock--){if(bmpCls==OFF){lcdWriteData(*bmp++);}elseif(bmpCls==ON){lcdWriteData(0x00);}}lcdPosY++;}lcdPosX=0x88;}lcdWriteCommand(cFuncDrawOn);lcdWriteCommand(cFunctionSetB);}//===============================================voidconvertChar(ucharCX,CY,width){displayPhoto(OFF,ON);lcdPosY=0x80;if(CX==0){CX=0x80;halfLineCnt=16;}elseif(CX==1){CX=0x80;halfLineCnt=32;}elseif(CX==2){CX=0x88;halfLineCnt=16;}elseif(CX==3){CX=0x88;halfLineCnt=32;}智芯锐电子:=CX+CY;for(;halfLineCnt!=0;halfLineCnt--){basicBlock=width;wrPosition();for(;basicBlock!=0;basicBlock--){if(halfLineCnt16){lcdWriteData(0x00);}else{lcdWriteData(0xff);}}lcdPosY++;}lcdWriteCommand(cFuncDrawOn);lcdWriteCommand(cFunctionSetB);}//===============================================voidwrPosition(void){lcdWr

1 / 72
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功