The MEASURE program uses analog and digital inputs to simulate a datalogger. You may watch the va

源代码在线查看: measure.ini

软件大小: 37 K
上传用户: lemon_zc1949
关键词: datalogger simulate MEASURE program
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*----------------------------------------------------------------------------
				 * Name:    Measure.ini
				 * Purpose: Functions used for simulating peripherals
				 * Version: V1.01
				 *----------------------------------------------------------------------------
				 * This file is part of the uVision/ARM development tools.
				 * This software may only be used under the terms of a valid, current,
				 * end user licence from KEIL for a compatible version of KEIL software
				 * development tools. Nothing else gives you the right to use this software.
				 *
				 * Copyright (c) 2005-2007 Keil Software. All rights reserved.
				 *----------------------------------------------------------------------------*/
				
				
				/*----------------------------------------------------------------------------
				  MyStatus shows analog and other values ...
				 *----------------------------------------------------------------------------*/
				FUNC void MyStatus (void)  {
				  printf ("=============================\n");
				  printf (" Analog-Input-1:  %f\n", ADC1_IN1);
				  printf (" Analog-Input-2:  %f\n", ADC1_IN2);
				  printf (" Analog-Input-3:  %f\n", ADC1_IN3);
				  printf (" GPIOA: %08X\n", PORTA);
				  printf (" GPIOC: %08X\n", PORTC);
				  printf ("=============================\n");
				}
				
				/*----------------------------------------------------------------------------
				  Simulate Push button S3 
				    Pins:
				      - S3 = PC.13
				 *----------------------------------------------------------------------------*/
				PORTC |= 0x002000;                      // set PC.13 high: Key Input
				
				// debug function for the push button S3
				signal void push_S3 (void)  {
				  PORTC &= ~0x002000;                   // set PC.13 low  (Key pressed)
				  swatch (0.025);                       // wait 25 msec
				  PORTC |= 0x002000;                    // set PC.13 high (Key released)
				}
				
				/*----------------------------------------------------------------------------
				  Simulate Push button S2 
				    Pins:
				      - S2 = PA.0
				 *----------------------------------------------------------------------------*/
				PORTA |= 0x000001;                      // set PC.13 high: Key Input
				
				// debug function for the push button S2
				signal void push_S2 (void)  {
				  PORTA &= ~0x000001;                   // set PA.0 low  (Key pressed)
				  swatch (0.025);                       // wait 25 msec
				  PORTA |= 0x000001;                    // set PA.0 high (Key released)
				}
				
				/*----------------------------------------------------------------------------
				  Analog1() simulates analog input values given to channel-1 (ADC1)
				 *----------------------------------------------------------------------------*/
				Signal void Analog1 (float limit)  {
				  float volts;
				
				  printf ("Analog1 (%f) entered.\n", limit);
				  while (1)  {                          // forever
				    volts = 0;
				    while (volts 				      ADC1_IN1 = volts;                 // analog input-1
				//      swatch (0.01);                    // wait 0.01 seconds
				      twatch (250000);                  // 250000 Cycles Time-Break
				      volts += 0.1;                     // increase voltage
				    }
				    volts = limit;
				    while (volts >= 0.0)  {
				      ADC1_IN1 = volts;
				//      swatch (0.01);                    // wait 0.01 seconds
				      twatch (250000);                  // 250000 Cycles Time-Break
				      volts -= 0.1;                     // decrease voltage
				    }
				  }
				}
				
				/*----------------------------------------------------------------------------
				  Simulate LCD Display (2 line 40 character Text LCD with 4-bit Interface)
				    Pins:
				      - DB4..DB7 = PC.3..PC.0
				      - RS       = PC.12
				      - RW       = PC.11
				      - E        = PC.10
				 *----------------------------------------------------------------------------*/
				
				define unsigned long oldPORTC;
				define unsigned char Cursor;
				define unsigned char bitpos;
				define unsigned char Cmd;
				
				define unsigned long _E;
				define unsigned long _RW;
				define unsigned long _RS;
				define unsigned long _CTRL;
				define unsigned long _DATA;
				
				define unsigned char DataShift;
				define unsigned long LCDMem;
				
				MAP 0x10000000, 0x10000100 READ WRITE   // LCD Memory
				                                        // Use Memory watch window to display LCD
				
				DataShift = 0;                          // shift data to 0 position
				LCDMem    = 0x10000000;                 // memory to display LCD
				
				oldPORTC = PORTC;
				Cursor   = 0;
				bitpos   = 0;
				
				_E    = 0x00000400;
				_RW   = 0x00000800;
				_RS   = 0x00001000;
				_CTRL = 0x00001C00;
				_DATA = 0x0000000F;
				
				//Swap the data bits (0 = 3, 1 = 2, 2 = 1, 3 = 0)
				Func unsigned char Data_Swap (unsigned char c) {
				  unsigned char x;
				  x  = 0;
				  x |= (c & 0x01) 				  x |= (c & 0x02) 				  x |= (c & 0x04) >> 1;
				  x |= (c & 0x08) >> 3;
				  
				  return(x);
				}
				// Clear Display Function
				Func void LCD_Clear (void) {
				  unsigned char i;
				
				  for (i = 0; i < 80; i++) {
				//    _WBYTE(LCDMem + i, 0x20);
				    _WBYTE(LCDMem + i, 0x0);
				  }
				  Cursor = 0;
				}
				
				// LCD Display Signal Function
				Signal void LCD_Display (void) {
				  unsigned char val;
				
				  while (1) {
				    wwatch(PORTC);  // Wait for write to PORTC
				    if ((PORTC & _RW) == 0) {
				      // Write to Display
				      if (((oldPORTC & _E) != 0) && ((PORTC & _E) == 0)) {
				        // E: 1->0
				        if ((PORTC & _RS) == 0) {
				          // Write Command
				          val  = (Data_Swap(PORTC & _DATA) >> DataShift);
				          if (val == 3) {
				            bitpos = 4;
				          }
				          Cmd &= 0xF0 >> bitpos;
				          Cmd |= val 				          if (bitpos == 0) {
				            if (Cmd == 0x01) {
				              // Clear Display
				              LCD_Clear();
				            } else if (Cmd & 0x80) {
				              // Set Cursor Position
				              Cursor = Cmd & 0x7F;
				            }
				          }
				        } else {
				          // Write Data
				          val  = _RBYTE(LCDMem + Cursor);
				          val &= 0xF0 >> bitpos;
				          val |= (Data_Swap(PORTC & _DATA) >> DataShift) 				          _WBYTE(LCDMem + Cursor, val);
				          if (bitpos == 0) Cursor++;
				        }
				        bitpos ^= 4;
				      }
				    } else {
				      // Read from Display
				      if (((oldPORTC & _E) == 0) && ((PORTC & _E) != 0)) {
				        // E: 0->1
				        if ((PORTC & _RS) == 0) {
				          // Read Status
				          val = (0x7F >> bitpos) & 0x0F;
				        } else {
				          // Read Pointer
				          val = ((Cursor & 0x7F) >> bitpos) & 0x0F;
				        }
				        PORTC &= ~_DATA;
				        PORTC |=  (Data_Swap(val) 				        bitpos ^= 4;
				      }
				    }
				    oldPORTC = PORTC;
				  }
				}
				
				/* define a toolbar buttons */
				define button "Button S2", "push_S2 ()"
				define button "Button S3", "push_S3 ()"
				define button "My Status Info", "MyStatus ()"
				define button "Analog1 0..3V", "Analog1(3.0)"
				define button "Stop Analog1", "signal kill Analog1"
				
				LCD_Display()
							

相关资源