51单片机C语言常用模块与综合系统设计实例精讲

源代码在线查看: function.lst

软件大小: 7344 K
上传用户: jyq110
关键词: 51单片机C语言 模块 设计实例
下载地址: 免注册下载 普通下载 VIP

相关代码

				C51 COMPILER V7.06   FUNCTION                                                              10/13/2006 09:21:09 PAGE 1   
				
				
				C51 COMPILER V7.06, COMPILATION OF MODULE FUNCTION
				OBJECT MODULE PLACED IN function.OBJ
				COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE function.c LARGE BROWSE DEBUG OBJECTEXTEND
				
				stmt level    source
				
				   1          #include 
				   2          #include 
				   3          #include 
				   4          #include 
				   5          #include "source.h"     
				   6          /*设置串口的波特率为19.2k*/     
				   7          void init_serial(void)
				   8          { 
				   9   1          unsigned char ch;
				  10   1              SCON = 0x50;   
				  11   1          ch=TMOD;
				  12   1              ch=ch&0x0f;
				  13   1              TMOD=ch|0x20;       
				  14   1              PCON=0XF0; // DIV 16
				  15   1              TH1=251;
				  16   1              TH0=TH1; /**波特率为19.2k***/
				  17   1              TR1=1; // 使定时器1运行
				  18   1              ES=1;//使能串口中断
				  19   1      }
				  20          /*系统初始化*/
				  21          void init_system(void){
				  22   1              test_timer_len=TEST_TIME_LENGTH;
				  23   1      }
				  24          /*把字节变为BCD码*/
				  25          unsigned char chtobcd(unsigned char ch){
				  26   1              unsigned char tmp=0;
				  27   1              tmp=ch/10;
				  28   1              tmp 				  29   1              tmp +=ch%10;
				  30   1              return tmp;
				  31   1      }
				  32          /*在固定位置(POS_TIMEX,POS_TIMEY)显示时间*/
				  33          void show_time(void){
				  34   1              if(updtime&UPD_YEAR){
				  35   2                      draw_wordw16(POS_TIMEX+2,POS_TIMEY,33,number16x33[2]);//draw 200x year
				  36   2                      draw_wordw16(POS_TIMEX+4,POS_TIMEY,33,number16x33[0]);
				  37   2                      draw_wordw16(POS_TIMEX+6,POS_TIMEY,33,number16x33[rtc.hnumy]);
				  38   2                      draw_wordw16(POS_TIMEX+8,POS_TIMEY,33,number16x33[rtc.lnumy]);
				  39   2                      draw_wordw32(POS_TIMEX+10,POS_TIMEY,33,nian);
				  40   2                      updtime &=~UPD_YEAR;
				  41   2              }
				  42   1              if(updtime&UPD_MONTH){
				  43   2                      draw_wordw16(POS_TIMEX+0,POS_TIMEY+33,33,number16x33[rtc.hnummon]);
				  44   2                      draw_wordw16(POS_TIMEX+2,POS_TIMEY+33,33,number16x33[rtc.lnummon]);
				  45   2                      draw_wordw32(POS_TIMEX+4,POS_TIMEY+33,33,yue);
				  46   2                      updtime &=~UPD_MONTH;
				  47   2              }
				  48   1              if(updtime&UPD_DAYOM){
				  49   2                      draw_wordw16(POS_TIMEX+8,POS_TIMEY+33,33,number16x33[rtc.hnumdom]);
				  50   2                      draw_wordw16(POS_TIMEX+10,POS_TIMEY+33,33,number16x33[rtc.lnumdom]);
				  51   2                      draw_wordw32(POS_TIMEX+12,POS_TIMEY+33,33,ri);
				  52   2                      updtime &=~UPD_DAYOM;
				  53   2              }
				  54   1              if(updtime&UPD_DAYOW){
				  55   2                      updtime &=~UPD_DAYOW;
				C51 COMPILER V7.06   FUNCTION                                                              10/13/2006 09:21:09 PAGE 2   
				
				  56   2              }
				  57   1              if(updtime&UPD_HOUR){
				  58   2                      draw_wordw16(POS_TIMEX+0,POS_TIMEY+66,33,number16x33[rtc.hnumh]);
				  59   2                      draw_wordw16(POS_TIMEX+2,POS_TIMEY+66,33,number16x33[rtc.lnumh]);
				  60   2                      draw_wordw8(POS_TIMEX+4,POS_TIMEY+66,33,timeseperate);
				  61   2                      updtime &=~UPD_HOUR;
				  62   2              }
				  63   1              if(updtime&UPD_MINUTE){
				  64   2                      draw_wordw16(POS_TIMEX+5,POS_TIMEY+66,33,number16x33[rtc.hnummin]);
				  65   2                      draw_wordw16(POS_TIMEX+7,POS_TIMEY+66,33,number16x33[rtc.lnummin]);
				  66   2                      draw_wordw8(POS_TIMEX+9,POS_TIMEY+66,33,timeseperate);
				  67   2                      updtime &=~UPD_MINUTE;
				  68   2              }
				  69   1              if(updtime&UPD_SECOND){
				  70   2                      draw_wordw16(POS_TIMEX+10,POS_TIMEY+66,33,number16x33[rtc.hnums]);
				  71   2                      draw_wordw16(POS_TIMEX+12,POS_TIMEY+66,33,number16x33[rtc.lnums]);
				  72   2                      updtime &=~UPD_SECOND;
				  73   2              }
				  74   1      }
				  75          /*在固定位置(POS_SHOW_WDX,POS_SHOW_WDY)显示温度*/
				  76          void show_wd(unsigned char tempe){
				  77   1              unsigned char tmp;
				  78   1              tmp=tempe;
				  79   1              if(tmp&0x80){//如温度小于0,则显示0度
				  80   2                      tmp=0;
				  81   2              }
				  82   1              if(tmp>=10){
				  83   2                      draw_wordw24(POS_SHOW_WDX ,POS_SHOW_WDY,48,number24x48[tmp/10]);//centigrade
				  84   2                      draw_wordw24(POS_SHOW_WDX+3 ,POS_SHOW_WDY,48,number24x48[tmp%10]);
				  85   2                      draw_wordw32(POS_SHOW_WDX+6 ,POS_SHOW_WDY,48,centigrade32x48);
				  86   2              }
				  87   1              else{
				  88   2                      clr_wordw24(POS_SHOW_WDX   ,POS_SHOW_WDY,48);
				  89   2                      clr_wordw24(POS_SHOW_WDX+3 ,POS_SHOW_WDY,48);
				  90   2                      clr_wordw32(POS_SHOW_WDX+6 ,POS_SHOW_WDY,48);
				  91   2                      draw_wordw24(POS_SHOW_WDX+0 ,POS_SHOW_WDY,48,number24x48[tmp%10]);
				  92   2                      draw_wordw32(POS_SHOW_WDX+3 ,POS_SHOW_WDY,48,centigrade32x48);
				  93   2              }
				  94   1      }
				  95          /*把RTC的时间读到结构rtc中*/
				  96          void rtc_update(void){
				  97   1              SD2000_read_time(&rtc);
				  98   1              if(rtc.second!=rtc.presecond){
				  99   2                      updtime |=UPD_SECOND;
				 100   2                      rtc.presecond=rtc.second;
				 101   2                      rtc.hnums=(rtc.second>>4)&0xf;
				 102   2                      rtc.hnums %=10;
				 103   2                      rtc.lnums=rtc.second&0xf;
				 104   2                      rtc.lnums %=10;
				 105   2              }
				 106   1              if(rtc.minute!=rtc.preminute){
				 107   2                      send_hbs_msg(MSG_HBS_UPD_TIME);
				 108   2                      updtime |=UPD_MINUTE;
				 109   2                      rtc.preminute=rtc.minute;
				 110   2                      rtc.hnummin=(rtc.minute>>4)&0xf;
				 111   2                      rtc.hnummin %=10;
				 112   2                      rtc.lnummin=rtc.minute&0xf;
				 113   2                      rtc.lnummin %=10;
				 114   2              }
				 115   1              if(rtc.hour!=rtc.prehour){
				 116   2                      updtime |=UPD_HOUR;
				 117   2                      rtc.prehour=rtc.hour;
				C51 COMPILER V7.06   FUNCTION                                                              10/13/2006 09:21:09 PAGE 3   
				
				 118   2                      rtc.hnumh=(rtc.hour>>4)&0xf;
				 119   2                      rtc.hnumh %=10;
				 120   2                      rtc.lnumh=rtc.hour&0xf;
				 121   2                      rtc.lnumh %=10;
				 122   2              }
				 123   1              if(rtc.dayom!=rtc.predayom){
				 124   2                      updtime |=UPD_DAYOM;
				 125   2                      rtc.predayom=rtc.dayom;
				 126   2                      rtc.hnumdom=(rtc.dayom>>4)&0xf;
				 127   2                      rtc.hnumdom %=10;
				 128   2                      rtc.lnumdom=rtc.dayom&0xf;
				 129   2                      rtc.lnumdom %=10;
				 130   2              }
				 131   1              if(rtc.month!=rtc.premonth){
				 132   2                      updtime |=UPD_MONTH;
				 133   2                      rtc.premonth=rtc.month;
				 134   2                      rtc.hnummon=(rtc.month>>4)&0xf;
				 135   2                      rtc.hnummon %=10;
				 136   2                      rtc.lnummon=rtc.month&0xf;
				 137   2                      rtc.lnummon %=10;
				 138   2              }
				 139   1              if(rtc.year!=rtc.preyear){
				 140   2                      updtime |=UPD_YEAR;
				 141   2                      rtc.preyear=rtc.year;
				 142   2                      rtc.hnumy=(rtc.year>>4)&0xf;
				 143   2                      rtc.hnumy%=10;
				 144   2                      rtc.lnumy=rtc.year&0xf;
				 145   2                      rtc.lnumy%=10;
				 146   2              }
				 147   1      }
				 148          /*更新大的数字,为2位数字,如果高位为0则只显示个位数据*/
				 149          bit num_update(void){
				 150   1              if((scentry.storey[1]!=scentry.prestry[1])||(scentry.storey[0]!=scentry.prestry[0])){//ten digital of sto
				             -rey. 
				 151   2                      if(scentry.storey[1]!=0){
				 152   3                              draw_storey(POS_STOREY_ORGX,POS_STOREY_ORGY,scentry.storey[1]);
				 153   3                              draw_storey(POS_STOREY_ORGX+STOREY_WIDTH,POS_STOREY_ORGY,scentry.storey[0]);
				 154   3                      }
				 155   2                      else{//把数字显示在中间的位置.
				 156   3                              draw_storey(POS_STOREY_ORGX+STOREY_WIDTH/2,POS_STOREY_ORGY,scentry.storey[0]);
				 157   3                      }
				 158   2                      scentry.prestry[1]=scentry.storey[1];
				 159   2                      scentry.prestry[0]=scentry.storey[0];
				 160   2                      return 1;
				 161   2              }
				 162   1              else{
				 163   2                      return 0;
				 164   2              }
				 165   1      }
				 166          
				
				
				MODULE INFORMATION:   STATIC OVERLAYABLE
				   CODE SIZE        =   1480    ----
				   CONSTANT SIZE    =   ----    ----
				   XDATA SIZE       =   ----       1
				   PDATA SIZE       =   ----    ----
				   DATA SIZE        =   ----    ----
				   IDATA SIZE       =   ----    ----
				   BIT SIZE         =   ----    ----
				END OF MODULE INFORMATION.
				
				
				C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
							

相关资源