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

📄 ex6-4.lst

📁 本压缩文件主要介绍温度传感芯片的应用
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   EX6_4                                                                 11/21/2008 00:54:13 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE EX6_4
OBJECT MODULE PLACED IN ex6-4.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ex6-4.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*
   2          标题:范例6-4
   3          版本:1.0
   4          Target:89S51
   5          程序描述:智能温度感测器,这个范例中使用到
   6          (1)8051 的Port 1连接到LCD显示器,PORT 3的P3.3,P3.4和P3.5分别连接到LCD显示器的控制线,程序执行时可以让LCD
             -显示器显示出时间和日期。
   7          (2)温度感测组件AD590经由ADC0804将感测到的温度,转换成数字数据,然后经由PORT 0输入8051。
   8          (3)8051的第10和第11只脚RXD和TXD分别连线到MAX232,然后连接到PC的COM埠。
   9          (4)8051实验板每 小时就读入ADC0804转换的数字温度数据,然后记录在串行式EEPROM 93C66中。
  10          (5)8051实验板可以经由RS232将记录在串行EEPROM 93C66中的数字温度数据传送PC端。*/
  11          /* ***************************************************** */
  12          #include <REGX51.H>
  13          #include <lcd.h>
  14          #define   XTAL             11059200
  15          #define   baudrate         9600
  16          #define   TIMES            25
  17          #define   TIMER0_COUNT    0xD8F0  /* 10000h-((12,000,000/(12*100)) */
  18          /* 数字时钟的工作模式 */
  19          #define   SET              11
  20          #define   TRUE             1
  21          #define   FALSE            0
  22          #define   putchar          write_LCD_data
  23          #define   adc_in           P0
  24          #define   adc_rd           P3_7
  25          #define   adc_wr           P3_6
  26          //
  27          #define   mode_button         P2_2
  28          #define   operation_button    P2_0
  29          #define   up_button      1  
  30          #define   down_button    1
  31          #define   heat      P2_3
  32          #define   cool      P2_1
  33          //
  34          typedef struct { 
  35                          char    hour;
  36                          char    minute;
  37                          char    second;
  38          } time;
  39          typedef struct { 
  40                          char    year;
  41                          char    month;
  42                          char    day;
  43          } date;
  44          time now={23,59,0},display;
  45          date today={04,12,15},tmpday;
  46          static unsigned timer0_tick=100,mode=0,operation;
  47          char code  dayofmonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
  48          char code       weekday[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
  49          char code         int2char[10]="0123456789";
  50          unsigned    char txOK,c,set_time;
  51          int ii;
  52          int      AT93C66_add,send_count;
  53          int heatfast=1;
  54          int   t,t1,tt,tt1;
C51 COMPILER V8.08   EX6_4                                                                 11/21/2008 00:54:13 PAGE 2   

  55          int   min,max;
  56          // 0 表示不记录在 AT93C66, 1 表示要记录在 AT93C66中     
  57          unsigned          char temp_wr;
  58          /*
  59                          AT93C66的读写程序
  60          */
  61          unsigned char   read_byte(int);
  62          void            write_byte(int,unsigned char);
  63          void delay(void)
  64          {
  65   1              unsigned char i,j;
  66   1              for(i=0;i<125;i++)
  67   1                      for(j=0;j<255;j++)
  68   1                      ;
  69   1      }
  70          void display_tempreture(unsigned char number)
  71          {
  72   1              unsigned char x,y;
  73   1              y=number-130;
  74   1      
  75   1                SBUF=number;         // 传送数据
  76   1      
  77   1                      //***************************
  78   1             if(y>=min&&y<=max) 
  79   1                 {
  80   2                 heat=1;
  81   2                 cool=1;
  82   2                 }
  83   1                 else if(y<min) 
  84   1                 {
  85   2                 if(heatfast==1){ heat=0;cool=1; P2=0X9F; }   //慢加热
  86   2                 else if(heatfast==2) {heat=1;cool=0; P2=0XDF; }   //快加热
  87   2              }
  88   1                 else if(y>max)  { cool=0;heat=0; } //制冷
  89   1                 //**********************************************
  90   1              x=y/10;
  91   1              gotoxy(1,9);
  92   1              write_LCD_data(int2char[x]);
  93   1              x=y%10;
  94   1              write_LCD_data(int2char[x]);
  95   1              if( temp_wr==1) {
  96   2                    write_byte(AT93C66_add,y);
  97   2                    if(AT93C66_add > 255) {
  98   3                            write_byte(0,1);
  99   3                            x=AT93C66_add -256;
 100   3                            write_byte(1,x);
 101   3                    } else write_byte(1,(unsigned char)AT93C66_add);
 102   2                    temp_wr=0;
 103   2                    AT93C66_add++;
 104   2              }
 105   1      }
 106          void display_time(void)
 107          {
 108   1              gotoxy(1,0);
 109   1              display_LCD_number(display.hour);
 110   1              display_LCD_string(":");
 111   1              display_LCD_number(display.minute);
 112   1              display_LCD_string(":");
 113   1              display_LCD_number(display.second);
 114   1      }
 115          void display_date()
 116          {
C51 COMPILER V8.08   EX6_4                                                                 11/21/2008 00:54:13 PAGE 3   

 117   1          char i,days=4;
 118   1              gotoxy(2,2);
 119   1              display_LCD_number(tmpday.year);
 120   1              display_LCD_string("/");
 121   1              display_LCD_number(tmpday.month);
 122   1              display_LCD_string("/");
 123   1              display_LCD_number(tmpday.day);
 124   1              display_LCD_string(" ");
 125   1              if(tmpday.month > 1)
 126   1                   for(i=0;i<=tmpday.month-2;i++)
 127   1                         days+=(dayofmonth[i]%7);
 128   1              if( tmpday.year !=0 ) days+=((tmpday.year-1)/4)
 129   1                    +tmpday.year+1;
 130   1              if (tmpday.year%4==0 && tmpday.month >2) days++;
 131   1              days=(days+tmpday.day) % 7;
 132   1              display_LCD_string(&weekday[days][0]);
 133   1      }
 134          char monthday(char year,char month)
 135          {
 136   1              if(month==2 && year%4==0)        //润年的2月有29天
 137   1              return(29);
 138   1              else
 139   1                 return(dayofmonth[month-1]);  //非闰年时的该月份天数
 140   1      }
 141          static void timer0_isr(void) interrupt  TF0_VECTOR using 1
 142          {
 143   1           TR0=0;
 144   1           TL0=(TIMER0_COUNT & 0x00FF);
 145   1           TH0=(TIMER0_COUNT >> 8);
 146   1           TR0=1;
 147   1           if(mode==1) return;
 148   1           if(--timer0_tick) return;
 149   1               /****************************************
 150   1                 if (timer0_tick==times) {
 151   1          i++;
 152   1              if(i==4) i=0;
 153   1              timer0_tick=0;
 154   1              if (status==FORWARD) heat=forward[i];
 155   1        }      
 156   1       ***************************/
 157   1           timer0_tick=100;
 158   1                       adc_wr=0;
 159   1               now.second++; //秒加1
 160   1                    if(timer0_tick%2==0)
 161   1                        {
 162   2                        adc_wr=1;  
 163   2                      temp_wr=1;   }                     
 164   1                           if (now.second==60) {                //如果秒等于60
 165   2                             now.second=0; 
 166   2                        //秒恢复为0
 167   2                         now.minute++;  
 168   2                      
 169   2                       //分加1
 170   2                if (now.minute==60) {           //如果分等于60
 171   3                     now.minute=0;             //分恢复为0
 172   3                          now.hour++;               //时加1
 173   3                     if (now.hour==24) {       //如果时等于24
 174   4                          now.hour=0;          //时恢复为0
 175   4                          today.day++;         //日加1
 176   4                          if (today.day>monthday(today.year,today
 177   4                                                 .month)) {
 178   5                          today.day=1; //如果日超过当月最大日数,就变成1
C51 COMPILER V8.08   EX6_4                                                                 11/21/2008 00:54:13 PAGE 4   

 179   5                          today.month++;       //月加1
 180   5                             if(today.month==13) {   //如果月等于13
 181   6                                 today.month=1;      //月恢复为1
 182   6                                 today.year++;       //年加1
 183   6                                     }
 184   5                               }
 185   4                               tmpday=today;
 186   4                               display_date();
 187   4                          }
 188   3                   }
 189   2          }
 190   1          display=now;
 191   1          display_time();
 192   1      }
 193          static void timer0_initialize(void)
 194          {
 195   1              EA=0;   
 196   1              TR0=0;
 197   1              TMOD &= 0XF0;
 198   1              TMOD |=0x01;
 199   1              TL0=(TIMER0_COUNT & 0x00FF);
 200   1              TH0=(TIMER0_COUNT >> 8);
 201   1              PT0=0;
 202   1              ET0=1;
 203   1              TR0=1;
 204   1              EA=1;
 205   1      }
 206          static void int0_isr(void) interrupt 0 using 0
 207          {
 208   1              unsigned char voltage;
 209   1              adc_in=0xFF;
 210   1              adc_rd=0;
 211   1              voltage=adc_in; 
 212   1              adc_rd=1;
 213   1              display_tempreture(voltage);    
 214   1      }
 215          static void com_isr(void) interrupt SIO_VECTOR using 1
 216          {
 217   1              if(TI) {
 218   2                   TI=0;
 219   2                  /* if (send_count < AT93C66_add) {
 220   2                        SBUF=read_byte(send_count)+32; // 传送数据
 221   2                        send_count++;
 222   2                   }  */
 223   2              }
 224   1      }
 225          void com_initialize(void) {
 226   1              PCON |= 0x80;
 227   1              TMOD=0x20;
 228   1              TH1=(unsigned char) (256-(XTAL/(16L*12L*baudrate)));
 229   1              TR1=(unsigned char) (256-(XTAL/(16L*12L*baudrate)));
 230   1              SCON=0x50;
 231   1              ES=1;
 232   1              TR1=1;
 233   1      }
 234          char gotkey() {
 235   1              if (mode_button==0) {
 236   2                      delay();
 237   2                      if (mode_button==0) return(0);
 238   2              }
 239   1              if (operation_button==0) {
 240   2                      delay();
C51 COMPILER V8.08   EX6_4                                                                 11/21/2008 00:54:13 PAGE 5   

 241   2                      if (operation_button==0) return(1);
 242   2              }
 243   1              if (up_button==0) {
 244   2                      delay();
 245   2                      if (up_button==0) return(2);
 246   2              }
 247   1          if (down_button==0) {

⌨️ 快捷键说明

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