1602源程序和仿真
单片机源程序:
- #include <REGX52.H>
- #include "INCLUDE.H"
- sbit key1 = P3^7;
- sbit key2 = P3^6;
- sbit Callbit = P1^5;
- void Delay1ms(unsigned int count)
- {
- unsigned int i,j;
- for(i=0;i<count;i++)
- for(j=0;j<120;j++);
- }
- main()
- {
- uchar flag = 0;
- uchar flag2 = 0;
- uchar Adrr = 20;
- uint cnt=0;
- LCD_Initial();
- // Initial_DS1302();
-
- // IIC_WriteData(20,120,&defaucode[0][0]);
- Callflag = 1;
- Delay1ms(50);
-
- while(1)
- {
- if(flag == 0)
- {
- if(flag2 ==0 )
- {
- GotoXY(0,0);
- Print("Date: ");
- GotoXY(0,1);
- Print("Time: ");
- flag2 = 1;
- }
-
- DS1302_GetTime();
- DateToStr();
- GotoXY(6,0);
- Print(&DateString[0]);
- TimeToStr();
- GotoXY(6,1);
- Print(&TimeString[0]);
-
- cnt =0;
- }
- else if(flag == 1)
- {
- IIC_ReadData(Adrr,20 ,&Callbuf[0]);//读数据函数
- if(flag2 ==0 )
- {
- GotoXY(0,0);
- Print(" ");
- GotoXY(0,1);
- Print(" ");
- flag2 = 1;
- }
-
- CallTostr();
- GotoXY(0,0);
- Print(&Callnumstr[0]);
- GotoXY(2,1);
- Print(&CallTimestr[0]);
- flag = 2;
- }
- else if(flag == 2)
- {
- if(flag2 ==0 )
- {
- GotoXY(0,0);
- Print(" ");
- GotoXY(0,1);
- Print("Time: ");
- flag2 = 1;
-
-
- DS1302_GetTime();
- GotoXY(0,0);
- Print(&Callnumbuf[0]);
- TimeToStr();
- GotoXY(6,1);
- Print(&TimeString[0]);
- }
- cnt =0;
- }
-
-
- key3 = Callbit ;
- if(Callbit == 0)
- {
- Callflag = 1;
- }
- if(Getnum()==1) //显示按键
- {
- flag = 2;
- flag2= 0;
- }
- if(key1 == 0) //上一条记录
- {
- cnt =0;
- flag = 1;
- flag2 = 0;
- Adrr +=20;
- if(Adrr >= 140)
- {
- Adrr = 20;
- }
- }
- else if(key2 == 0) //下一条记录
- {
- cnt =0;
- flag = 1;
- flag2 = 0;
- if(Adrr == 0)
- {
- Adrr = 120;
- }
- else
- {
- Adrr -=20;
- }
- }
-
- cnt++;
- if(cnt >= 300)
- {
- flag = 0;
- flag2 = 0;
- cnt = 0;
- }
- // Delay1ms(10) ;
-
- }
- }
复制代码
下载:
1602.rar
(111.45 KB, 下载次数: 32)
|