⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new.lst

📁 这是我自己写的一段程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
1018   2              if(Dec_Key == 0)
1019   2                              Set_Bell(id2,1);  
1020   2                      while(Dec_Key ==0);
1021   2            }
1022   1      }
1023          
1024          /******************************************************************************/
1025          void Set_Bell(unsigned char sel, bit sel_1)//根据选择调整相应项目并写入24 
1026          {
1027   1        signed char address,item;
1028   1        signed char max,mini;
1029   1        if(sel==4)  {address=0x03; max=59;mini=0;}    //秒
1030   1        if(sel==3)  {address=0x02; max=59;mini=0;}    //分
1031   1        if(sel==2)  {address=0x01; max=23; mini=0;}   //时
1032   1        if(sel==1)  
1033   1        {
1034   2              address=0x04;
1035   2              if(Add_Key ==0 || Dec_Key ==0)
1036   2              Bell_Swh=~Bell_Swh;
1037   2              Write_One_Byte(address,Bell_Swh);
1038   2        }    //开关
1039   1      
1040   1        item = Read_One_Byte(address);
1041   1        if(sel_1==0) 
1042   1              item++;  
1043   1        else
1044   1              item--;
1045   1        if(item>max) item=mini;   
1046   1        if(item<mini) item=max;
1047   1      
1048   1        Write_One_Byte(address,item);//写入24
1049   1      }
1050          
1051          /******************************************************************************/
1052          void Timer0_Init(void)//定时器0初始化
1053          {
1054   1              TMOD=0x01;
1055   1              TH0=(65535-50000)/256;
1056   1              TL0=(65535-50000)%256;
1057   1              EA=1;
1058   1              ET0=1; 
1059   1              TR0=1;
1060   1      }
1061          
1062          /******************************************************************************/
1063          void Timer0(void) interrupt 1 using 1//中断入口,冒号闪烁
1064          {
1065   1              static unsigned char timecount = 0;//
1066   1      
1067   1              TH0=(65535-50000)/256; //50ms定时
1068   1              TL0=(65535-50000)%256;  
1069   1              timecount++;
C51 COMPILER V8.05a   NEW                                                                  11/16/2007 20:45:07 PAGE 19  

1070   1              if(timecount > 9)//500MS
1071   1              {
1072   2              timecount = 0;    
1073   2              flag = ~flag;          
1074   2          }
1075   1      }
1076          
1077          /******************************************************************************/
1078          void Init_1302(void)//设置1302的初始时间
1079          {
1080   1              write_clock(0x8e,0x00);//允许写操作
1081   1              write_clock(0x8c,0x05);//年
1082   1              write_clock(0x8a,0x06);//星期
1083   1              write_clock(0x88,0x01);//月
1084   1              write_clock(0x86,0x01);//日
1085   1              write_clock(0x84,0x12);//小时
1086   1              write_clock(0x82,0x00);//分钟
1087   1              write_clock(0x80,0x00);//秒
1088   1              write_clock(0x90,0xa5);//充电   
1089   1              write_clock(0x8e,0x80);//禁止写操作
1090   1      }
1091          
1092          /******************************************************************************/
1093          void Lcd_Mark1(void)//在预定的位置上写入汉字)
1094          {
1095   1              Clr_Scr();//清屏
1096   1              frame();//显示边框
1097   1              Mcs=1;Scs=0;
1098   1              Disp_Chinese(5,8,shi);
1099   1              Disp_Chinese(5,24,wen);
1100   1              Disp_Chinese(3,8,xing);
1101   1              Disp_Chinese(3,24,qi);
1102   1              Disp_Chinese(1,40,nian);
1103   1              Disp_Digit(5,56,point);
1104   1              Mcs=0;Scs=1;
1105   1              Disp_Chinese(5,8,sheshidu);
1106   1              if(Bell_Swh == 1)//闹钟为开
1107   1              {       
1108   2                      Mcs=0;Scs=1;
1109   2                      Disp_Chinese(5,40,biaozhi);//显示闹钟图标
1110   2              }
1111   1      
1112   1      }
1113          
1114          /******************************************************************************/
1115          void Lcd_Mark2(void)
1116          {
1117   1              Clr_Scr();//清屏
1118   1              frame();//显示边框
1119   1              
1120   1              Mcs=1;Scs=0;//显示闹钟设定等几个汉字
1121   1              Disp_Chinese(2,16,nao);
1122   1              Disp_Chinese(2,32,zhong);
1123   1              Disp_Chinese(2,48,she);
1124   1              Mcs=0;Scs=1;
1125   1              Disp_Chinese(2,0,ding);
1126   1              Disp_Digit(4,0,maohao);
1127   1              Disp_Digit(4,24,maohao);        
1128   1      }
1129          
1130          /******************************************************************************/
1131          void main(void)
C51 COMPILER V8.05a   NEW                                                                  11/16/2007 20:45:07 PAGE 20  

1132          {
1133   1              unsigned char a;
1134   1      
1135   1              Timer0_Init();
1136   1              Init_lcd();//设置液晶显示器
1137   1              WP = 0;//允许2408的写操作!
1138   1      
1139   1              Clr_Scr();//清屏
1140   1      
1141   1              Bell_Swh = Read_One_Byte(0x04);//读取开关的状态
1142   1              Lcd_Mark1();
1143   1      
1144   1              while(1)//主循环
1145   1              {       
1146   2                      //设置时钟的初始值,显示05年1月1号12:00:00
1147   2                      if(Add_Key == 0 && Dec_Key == 0)
1148   2                      {
1149   3                              Delay(1000);
1150   3                              if(Add_Key == 0 && Dec_Key == 0)
1151   3                              {
1152   4                                      Init_1302();
1153   4                              }
1154   3                      }
1155   2      
1156   2              if(Add_Key == 0)
1157   2                      {       Delay(1000);
1158   3                              if(Add_Key ==0)
1159   3                              {       
1160   4                                      //写入闹钟初始值08:00:00
1161   4                                      Write_One_Byte(0x01,8);
1162   4                                      Write_One_Byte(0x02,0);
1163   4                                      Write_One_Byte(0x03,0);
1164   4                              }
1165   3      
1166   3            }
1167   2                      if(OK_Key == 0 && Dec_Key ==0 )//进入闹钟设置界面
1168   2                      {
1169   3                              Delay12864(100);
1170   3                              if(OK_Key == 0 && Dec_Key ==0 )
1171   3                              {
1172   4                                      Lcd_Mark2();
1173   4                                      if(Bell_Swh == 0){Mcs=0;Scs=1;Disp_Chinese(2,32,guan);}//关
1174   4                                      else  {Mcs=0;Scs=1;Disp_Chinese(2,32,kai);}
1175   4                                      while(1)
1176   4                                      {       
1177   5                                              if (OK_Key == 0) // 设置和选择项目键
1178   5                                      {       
1179   6                                                      Delay(1000);
1180   6                                              if(OK_Key == 0)
1181   6                                                      {
1182   7                                                              id2++;if(id2>5) id2=0;
1183   7                                                      }
1184   6                                              while(OK_Key == 0);//等待键松开   
1185   6                                          }
1186   5                                              switch( id2 )
1187   5                                              {
1188   6                                                      case 0:Disp2();break;//正常显示
1189   6                                                      case 1:Kgb = 1;id_case2_key();Disp2();break;//开关
1190   6                                                      case 2:Kgb= 0;Hourb=1;id_case2_key();Disp2();break;//
1191   6                                                      case 3:Hourb=0;Minb=1;id_case2_key();Disp2();break;
1192   6                                                      case 4:Minb=0;Secb=1;id_case2_key();Disp2();break;
1193   6                                                      case 5:Secb=0;id2 = 0;Lcd_Mark1();goto FF;break;//返回主界面
C51 COMPILER V8.05a   NEW                                                                  11/16/2007 20:45:07 PAGE 21  

1194   6                                                      default:break;
1195   6                                              }
1196   5                                      }//while(1)
1197   4                              }//if
1198   3                      }//if
1199   2      /*****************************************/
1200   2                      FF:   //返回主界面
1201   2      /*****************************************/                     
1202   2                      if(flag == 0)
1203   2                      {
1204   3                              Mcs=0;Scs=1;
1205   3                              Disp_Digit(3,8,maohao);// :闪烁 
1206   3                              Disp_Digit(3,32,maohao);
1207   3                      }
1208   2                      else 
1209   2                      {
1210   3                              Mcs=0;Scs=1;
1211   3                              Disp_Digit(3,8,space);//显示空格
1212   3                              Disp_Digit(3,32,space); 
1213   3                      }
1214   2                      if (OK_Key == 0) // 设置和选择项目键
1215   2              {
1216   3                      Delay(1000);
1217   3                      if(OK_Key == 0)
1218   3                              {
1219   4                                      id++;if(id>7)id=0;      
1220   4                              }
1221   3                      while(OK_Key == 0);//等待键松开    
1222   3              }
1223   2              switch( id )
1224   2              {
1225   3                      case 0:sec = 0; Disp( );break;//正常显示
1226   3                      case 1:year = 1;id_case1_key();Disp();break;//年        
1227   3                              case 2:year=0;mon=1;id_case1_key();Disp();break;//月
1228   3                  case 3:mon=0;day=1;id_case1_key();Disp();break;  //日 
1229   3                      case 4:day=0;weekk=1;id_case1_key();Disp();break;//星期     
1230   3                      case 5:weekk=0;hour=1;id_case1_key();Disp();break;  //小时
1231   3                      case 6:hour=0;min=1;id_case1_key();Disp();break; //分钟
1232   3                      case 7:min=0;sec=1;id_case1_key();Disp();break; //秒
1233   3                      default:break;  
1234   3              }
1235   2      
1236   2                      if(Bell_Swh == 1)//闹钟为开
1237   2                      {
1238   3                              H_2402=Read_One_Byte(0x01);//读取2408的
1239   3                              S_2402=Read_One_Byte(0x02);
1240   3                              
1241   3                              d=read_clock(0x85);//读小时
1242   3                              e=d;
1243   3                              d=d>>4;
1244   3                              e=e&0x0f;
1245   3                              H_1302=10*d+e;
1246   3      
1247   3                              d=read_clock(0x83);//读分钟
1248   3                              e=d;
1249   3                              d=d>>4;
1250   3                              e=e&0x0f;
1251   3                              S_1302=10*d+e;
1252   3      
1253   3                              if(H_2402 == H_1302) 
1254   3                              {
1255   4                                      if(S_2402 == S_1302)
C51 COMPILER V8.05a   NEW                                                                  11/16/2007 20:45:07 PAGE 22  

1256   4                                      {
1257   5                                              Clr_Scr();//清屏
1258   5                                              frame();//显示边框
1259   5                                              Mcs=1;Scs=0;
1260   5                                              Disp_Chinese(3,16,nao);//闹钟显示时间到!
1261   5                                              Disp_Chinese(3,32,zhong);
1262   5                                              Disp_Chinese(3,48,shit);
1263   5                                              Mcs=0;Scs=1;
1264   5                                              Disp_Chinese(3,0,jian);
1265   5                                              Disp_Chinese(3,16,dao);
1266   5                                              Disp_Digit(3,40,fh);
1267   5                              
1268   5                                              while(S_2402 == S_1302)//判断是否到闹钟设定时间
1269   5                                              {
1270   6                                                      for(a=0; a<100; a++)//BELL脉冲输出,驱动蜂鸣器
1271   6                                                      {
1272   7                                                              if(a<50){Bell_Out = 0;Delay(100);}
1273   7                                                              else {Bell_Out = 1;Delay(100);}
1274   7                                                      }
1275   6                                                              
1276   6                                                      d=read_clock(0x83);//读分钟
1277   6                                                      e=d;
1278   6                                                      d=d>>4;
1279   6                                                      e=e&0x0f;
1280   6                                                      S_1302=10*d+e;
1281   6                                              }
1282   5                    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -