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

📄 lpc935.lst

📁 PHILIPS LPC935 MCU 利用其8路AD转换器,对监测对象进行数据采集,然后通过UART将采集到的数据发送到PC上位机
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.09   LPC935                                                                09/08/2005 22:25:29 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE LPC935
OBJECT MODULE PLACED IN lpc935.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lpc935.c LARGE OPTIMIZE(0,SPEED) BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "reg935.h"
   2          #define byte unsigned char
   3          #define word unsigned int
   4          #define TH0_DATA      0x6F                              // On Chip Oscillator (7.3728MHz ± 2.5%)10ms
   5          #define TL0_DATA      0xFF 
   6          
   7          #define true    1
   8          #define false   0
   9          #define High    1
  10          #define Low             0
  11          
  12          #define On              0
  13          #define Off             1
  14          
  15          //******** Time constant **************
  16          #define _10MS           1
  17          #define _20MS           2
  18          #define _30MS           3
  19          #define _50MS           5
  20          #define _100MS          10
  21          #define _200MS          20
  22          #define _250MS          25
  23          #define _300MS          30
  24          #define _500MS          50
  25          #define _800MS          80
  26          #define _1S             100
  27          #define _2S             200
  28          #define _3S             300
  29          #define _4S             400
  30          #define _5S             500
  31          #define _6S             600
  32          #define _7S     700
  33          #define _8S             800
  34          #define _10S            1000
  35          #define _20S            2000
  36          #define _900S           9000 
  37          
  38          //State Machina
  39          #define State_Start                     0       
  40          #define State_Work                      1
  41          
  42          //******************************************
  43          //变量定义
  44          bit Flag_100us=0;
  45          bit Flag_10ms=0;
  46          bit Flag_COM_Rec=0;
  47          bit Flag_Second=0;
  48          
  49          byte State=State_Start;
  50          byte COM_Rec_Buf;
  51          word RecWord=0;
  52          word RecTmp=0;
  53          word Temp_Word=0;
  54          
  55          byte Temp_Byte;
C51 COMPILER V7.09   LPC935                                                                09/08/2005 22:25:29 PAGE 2   

  56          byte Cnt_10ms=0;
  57          
  58          byte Temp=0;
  59          byte ADC_Time=0;
  60          byte ADC_BAT0=0;
  61          byte ADC_BAT1=0;
  62          byte ADC_BAT2=0;
  63          byte ADC_BAT3=0;
  64          byte ADC_BAT4=0;
  65          byte ADC_BAT5=0;
  66          byte ADC_BAT6=0;
  67          byte ADC_BAT7=0;
  68          byte Old_Minute=0;
  69          byte Minute_Cnt=0;
  70          byte Second_Cnt=0;
  71          byte Snd_Time_Cnt=0;   //SECOND
  72          
  73          //******************************************
  74          //脚位定义
  75          sbit CON_PIN0=P1^6;
  76          sbit CON_PIN1=P1^4;
  77          sbit CON_PIN2=P3^0;
  78          sbit CON_PIN3=P3^1;
  79          sbit CON_PIN4=P2^2;
  80          sbit CON_PIN5=P2^3;
  81          sbit CON_PIN6=P2^4;
  82          sbit CON_PIN7=P2^5;
  83          
  84          //******************************************
  85          //函数定义
  86          void    Init_hw();
  87          void    RecData();
  88          void    UART_init();
  89          void    Relay_Reset();
  90          void    Relay_On(byte Relay);
  91          void    Relay_Off(byte Relay);
  92          void    timer0_init();
  93          void    Clear_Timer(void);
  94          void    ADC_init();
  95          void    delayms(word ms);
  96          void    SIO_Out_Str(byte *pstr);
  97          void    SIO_Out_Hex(byte b);
  98          void    Do_ADC();
  99          void    delayus(word us);
 100          void    SIO_Out_Byte(byte b);
 101          bit     Check_Start(void);
 102          void    Do_Start(void);
 103          void    Send_AD_Result(void);
 104          void main()
 105          {
 106   1       //   word i;
 107   1      //      byte Temp_Byte;
 108   1              EA=0;
 109   1              Init_hw();
 110   1              timer0_init();
 111   1              Clear_Timer();
 112   1              UART_init();
 113   1              ADC_init();
 114   1              EA=1;
 115   1              CON_PIN0=Low;
 116   1              CON_PIN1=Low;
 117   1              CON_PIN2=Low;
C51 COMPILER V7.09   LPC935                                                                09/08/2005 22:25:29 PAGE 3   

 118   1              CON_PIN3=Low;
 119   1              CON_PIN4=Low;
 120   1              CON_PIN5=Low;
 121   1              CON_PIN6=Low;
 122   1              CON_PIN7=Low;
 123   1              SIO_Out_Str("Welcom to Battery test world!\r\n");
 124   1      /*
 125   1          while (1)
 126   1          {
 127   1                      Do_Start();
 128   1          }*/
 129   1              while (1)
 130   1              { 
 131   2                  /*if (Flag_Second)
 132   2                      {       
 133   2                              Flag_Second=false;
 134   2                              Second_Cnt++;
 135   2                              Snd_Time_Cnt++;
 136   2                              //Do_ADC();
 137   2                      }*/
 138   2                      if(Second_Cnt>=60)
 139   2                      {
 140   3                              Second_Cnt=0;
 141   3                              Minute_Cnt++;
 142   3                      }               
 143   2                      switch(State)
 144   2                      {
 145   3                              case State_Start:
 146   3                                              Do_Start();
 147   3                                              State=State_Work;
 148   3                                              Minute_Cnt=0;
 149   3                                              Second_Cnt=0;
 150   3                                              Snd_Time_Cnt=0;
 151   3                              break;
 152   3                              case State_Work:                
 153   3                                      /*if(Snd_Time_Cnt>=20)
 154   3                                      {
 155   3                                              EA=0;
 156   3                                              SIO_Out_Byte(ADC_BAT0);
 157   3                                              //SIO_Out_Byte(0x20);
 158   3                                              SIO_Out_Byte(ADC_BAT1);
 159   3                                              //SIO_Out_Byte(0x20);
 160   3                                              SIO_Out_Byte(ADC_BAT2);
 161   3                                              //SIO_Out_Byte(0x20);
 162   3                                              SIO_Out_Byte(ADC_BAT3);
 163   3                                              //SIO_Out_Byte(0x20);
 164   3                                              SIO_Out_Byte(ADC_BAT4);
 165   3                                              //SIO_Out_Byte(0x20);
 166   3                                              SIO_Out_Byte(ADC_BAT5);
 167   3                                              //SIO_Out_Byte(0x20);
 168   3                                              SIO_Out_Byte(ADC_BAT6);
 169   3                                              //SIO_Out_Byte(0x20);
 170   3                                              SIO_Out_Byte(ADC_BAT7);
 171   3                                              //SIO_Out_Byte(0x20);
 172   3                                              SIO_Out_Byte(0x0D);
 173   3                                              SIO_Out_Byte(0x0A);
 174   3                                              Snd_Time_Cnt=0;
 175   3                                              EA=1;
 176   3                                      }*/
 177   3                                      if(Minute_Cnt>=80) State=State_Start;
 178   3                                      if(!Check_Start()) Do_Start();
 179   3                              break;
C51 COMPILER V7.09   LPC935                                                                09/08/2005 22:25:29 PAGE 4   

 180   3                      }
 181   2              
 182   2              }
 183   1      
 184   1      
 185   1      }       // end main()
 186          
 187          
 188          //**************************************************
 189          
 190          
 191          
 192          void Init_hw(void)
 193          {
 194   1      //      P2M1=0x00;
 195   1      //      P2M2=0x00;
 196   1              P2M1=0x03;
 197   1              P2M2=0x00;
 198   1              P3M1=0x00;
 199   1              P3M2=0x00;
 200   1      //      P1M1=0x0C;
 201   1      //      P1M2=0x0C;
 202   1              P1M1=0x80;
 203   1              P1M2=0x00;
 204   1      //      P0M1=0x00;
 205   1      //      P0M2=0xFF;
 206   1              P0M1=0x1F;
 207   1              P0M2=0x00;
 208   1              AUXR1=1;
 209   1              DIVM=0;
 210   1              EA=0;
 211   1      }
 212          
 213          //**************************************************
 214          //串口 9600BAUDRATE N 8 1
 215          void UART_init()
 216          {
 217   1              // configure UART
 218   1        // clear SMOD0
 219   1              PCON &= ~0x40;
 220   1              SCON = 0x50;
 221   1        // set or clear SMOD1
 222   1              PCON &= 0x7f;
 223   1              PCON |= (0 << 8);
 224   1              SSTAT = 0x00;
 225   1      
 226   1        // configure baud rate generator
 227   1              BRGCON = 0x00;
 228   1              BRGR0 = 0xF0;           //7.373M  baudrate=9600   (BRGR1,BTGR0)=7.373M/9600-16
 229   1              BRGR1 = 0x02;
 230   1              BRGCON = 0x03;
 231   1      /*
 232   1        // TxD = push-pull, RxD = input
 233   1              P1M1 &= ~0x01;
 234   1              P1M2 |= 0x01;
 235   1              P1M1 |= 0x02;
 236   1              P1M2 &= ~0x02;
 237   1      */
 238   1          ESR=1;              //ESR=Enable Serial Recieve
 239   1      }
 240          
 241          void Rcv_ISR() interrupt 4
C51 COMPILER V7.09   LPC935                                                                09/08/2005 22:25:29 PAGE 5   

 242          { //当接收完一个字节RI置1进入Recieve中
 243   1              EA=0;           //
 244   1              if (RI)

⌨️ 快捷键说明

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