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

📄 ai.lst

📁 c8051f040 内部集成的温度传感器使用 直接给出温度的函数
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.17   AI                                                                    04/16/2009 17:40:13 PAGE 1   


C51 COMPILER V8.17, COMPILATION OF MODULE AI
OBJECT MODULE PLACED IN AI.OBJ
COMPILER INVOKED BY: c:\Keil\C51\BIN\C51.EXE AI.c LARGE OPTIMIZE(0,SPEED) BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*************************************************************************/
   2          /*                                                                       */
   3          /*        Copyright (c) 2006 CNRERD.                                     */
   4          /*                                                                       */
   5          /* PROPRIETARY RIGHTS of CNRERD are involved in the subject matter of    */
   6          /* this material. All manufacturing, reproduction, use, and sales rights */
   7          /*  pertaining to this subject matter are governed                       */
   8          /* by the license agreement.  The recipient of this software implicitly  */
   9          /* accepts the terms of the license.                                     */
  10          /*                                                                       */
  11          /*************************************************************************/
  12          
  13          /*************************************************************************/
  14          /*                                                                       */
  15          /* FILE NAME                                            VERSION          */
  16          /*                                                                       */
  17          /*      main.c                                             1.0           */
  18          /*                                                                       */
  19          /* COMPONENT                                                             */
  20          /*                                                                       */
  21          /*      C8051F040                                                        */
  22          /*                                                                       */
  23          /* AUTHOR                                                                */
  24          /*                                                                       */
  25          /*      Wang ZhongFu                                                     */
  26          /*                                                                       */
  27          /*                                                                       */
  28          /* DEPENDENCIES                                                          */
  29          /*                                                                       */
  30          /*      datatype.h                                                      */
  31          /*                                                                       */
  32          /* HISTORY                                                               */
  33          /*                                                                       */
  34          /*         DATE                    REMARKS                 author        */
  35          /*      10-21-2008         Created initial version 1.0     Wangzhongfu   */
  36          /*                                                                       */
  37          /*************************************************************************/
  38          #include "datatype.h"
  39          #include "C8051F040.h"  /*Register/bit definitions for the C8051F040*/
  40          #include <string.h>
  41          /***************************************************/
  42          /* define T0 macro functions           */
  43          /***************************************************/
  44          #define T0RUN SFRPAGE=0x00;TR0=1
  45          #define T0STOP SFRPAGE=0x00;TR0=0
  46          #define ADC0START SFRPAGE=0x00;AD0BUSY=1
  47          
  48          /***************************************************/
  49          /* define Analog  data             */
  50          /***************************************************/
  51          //#define STACK_LEN 128/*sample data length*/
  52          #define AlarmTemprature_LowLine  18.0
  53          #define AlarmTemprature_HighLine 20.0
  54          
  55          
