?? lcdsim.ini
字號:
/*----------------------------------------------------------------------------
* Name: Sim.ini
* Purpose: Functions used for simulating peripherals
* Version: V1.0
*----------------------------------------------------------------------------
* 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 it.
*
* Copyright (c) 2005-2007 Keil Software.
*---------------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Analog0() simulates analog input values given to channel-0 (AD00) */
/*-------------------------------------------------------------------*/
Signal void analog1 (float limit) {
float volts;
/* printf ("Analog1 (%f) entered.\n", limit); */
while (1) { /* forever */
volts = 0;
while (volts <= limit) {
ADC1_IN1 = volts; /* analog input-1 */
twatch (100000); /* 100000 Cycles Time-Break */
volts += 0.01; /* increase voltage */
}
volts = limit;
while (volts >= 0.0) {
ADC1_IN1 = volts; /* analog input-1 */
twatch (100000); /* 100000 Cycles Time-Break */
volts -= 0.01; /* 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()
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -