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

📄 clock.lst

📁 用C写的单片机中断时钟
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.12  CLOCK                                                                  07/05/2007 08:11:03 PAGE 1   


C51 COMPILER V6.12, COMPILATION OF MODULE CLOCK
OBJECT MODULE PLACED IN .\clock.OBJ
COMPILER INVOKED BY: E:\Program Files\keil c\C51\BIN\C51.EXE .\clock.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /************************************************************************************/
   2          /*  程序名:多功能时钟                                                              */
   3          /*  晶振:   12M                      单片机型号:AT89S51                           */
   4          /*  作者:   邓波   李杰   苏昆                                                     */
   5          /*  功能描述:本开发板P0口接数码管的段选,P2口接数码管的位选,四个按键调节控制        */
   6          /*             本程序具有时钟,闹钟,年月日功能,均可以调节,而且还能够整点报时功能  */
   7          /*  说明:P3的4,5,6,7口连接键盘,有一列线接地。P1_0连接蜂鸣器。                  */
   8          /*  时间:2007年4月5号                                                              */
   9          /*  地点:湖南科大                                                                  */
  10          /************************************************************************************/
  11          #include<reg51.h>
  12          
  13          #define _TH0_TL0_ 	(65536 - 50000)  
  14          #define HI 			(_TH0_TL0_ / 256) //给高8位赋值3C
  15          #define LO 			(_TH0_TL0_ % 256) //给低8位赋值B0
  16          #define M 			20                //(1000/50)1秒要50个中断的累计
  17           
  18          sbit P1_0=P1^0;      //定义位变量
  19          sbit P2_0 = P2 ^ 0;  
  20          sbit P2_1 = P2 ^ 1;
  21          sbit P2_2 = P2 ^ 2;
  22          sbit P2_3 = P2 ^ 3;
  23          sbit P2_4 = P2 ^ 4;
  24          sbit P2_5 = P2 ^ 5;
  25          sbit P2_6 = P2 ^ 6;
  26          sbit P2_7 = P2 ^ 7;
  27          sbit P3_4 = P3 ^ 4;
  28          sbit P3_5 = P3 ^ 5;
  29          sbit P3_6 = P3 ^ 6;
  30          sbit P3_7 = P3 ^ 7;
  31          
  32          #define BEEP_on   P1_0=0;                 //蜂鸣器蜂鸣,可以整点报时,可以闹钟
  33          #define BEEP_off   P1_0=1;
  34          
  35          struct Time{                        
  36                      unsigned char hour;
  37          			unsigned char min;
  38          			unsigned char sec;
  39          			}clock={12,58,50};
  40          struct calendar{
  41                          unsigned int year;
  42          				unsigned char month;
  43          				unsigned char day;
  44                         }rili={1997,04,03};
  45          struct alarm{
  46                          unsigned char shi;
  47          				unsigned char fen;
  48          				unsigned char miao;
  49                         }naozhong={12,40,00};
  50          			   
  51          unsigned char SEG_TAB1[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};//0-9数字
  52          unsigned char SEG_TAB2[] = {0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10};//0.-9.数字
  53          unsigned char Led[6];  
  54          unsigned char tt[8];
  55          
C51 COMPILER V6.12  CLOCK                                                                  07/05/2007 08:11:03 PAGE 2   

  56          /*********************************************************************************************/
  57          
  58          void Delay(unsigned char a)            //延时程序
  59          {
  60   1      	unsigned char j; 
  61   1      	while(--a != 0)
  62   1      	{
  63   2      		for (j = 0; j < 125; j++);
  64   2      	}
  65   1      }
  66          
  67          /*********************************************************************************************/
  68          void Disp1(void)                                  //数码管显示时钟模块
  69          {
  70   1      		P2_0 = 0;            //第一个数码管显示时的十位		
  71   1      		Led[0] = clock.hour / 10;
  72   1      		P0 = SEG_TAB1[Led[0]];
  73   1      		Delay(2);
  74   1      		P2_0= 1;
  75   1      
  76   1      		P2_1 = 0;          //第2个数码管显示时的个位
  77   1      		Led[1] = clock.hour % 10;
  78   1      		P0 = SEG_TAB1[Led[1]];
  79   1      		Delay(2);
  80   1      		P2_1 = 1;
  81   1              
  82   1      		P2_2=0;P0=0xbf;Delay(4);P2_2=1;
  83   1      		
  84   1      		P2_3= 0;         //第4个数码管显示分的十位
  85   1      		Led[2] = clock.min / 10;
  86   1      		P0 = SEG_TAB1[Led[2]];
  87   1      		Delay(2);	
  88   1      		P2_3= 1;
  89   1      
  90   1      		P2_4 = 0;        //第5个数码管显示分的个位		
  91   1      		Led[3] = clock.min % 10;
  92   1      		P0 = SEG_TAB1[Led[3]];
  93   1      		Delay(2);
  94   1      		P2_4 = 1;
  95   1              
  96   1      		P2_5=0;P0=0xbf;Delay(4);P2_5=1;
  97   1      		
  98   1      		P2_6 = 0;        //第7个数码管显示秒的十位
  99   1      		Led[4] = clock.sec / 10;
 100   1      		P0 = SEG_TAB1[Led[4]];
 101   1      		Delay(2);	
 102   1      		P2_6 = 1;
 103   1      
 104   1      		P2_7 = 0;         //第8个数码管显示秒的个位。
 105   1      		Led[5] = clock.sec % 10;
 106   1      		P0 = SEG_TAB1[Led[5]];	
 107   1      		Delay(2);	
 108   1      		P2_7= 1;
 109   1              
 110   1              if(clock.sec==0&&clock.min==0)     //增加整点报时功能,
 111   1               {
 112   2      		  BEEP_on;
 113   2      		  Delay(100);
 114   2                BEEP_off;
 115   2      		 }
 116   1      }
 117                 
C51 COMPILER V6.12  CLOCK                                                                  07/05/2007 08:11:03 PAGE 3   

 118          void Disp2(void)                             //数码管显示日历模块
 119          {        
 120   1              P2_7=0;       //后两个数码管显示日期
 121   1              tt[0]=rili.day%10;
 122   1              P0 = SEG_TAB1[tt[0]];
 123   1              Delay(4);
 124   1              P2_7=1;
 125   1      
 126   1              P2_6=0;
 127   1              tt[1]=rili.day/10;
 128   1              P0 = SEG_TAB1[tt[1]];
 129   1              Delay(4);
 130   1              P2_6=1;
 131   1      
 132   1              P2_5=0;       //中间两个数码管显示月份
 133   1              tt[2]=rili.month%10;
 134   1              P0 = SEG_TAB2[tt[2]];
 135   1              Delay(4);
 136   1              P2_5=1;
 137   1      
 138   1              P2_4=0;
 139   1              tt[3]=rili.month/10;
 140   1              P0 = SEG_TAB1[tt[3]];
 141   1              Delay(4);
 142   1              P2_4=1;
 143   1          
 144   1              P2_3=0;       //前四个数码管显示年
 145   1              tt[4]=rili.year%10;
 146   1              P0 = SEG_TAB2[tt[4]];
 147   1              Delay(4);
 148   1              P2_3=1;
 149   1      
 150   1              P2_2=0;
 151   1              tt[5]=rili.year/10%10;
 152   1              P0 = SEG_TAB1[tt[5]];
 153   1              Delay(4);
 154   1              P2_2=1;
 155   1      
 156   1              P2_1=0;
 157   1              tt[6]=rili.year/100%10;
 158   1              P0 = SEG_TAB1[tt[6]];
 159   1              Delay(4);
 160   1              P2_1=1;
 161   1      
 162   1              P2_0=0;
 163   1              tt[7]=rili.year/1000%10;
 164   1              P0 = SEG_TAB1[tt[7]];
 165   1              Delay(4);
 166   1              P2_0=1;
 167   1      }
 168          
 169          void Disp3(void)                              //数码管显示闹钟模块
 170          {
 171   1      		P2_0 = 0;   //第一个数码管显示闹钟时的个位		
 172   1      		Led[0] = naozhong.shi / 10;
 173   1      		P0 = SEG_TAB1[Led[0]];
 174   1      		Delay(3);
 175   1      		P2_0= 1;
 176   1      
 177   1      		P2_1 = 0;//第2个数码管显示闹钟时的十位
 178   1      		Led[1] = naozhong.shi % 10;
 179   1      		P0 = SEG_TAB1[Led[1]];
C51 COMPILER V6.12  CLOCK                                                                  07/05/2007 08:11:03 PAGE 4   

 180   1      		Delay(3);
 181   1      		P2_1 = 1;
 182   1              
 183   1      		P2_2=0;P0=0xbf;Delay(4);P2_2=1;
 184   1      		
 185   1      		P2_3= 0;//第4个数码管显示闹钟分的个位
 186   1      		Led[2] = naozhong.fen / 10;
 187   1      		P0 = SEG_TAB1[Led[2]];
 188   1      		Delay(3);	
 189   1      		P2_3= 1;
 190   1      
 191   1      		P2_4 = 0;//第5个数码管显示闹钟分的十位		
 192   1      		Led[3] = naozhong.fen % 10;
 193   1      		P0 = SEG_TAB1[Led[3]];
 194   1      		Delay(3);
 195   1      		P2_4 = 1;
 196   1              
 197   1      		P2_5=0;P0=0xbf;Delay(5);P2_5=1;
 198   1      		
 199   1      		P2_6 = 0;//第7个数码管显示闹钟秒的个位	
 200   1      		Led[4] = naozhong.miao / 10;
 201   1      		P0 = SEG_TAB1[Led[4]];

⌨️ 快捷键说明

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