公歷陽(yáng)歷轉(zhuǎn)陰歷農(nóng)歷C51程序鍵盤數(shù)碼管成功剖析_第1頁(yè)
公歷陽(yáng)歷轉(zhuǎn)陰歷農(nóng)歷C51程序鍵盤數(shù)碼管成功剖析_第2頁(yè)
公歷陽(yáng)歷轉(zhuǎn)陰歷農(nóng)歷C51程序鍵盤數(shù)碼管成功剖析_第3頁(yè)
公歷陽(yáng)歷轉(zhuǎn)陰歷農(nóng)歷C51程序鍵盤數(shù)碼管成功剖析_第4頁(yè)
公歷陽(yáng)歷轉(zhuǎn)陰歷農(nóng)歷C51程序鍵盤數(shù)碼管成功剖析_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、末實(shí)驗(yàn)名 *使用的10*實(shí)驗(yàn)效果*注意:動(dòng)態(tài)顯示數(shù)碼管實(shí)驗(yàn):數(shù)碼管使用P0F22P23P2.4:數(shù)碼管顯示76543210c>K)4c)K*p)K*)K*p*p*p*p*)4c)K*p)K*)K*p*p)K*)K*>K*p>K)4c)K*p)K*p*p*)K*p*p>K)4c)K*p*)K*)K*p)K*)K*>K*p*p*#in clude<reg51.h>#in clude<stdio.h>#define GPIO_DIG P0數(shù)碼管顯示#define GPIO_KEY Pl/鍵盤sbit LSA=P2A2;sbit LSB=P2A3;

2、sbit LSC=P2A4;sbit K3=P3A2;/外部中斷 unsigned char code DataTab404=口期差上大小月卞人小月閏月月份及大小 0x46,0x43,0x21,0x00,999 0x35,0x15,0x51,0x007/20000x23,0x11,0x52,0x41,0x42,0x12,0x65,0x00,0x31,0x11,0x32,0x00,0x21,0x42,0x52,0x21,0x39,0x52,0x25,0x007/2005 0x28,0x25,0x04,0x71,0x4&0x66,0x42,0x00,0x37,0x33,0x22,0x00,

3、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,/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

4、,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,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

5、,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,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

6、,0x55,0x50,0x00,0x38,0x46,0x64,0x00,0x27,0x45,0x65,0x60,0x45,0x05,0x32,0x00,0x34,0x45,0x15,0x00,0x23,0x26,0x23,0x40,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

7、,0x26,0x22,0x00,/2O25/2O3O/2O35/2O4O仇045/2O5O/Z2O55/2O6O/2O650x22,0x52,0x42,0x41,0x41,0x53,0x22,0x00,/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

8、,0x30,0x31,/2O8O0x39,0x45,0x54,0x00,0x28,0x43/0xl4,0x71,0x47,0x45,0x25,0x00,0x36,0x24,0x52,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

9、,0x00,0x35,0x55,0x21,0x00,/20950x24,0x25,0x42,0x41,0x42,0x26,0x62,0x00,0x31,0x13,0x52,0x00,0x20,0x03,0x32,0x21/2099lhunsigned char code DIG_CODE17=0x3£0x06,0x5b,0x4f,0x66,0x6cL0x7ct0x070x7f,0x6f/0x77/0x7c/0x39,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

10、/28,31/30/31,30,31,31,30,31,30,31;公歷該月的天數(shù)unsigned char DisplayData8;用來(lái)存放要顯示的8位數(shù)的值unsigned char TempData8;unsigned char TurnData4;轉(zhuǎn)換用于取出數(shù)據(jù)表的四個(gè)數(shù)據(jù)unsigned char KeyValue;用來(lái)存放讀取到的鍵值unsigned char KV;char year_soH;char year_so;/ 公歷年月口char month_so;char day_so;int SumDar_so; /char型位數(shù)不夠,出現(xiàn)瓶頸char yearu;農(nóng)歷年月口c

11、har monthju;char day Ju;int SumDarJu;int mH;延時(shí)10ms檢測(cè)按鍵函數(shù) 檢測(cè)鍵值并顯示 陽(yáng)歷轉(zhuǎn)換陰歷void DigDisplay(); /動(dòng)態(tài)顯示函數(shù)void DelaylOms();void KeyDown();void KeyShow();void Turn();/int LMPfint LP);int monthl2_lu(int month_a,unsigned char month_b,unsigned char month_c);:main:主函數(shù):無(wú):無(wú)末函數(shù)名 *函數(shù)功能 *輸 入 *輸 出void main()year_lu=0;農(nóng)

12、歷年月口 mon th_lu=O; dayJu=O;KeyShow();設(shè)置INTOIT0=l;/跳變沿出發(fā)方式(下降沿) EXO=1;打開(kāi)INTO的中斷允許。EA=1;/打開(kāi)總中斷while(l)DigDisplay();/ 顯示 if(KV=l)/ 進(jìn)中斷Turn(); 轉(zhuǎn)換程序承函數(shù)名*函數(shù)功能*輸 入*輸 出:KeyShow:檢測(cè)有按鍵按卞并顯示鍵值:無(wú):無(wú)void KeyShow()unsigned char i=0;int j=0;int q,u=0;SumDar_so=0;LSA=O; 給一個(gè)數(shù)碼管提供位選LSB=O;LSC=O;while(i<=7)GPIO_KEY=Ox

13、Of;if(GPIO_KEY!=OxOf)/讀取按鍵是否按下DelaylOmsf);/延時(shí)10ms進(jìn)行消抖 if(GPIO_KEY!=OxOf)/再次檢測(cè)鍵盤是否按F KeyDown();/讀取鍵值 if(KeyValue<=9)/ 鍵值有效 TempDatai=KeyValue;/W按鍵輸入的8位數(shù)存在寄存器中DisplayDatai=DIG_CODEKeyValue;/ 將查到的值送到顯示數(shù)據(jù) 寄存器i+;DigDisplay();/ 顯示DigDisplay();/ 顯示DigDisplay();/ 顯示year_soH=(int)(TempData0);從寄存器中讀取公歷年份ye

14、ar_soH=year_soH*10+(int)(TempDatal);year_so=(int)(TempData2);從寄存器中讀取公歷年份year_so=year_so*10+(int)(TempData3);month_so=(int)(TempData4); month_so=month_so*10+(int)(TempData5);/ 讀取公歷月 day_so=(int)(TempData 6);day_so=day_so*10+(int)(TempData7);/ 讀取公歷月 j=month_so-l;for(q=0;q<j;q+)u 二 so_m_dq;SumDar-so

15、=SumDar_so+u;SumDa r_so=Sum Da r_so+d ay_so;H=SumDar-so;if(j>l)/J>l需要考慮公歷閏年 if(year_so%4=0) SumDar-so=SumDar_so+l;承函數(shù)名*函數(shù)功能*輸 入*輸 出:Turn:陽(yáng)歷轉(zhuǎn)陰歷:無(wú):無(wú)void Turn()unsigned char Temp; unsigned char L_Temp; unsigned chary;unsigned char sy;unsigned char xy;unsigned char L_y; unsigned char L_sy;unsigned

16、 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 jkrnpT;intllJ2J3j4J5J6j7j8/l9/ll0/lllJ12/LastMonth;p=year_soH* 100+year_so;/年份 20"年Temp=(p-2000+l)*4;公歷年份*4再去查表,存入轉(zhuǎn)化暫存器y=DataTabTemp;/上半年的數(shù)據(jù)Temp+;sy=DataTabTe

17、mp;Te mp+;/下半年的數(shù)據(jù)xy=DataTabTemp;Te mp+;/閏月的月份和大小ry=DataTabTemp;/BCD碼轉(zhuǎn)十進(jìn)制,求出差值n=10*(int)(y&0xf0)»4)+(int)(y&0x0f);/ 天數(shù)差值SumDar_lu=SumDar_so-n; /農(nóng)歷總天數(shù)k = (int)(ry&0xf0)»4);/ 閏月月份m = 30- (int)(ry&0x0f);閏月的天數(shù)Il=monthl2_lu(l/sy/xy);/農(nóng)歷 1 月多少天I2=monthl2_lu(2/sy,xy);/農(nóng)歷 1 月多少天I3=m

18、onthl2_lu(3/sy,xy);/農(nóng)歷 1 月多少天I4=monthl2_lu(4,sy/xy);/農(nóng)歷 1 月多少天I5=monthl2_lu(5/sy,xy);/農(nóng)歷 1 月多少天I6=monthl2u(6,s%xy);農(nóng)歷 1 月多少天I7=monthl2_lu(7/sy,xy);/農(nóng)歷 1 月多少天I8=monthl2u(&sy,xy);/農(nóng)歷 1 月多少天I9=monthl2_lu(9/sy,xy);/農(nóng)歷 1 月多少天I10=monthl2u(10,sy,xy);農(nóng)歷 1 月多少天lll=monthl2Ju(ll/syzxy);/農(nóng)歷 1 月多少天I12=monthl

19、2ju(12,syzxy);/農(nóng)歷 1 月多少天T=SumDar_so;if(T<n) /如果跨年L_Temp=(p-2000)*4;去年公歷年份*4再去查表,存入轉(zhuǎn)化暫存器L_y=DataTabL_Temp;/ 上半年的數(shù)據(jù)L_Temp+;L_sy=DataTabL_Temp;L_Temp+;/ F半年的數(shù)據(jù)L_xy=DataTabL_Temp;monthju=ll;跨年到去年的11月LastMonth=monthl2u(12,L_syL_xy);day Ju 二n-SumDar_so-LastM on th;LastMonth=monthl2u(l 丄_sy丄 _xy);dayu=L

20、astMonth-dayu; dayju=dayju+l; 2if (n)>0)&&(n-T)<=31)month_lu=12; 跨年到去年的12月LastMonth=monthl2u(12 丄_sy丄 _xy); dayJu=LastMonth-(n-T);else 沒(méi)有跨年if(SumDarJu-ll)>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

21、-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-l6-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-

22、l6-l5-l4-l3-l2-ll;elsemonth _lu=ll;dayJu=SumDarJu-H0-l9-l8-l7-l6-l5-l4-l3-l2-ll;elsemonthu=10;day_lu=SumDarJu-l9-l8-l7-l6-l5-l4-l3-l2-ll;elsemonth Ju=9;dayJu=SumDarJu-l8-l7-l6-l5-l4-l3-l2-ll;elsemon thju=8; dayJu=SumDarJu-l7-l6-l5-l4-l3-l2-ll;elsemon thju=7;dayJu=SumDarJu-l6-l5-l4-l3-l2-ll;elsemonth

23、_lu=6;dayJu=SumDar_lu-l5-l4-l3-l2-ll;elsemonth lu=5;day_lu=SumDar_lu-l4-l3-l2-ll;elsemonthu=4; day_lu=SumDar_lu-l3-l2-ll;elsemonth_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)有農(nóng)歷閏月if(month_lu-k)>=l)/在第二個(gè)閏月,月減一,口不變if(day_lu>m) /跨月day_l

24、u=l;else/沒(méi)夸,月減一,口不變monthu=monthu-l;正好在第一個(gè)閏月,月份不變顯示程序T=SumDar_so;/if(SumDar_so<n) 如果跨年 if(T<n) /如果跨年if(year_so=0)/是 2000 年DisplayData0=DIG-CODEl;DisplayDatal=DIG-CODE9;DisplayData2=DIG_CODE ;DisplayData 3=DIG_CODE ;else 公歷不是2000年yearju=year_so-l;DisplayData0=DIG_CODE2;DisplayDatal=DIG_CODE0;Z=

25、year_lu/10;F= year_lu%10;DisplayData2=DIGCODEZ;DisplayData3=DIGCODEF;else/沒(méi)跨年yearju=year_so;DisplayData0=DIG-CODE2;DisplayData 1=DIG_CODE0;Z= year_lu/10;F= yearJu%10;DisplayData 2=DIG_CODEZ;DisplayData3=DIG_CODEF;Z_y= monthu/10;F_y= monthju%10;Z_ r=dayJu/10;F_r=day_lu%10;DisplayData4=DIG_CODEZ_y;Dis

26、playData5=DIG-CODEF_y;DisplayData6=DIG_CODE Z_r;DisplayData7=DIG_CODEF_r;:lntO() interrupt 0*函數(shù)功能:外部中斷0的中斷函數(shù):無(wú)*輸 出:無(wú)void lntO() interrupt 0外部中斷0的中斷函數(shù)DelaylOms();/延時(shí)10ms進(jìn)行消抖if(K3=0)KV=1;承函數(shù)名*函數(shù)功能:monthl2u:查出那個(gè)農(nóng)月多少天承輸入:農(nóng)歷的月份,查表所得農(nóng)歷月份數(shù)據(jù)審輸出:返回該農(nóng)歷月份天數(shù)int monthl2_lu(int month_a, unsigned char month_b,unsi

27、gned char month_c) switch(m on th_a)case l:if(month_b&0x40) return 29; else return 30;case 2:if(month_b&0x20) return 29; 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 retu

28、rn 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; else return 30;case 9:if(month_c&OxlO) return 29; else return 30;case 10:if(month_c&0x04) return 29; else return 30;case ll:if(month_c&

29、OxO2) return 29; else return 30;case 12:if(month_c&0x01) return 29; else return 30;case 13:return 1000;default:return 0;承函數(shù)名*函數(shù)功能*輸 入*輸 出:KeyDown:檢測(cè)有按鍵按卞并讀取鍵值:無(wú):無(wú)*void KeyDown(void)char a=0;GPIO_KEY=OxOf;if(GPIO_KEY!=OxOf)/讀取按鍵是否按FDelaylOms();/延時(shí)10ms進(jìn)行消抖 if(GPIO_KEY!=OxOf)再次檢測(cè)鍵盤是否按卜測(cè)試列GPIO_KEY=OXOF; switch(GPIO_KEY)case(0X07):KeyValue=O;break;case(OXOb):KeyValue=l;bre

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論