C51 COMPILER V8.17   AI                                                                    04/16/2009 17:40:13 PAGE 2   

  56          //xdata         uchar stack_index=0;     /*index of sample data*/
  57          //xdata         uchar dataindex=0;       /*index of sample adding*/
  58          //xdata         ulong total;             /*tatol for sample data*/
  59          //uchar         ti=0;                    /*temprature adding count*/
  60          float   tempvalue;              /*temp value of temprature*/
  61          float   Sample_TempratureValue=0;
  62          //float xdata   temp16[20];    /*ADC0 16bit data*/ 
  63          xdata   uint SampleValue;   /*array for sample data*/
  64          float   Start_temprature=0;
  65          float   Sub_temprature=0;
  66          float   Enviroment_temprature=0;
  67          float   Enviroment_History_temprature=0;
  68          
  69          sbit RelayOut_ControlFan=P0^0;   
  70          sbit OutTest=P1^6;  
  71          
  72          
  73          uchar   temppage1;
  74          uint    Time_1_Minute_Switch=0;
  75          uint    Time_3_Minute_Switch=0;
  76          uchar   Temprature_Measure_Switch=0;
  77          uchar   Relay_Run_Stop_Switch=0;
  78          uchar   OutControl_Switch=1;
  79          /************************************/
  80          /* delay 1ms function               */
  81          /************************************/
  82          void delay1ms(uint time){
  83   1              uint i;
  84   1              uint j;
  85   1              for (i=0;i<time;i++){
  86   2                      for(j=0;j<300;j++);
  87   2              }
  88   1      }
  89          
  90          /************************************/
  91          /* c8051f040 initialization function */
  92          /************************************/
  93          void config(){
  94   1      //看门狗禁止
  95   1              WDTCN = 0x07;   
  96   1          WDTCN = 0xDE;   
  97   1              WDTCN = 0xAD;
  98   1      //交叉开关使能,但没有进行外围设备配置
  99   1              SFRPAGE = 0x0F;
 100   1              XBR0 = 0x00;    
 101   1              XBR1 = 0x00;    
 102   1              XBR2 = 0x40;
 103   1              XBR3 = 0x00; 
 104   1              
 105   1      //管脚输出配置,P4口、P5口、P6、P7、P2.0及P2.1为推挽模式,均为为数字输入口
 106   1      //P3.0-P3.3为开漏模式,P3.0-P3.3为数字输入口
 107   1      
 108   1              //SFRPAGE = 0x0F;
 109   1              P1MDOUT = 0x40;
 110   1              P0MDOUT = 0x01; 
 111   1      
 112   1      //晶振配置,采用外部晶振22.1184MHz
 113   1              //SFRPAGE = 0x0F;
 114   1              OSCICN |= 0x80; 
 115   1              //OSCXCN |= 0x67;                                          //Running at 22.1184MHz.     
 116   1              //while (!((OSCXCN & 0x80) == 0x80));
 117   1              CLKSEL |= 0x00;
C51 COMPILER V8.17   AI                                                                    04/16/2009 17:40:13 PAGE 3   

 118   1               
 119   1      }
 120          
 121          /************************************/
 122          /* T0 initialization function      */
 123          /************************************/
 124          void t0ini(void){               //设置T0为16位定时器模式
 125   1              SFRPAGE=0x00;
 126   1              TMOD  = 0x01;
 127   1          TCON  = 0x00;
 128   1              CKCON = 0x02;           //T0时钟为系统时钟48分频,即24.5MHZ/48/8
 129   1              TH0   = 62346/256;
 130   1              TL0   = 62346%256;      //计算T0初值:每隔50msT0产生一次中断,则计数值为
 131   1                                      //50ms/(48*8/24.5MHZ)=3190,因此计数初值为
 132   1                                      //65536-3190=62346
 133   1              ET0   =  1;             //开启T0中断6
 134   1      }
 135          
 136          
 137          void adc0_source(uchar source){//ADC0通道选择,为adc0_mux()的简化函数
 138   1              SFRPAGE=0x00;
 139   1              AMX0SL=source;
 140   1      }
 141          
 142          
 143          /************************************************/
 144          /* ADC0 initialization function       */
 145          /************************************************/
 146          void adc0_ini(){
 147   1              SFRPAGE=0x00;
 148   1              ADC0CF=0x81;//ADC0 clock is 17 divisions of system clock,PGA=1
 149   1              ADC0CN=0x80;
 150   1              /*AD0EN=1,ADC0 module enable
 151   1              AD0TM=0,ADC0 continous track model
 152   1              AD0CM1:AD0CM0=00b,ADC0BUSY start model
 153   1              AD0LJST=0*/
 154   1              REF0CN&=0x0E;//AD0VRS=0,ADC0 reference voltage is VREFA
 155   1              REF0CN|=0x07;//TEMPE=1,enable inner temprature sensor
 156   1              //p3anolog_ini(3);
 157   1              //adc0_mux(0x0C,0);
 158   1              //EIE2 |= 0x02;        //start ADC0 interrupt
 159   1      }
 160          
 161          /*************************************************************************/
 162          /*                                                                       */

⌨️ 快捷键说明

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