📄 blinky.ini
字号:
/*----------------------------------------------------------------------------
* Name: Sim.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.
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
Analog() simulates analog input values given to channel-1 (ADC1)
*----------------------------------------------------------------------------*/
Signal void Analog (float limit) {
float volts;
printf ("Analog (%f) entered.\n", limit);
while (1) { // forever
volts = 0;
while (volts <= limit) {
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) << 3;
x |= (c & 0x02) << 1;
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 << bitpos;
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) << bitpos;
_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) << DataShift);
bitpos ^= 4;
}
}
oldPORTC = PORTC;
}
}
LCD_Display()
Analog(3)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -