公历阳历转阴历农历C51程序键盘数码管成功剖析_第1页
公历阳历转阴历农历C51程序键盘数码管成功剖析_第2页
公历阳历转阴历农历C51程序键盘数码管成功剖析_第3页
公历阳历转阴历农历C51程序键盘数码管成功剖析_第4页
公历阳历转阴历农历C51程序键盘数码管成功剖析_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、*实验名* 使用的10* 实验效果* 注 意:动态显示数码管实验:数码管使用p0,p22p23p2.4:数码管显示765432100*#include#include #define gpio_dig po数码管显示#define gpio_key pl/键盘sbit lsa=p2a2;sbit lsb=p2a3;sbit lsc=p2a4;sbit k3=p3a2;外部中断unsigned char code datatab404=口期差上大小月下大小月闰月月份及大小 0x46,0x43,0x21,0x007/1999 0x35,0x15,0x51,0x007/20000x23,0x11,0

2、x52,0x41,0x42,0x12,0x65,0x00,0x31,0x11,0x32,0x00,0x21,0x42,0x52,0x21, 0x39,0x52,0x25,0x007/20050x28,0x25,0x04,0x71,0x48,0x66,0x42,0x00,0x37,0x33,0x22,0x00,0x25,0x15,0x24,0x51, 0x44,0x25,0x52,0x007/20100x33,0x22,0x65,0x00,0x22,0x21,0x25,0x41,0x40,0x24,0x52,0x00,0x30,0x52,0x42,0x91,0x49,0x55,0x05,0x00

3、,/20150x38,0x26,0x44,0x00,0x27,0x53,0x50,0x60,0x46,0x53,0x24,0x00,0x35,0x25,0x54,0x00,0x24,0x41,0x52,0x41,/2o2o0x42,0x45,0x25,0x00,0x31,0x24,0x52,0x00,0x21,0x51,0x12,0x21,0x40,0x55,0x11,0x00,0x28,0x32,0x21,0x61, 0x47,0x26,0x61,0x00, 0x36,0x13,0x31,0x00, 0x25,0x05,0x31,0x51, 0x43,0x12,0x54,0x00, 0x33

4、,0x51,0x25,0x00, 0x22,0x42,0x25,0x31, 0x41,0x32,0x22,0x00, 0x30,0x55,0x02,0x71, 0x49,0x55,0x22,0x00, 0x38,0x26,0x62,0x00, 0x27,0x13,0x64,0x60, 0x45,0x13,0x32,0x00, 0x34,0x12,0x55,0x00, 0x23,0x10,0x53,0x51, 0x42,0x22,0x45,0x00, 0x31,0x52,0x22,0x00, 0x21,0x52,0x44,0x21, 0x40,0x55,0x44,0x00, 0x29,0x26,

5、0x50,0x71, 0x47,0x26,0x64,0x00, 0x36,0x25,0x32,0x00, 0x25,0x23,0x32,0x50, 0x44,0x44,0x55,0x00, 0x32,0x24,0x45,0x00, 0x22,0x55,0x11,0x30, 0x41,0x33,0x10,0x00, 0x31,0x55,0x40,0x81, 0x49,0x55,0x50,0x00, 0x38,0x46,0x64,0x00, 0x27,0x45,0x65,0x60, 0x45,0x05,0x32,0x00, 0x34,0x45,0x15,0x00, 0x23,0x26,0x23,0

6、x40, 0x42,0x25,0x21,0x00, 0x32,0x33,0x21,0x00, 0x20,0x43,0x21,0x31, 0x39,0x15,0x51,0x00, 0x28,0x12,0x52,0x71, 0x47,0x12,0x65,0x00, 0x35,0x11,0x32,0x00, 0x25,0x50,0x52,0x51, 0x44,0x52,0x25,0x00, 0x33,0x26,0x22,0x00,/2o25/2o3o/2o35/2o4o/2045/2o5o/z2o55/2o6o/2o650x22,0x52,0x42,0x41, 0x41,0x53,0x22,0x00

7、,/2o7o0x30,0x25,0x44,0x81, 0x49,0x25,0x52,0x00, 0x37,0x22,0x65,0x00, 0x26,0x22,0x25,0x61, 0x45,0x24,0x52,0x00,/2o750x35,0x52,0x45,0x00, 0x23,0x25,0x05,0x41, 0x42,0x26,0x44,0x00, 0x32,0x53,0x24,0x00, 0x21,0x23,0x30,0x31,/2o8o0x39,0x45,0x54,0x00, 0x28,0x43,0x14,0x71, 0x47,0x45,0x25,0x00, 0x36,0x24,0x5

8、2,0x00, 0x25,0x55,0x12,0x50,/20850x44,0x55,0x11,0x00, 0x33,0x26,0x50,0x00, 0x23,0x52,0x61,0x41, 0x40,0x13,0x31,0x00, 0x29,0x05,0x51,0x81,/2o9o0x48,0x12,0x55,0x00, 0x37,0x11,0x25,0x00, 0x26,0x45,0x25,0x60, 0x45,0x52,0x22,0x00, 0x35,0x55,0x21,0x00,/20950x24,0x25,0x42,0x41, 0x42,0x26,0x62,0x00, 0x31,0x

9、13,0x52,0x00, 0x20,0x03,0x32,0x21/2099;unsigned char code dig_code17= 0x3f,0x06,0x5bqx4f,0x66qx6d,0x7d,0x07, 0x7f,0x6f,0x77/)x7a0x39,0x5e,0x79,0x71; /q、1、2、3、4、5、6、7、8、9、a、b、c、d、e、f 的显示码 unsigned char code so_m_d12=31,28,31/30,31,30,31,31,30,31,30,31); 公历该月的天数 unsigned char displaydata8;用来存放要显示的8位数的

10、值unsigned char tempdata8;unsigned char turndata4;转换用于取出数据表的四个数据unsigned char keyvalue;用来存放读取到的键值unsigned char kv;char year_soh;char yeajso;公历年月 口char month_so;char day_so;int sumdar_so; char型位数不够,出现瓶颈 char yearu;农历年月口 char monthju;char day ju;int sumdarju;int n,h;void digdisplay();动态显示函数void delaylo

11、ms();void keydown();void keyshow();void turn();/int lmpfint lp);延时10ms检测按键函数检测键值并显示阳历转换阴历int monthl2_lu(int month_a ,unsigned char month_b,unsigned char month_c);/*函数名 函数功能 输 入 输 出:mam:主函数:无:无*void main()(year_lu=0;农历年月口month_lu=0;day_lu=o;keyshow();设置intoito=1;跳变沿出发方式(下降沿) exo=1;打开into的中断允许。ea=1;打开

12、总中断while(l)digdisplay();显示 if(kv=l)进中断turn(); 转换程序* 函数名:keyshow* 函数功能:检测有按键按下并显示键值* 输 入:无* 输 出:无*void keyshow()(unsigned char i=0;int j=0;int q,u=0;sumdar_so=0;lsa=o; 给一个数码管提供位选lsb=o;lsc=o;while(i=7) gpio_key=oxof;if(gpio_key!=oxof) 读取按键是否按下 delayloms();延时10ms进行消抖 if(gpio_key!=oxof)再次检测键盘是否按f keydow

13、n。; 读取键值if(keyvalue=9)键值有效(tempdatai=keyvalue;将按键输入的8位数存在寄存器中displaydatai=dig_codekeyvalue;/w 查到的值送到显示数据 寄存器i+;digdisplay();显示 ) ) ) digdisplay();显示 )digdisplay();显示year_soh=(int)(tempdata0);从寄存器中读取公历年份year_soh=year_soh*10+(int)(tempdatal);year_so=(int)(tempdata2);从寄存器中读取公历年份year_so=year_so*10+(int)

14、(tempdata3);month_so=(int)(tempdata4);month_so二month_so*10+(int)(tempdata5);/读取公历月day_so=(int)(tempdata6);day_so=day_so*10+(inu(tempdata7);读取公历月j=month_so-l;for(q=0;ql)/jl需要考虑公历闰年if(year_so%4=0) sumdar_so=sumdar_so+l; )*阳历转阴历 无无函数名 函数功能 输 入 输 出*void turn()unsigned char temp;unsigned char l_temp;unsi

15、gned chary;unsigned char sy;unsigned char xy;unsigned char l_y;unsigned char l_sy;unsigned char l_xy;unsigned char ry;unsigned char z;unsigned char f;unsigned char z_y;unsigned char f_y;unsigned char z_r;unsigned char f_r;int jhm,p,t;intllj2j3j4j5j6j7j8/l9j10/lllj12/lastmonth;p=year_soh*100+year_so;

16、年份 20*年temp=(p-2000+l)*4;公历年份*4再去查表,存入转化暂存器 y=datatabtemp; 上半年的数据temp+;sy=datatabtemp;te m p+;下半年的数据 xy=datatabtemp;tem p+;闰月的月份和大小ry=datatabtemp;bcd码转十进制,求出差值n=10*(int)(y&0xf0)4)+(int)(y&0x0f); 天数差值sumdaru=sumdar_so-n; 农历总天数k = (int3(ry&oxfo)4);闰月月份m = 30- (intmry&oxof);闰月的天数il=monthl2/u(l,sy,xy);农

17、历 1 月多少天i2=monthl2u(2,sy,xy);农历 1 月多少天i3=monthl2u(3,sy,xy);农历 1 月多少天i4=monthl2u(4,sy,xy);农历 1 月多少天i5=monthl2u(5,sy,xy);农历 1 月多少天i6=monthl2usyxy);农历1月多少天i7=monthl2u(7,sy,xy);农历 1 月多少天i8=monthl2u(8,sy,xy);农历 1 月多少天i9=monthl2u(9,sy,xy);农历 1 月多少天i10=monthl2u(10,sy,xy);农历 1 月多少天ill=monthl2_lu(ll,sy,xy);农

18、历 1 月多少天i12=monthl2_lu(12,sy,xy);农历 1 月多少天t=sumdar_so;if(t0)&(n-t)0)if(sumdar_lu-l2-ll)0)if(sumdarju-l3-l2-ll)0)(if(sumdarju-l4-l3-l2-ll)0)(if(sumdarju-l5-l4-l3-l2-ll)0)(if(sumdarju-l6-l5-l4-l3-l2-ll)0)if(sumdarju-l7-l6-l5-l4-l3-l2-ll)0)if(sumdar_lu-l8-l7-l6-l5-l4-l3-l2-ll)0)(if(sumdar_lu-l9-l8-l7-l

19、6-l5-l4-l3-l2-ll)0)(if(sumdarju-h0-l9-l8-l7-l6-l5-l4-l3-l2-ll)0)if(sumdarju-lll-h0-l9-l8-l7-l6-l5-l4-l3-l2-ll)0)monthju=12;dayju=sumdarju-lll-h0-l9-l8-l7-l6-l5-l4-l3-l2-ll;else monthju=ll;dayju=sumdarju-h0-l9-l8-l7-l6-l5-l4-l3-l2-ll; ) else (month_lu=10;dayju=sumdarju-l9-l8-l7-l6-l5-l4-l3-l2-ll;) )

20、else (monthju=9;dayju=sumdarju-l8-l7-l6-l5-l4-l3-l2-ll;) else (monthju=8;dayju=sumdarju-l7-l6-l5-l4-l3-l2-ll;) else monthju=7; dayju=sumdarju-l6-l5-l4-l3-l2-ll;) else month_lu=6; dayju=sumdar_lu-l5-l4-l3-l2-ll;)else(month lu=5;day_lu=sumdar_lu-l4-l3-l2-ll;)else(month_lu=4;day_lu=sumdar_lu-l3-l2-ll;)

21、else(month_lu=3;day_lu=sumdar_lu-l2-ll;)elsemonth_lu=2;day_lu=sumdar_lu-ll;)elsemonth_lu=l;day_lu=sumdar_lu;)if(k!=o)有农历闰月if(monthu-k)=l)在第二个闰月,月减一,口不变if(dayum) 跨月day_lu=l;)else没夸,月减一,口不变(month_lu=month_lu-l;)正好在第一个闰月,月份不变显示程序t=sumdar_so; if(sumdar_son) 如果跨年if(tn) 如果跨年if(year_so=0)是 2000 年(displayda

22、ta0=dig-codel;displaydatal=dig-code9;displaydata2=dig-code9;displaydata3=dig-code9;)else 公历不是2000年 (year_lu=year_so-l;displaydata0=dig_code2;displaydatal=dig_code0;z= year_lu/10;f= year_lu%10;displaydata2=dig_codez;displaydata3=dig_codef;) else 没跨年yearju=year_so;displaydata0=dig_code2;displaydatal=d

23、ig_code0;z= year_lu/10;f= year_lu%10;displaydata2=dig_codez;displaydata3=dig_codef;)z_y= month_lu/10;f_y= monthju%10;z_r=day_lu/10;f_r=dayju%10;displaydata4=dig_codez-y;displaydata5=dig_codef_y;displaydata6=dig_codez-r;displaydata7=dig_codef_r;)*函数名:lnt0() interrupt 0函数功能输入输出外部中断。的中断函数无无*void lnto()

24、 interrupt 0外部中断0的中断函数(delay 10ms();延时10ms进行消抖if(k3=0)kv=1;* 函数名:monthl2ju* 函数功能:查出那个农月多少天* 输 入:农历的月份,查表所得农历月份数据* 输 出:返回该农历月份天数*int monthl2_lu(int month_a, unsigned char month_b,unsigned char month_c) (switch(month_a)case l:if(month_b&0x40) return 29; else return 30;case 2:if(month_b&0x20) return 29

25、; else return 30;case 3:if(month_b&0xl0) return 29; else return 30;case 4:if(month_b&0x04) return 29; else return 30;case 5:if(month_b&0x02) return 29; else return 30;case 6:if(month_b&0x01) return 29; else return 30;case 7:if(month_c&0x40) return 29; else return 30;case 8:if(month_c&0x20) return 29

26、; else return 30;case 9:if(month_c&0xl0) return 29; else return 30;case 10:if(month-c&0x04) return 29; else return 30;case ll:if(month_c&0x02) return 29; else return 30;case 12:if(month-c&0x01) return 29; else return 30;case 13:return 1000;default:return 0;)*函数名*函数功能*输入*输出:keydown:检测有按键按下井读取键值:无:无*void keydown(void)(char a=0;gpio_key=oxof;if(gpio_key!=oxof)读取按键是否按fdelay 10ms();延时10ms进行消抖 if(gpio_key!=oxof)再次检测键盘是否按卜测试列gpio_key=ox

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论