📄 can_simulate.ini
字号:
/******************************************************************************/
/* CAN_Simulate.ini Script for simulator, for simulating CAN loopback and AD */
/******************************************************************************/
// <<< Use Configuration Wizard in Context Menu >>> //
/******************************************************************************/
/* This file is part of the uVision/ARM development tools. */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved. */
/* 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. */
/******************************************************************************/
/*----------------------------------------------------------------------------*/
/* CAN_loopback_1_to_2() simulates loopback connection from CAN1 to CAN2 port */
/*----------------------------------------------------------------------------*/
signal void CAN_loopback_1_to_2 (void) {
while (1) {
wwatch(CAN1OUT);
CAN2ID = CAN1ID;
CAN2B0 = CAN1B0; CAN2B1 = CAN1B1; CAN2B2 = CAN1B2; CAN2B3 = CAN1B3;
CAN2B4 = CAN1B4; CAN2B5 = CAN1B5; CAN2B6 = CAN1B6; CAN2B7 = CAN1B7;
CAN2L = CAN1L;
CAN2IN = CAN1OUT;
}
}
/*----------------------------------------------------------------------------*/
/* CAN_loopback_2_to_1() simulates loopback connection from CAN2 to CAN1 port */
/*----------------------------------------------------------------------------*/
signal void CAN_loopback_2_to_1 (void) {
while (1) {
wwatch(CAN2OUT);
CAN1ID = CAN2ID;
CAN1B0 = CAN2B0; CAN1B1 = CAN2B1; CAN1B2 = CAN2B2; CAN1B3 = CAN2B3;
CAN1B4 = CAN2B4; CAN1B5 = CAN2B5; CAN1B6 = CAN2B6; CAN1B7 = CAN2B7;
CAN1L = CAN2L;
CAN1IN = CAN2OUT;
}
}
/*----------------------------------------------------------------------------*/
/* Analog0() simulates analog input values given to channel-0 (AD00) */
/*----------------------------------------------------------------------------*/
Signal void analog0 (float limit) {
float volts;
/* printf ("Analog0 (%f) entered.\n", limit); */
while (1) { /* forever */
volts = 0;
while (volts <= limit) {
AD00 = volts; /* analog input-0 */
twatch (100000); /* 100000 Cycles Time-Break */
volts += 0.01; /* increase voltage */
}
volts = limit;
while (volts >= 0.0) {
AD00 = volts;
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 = P1.24..P1.27
* - RS = P1.28
* - RW = P1.29
* - E = P1.31
*/
define unsigned long oldPORT1;
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;
MAP 0x10000000, 0x1000004F READ WRITE // LCD Memory
oldPORT1 = PORT1;
Cursor = 0;
bitpos = 0;
_E = 0x80000000;
_RW = 0x20000000;
_RS = 0x10000000;
_CTRL = 0xB0000000;
_DATA = 0x0F000000;
// Clear Display Function
Func void LCD_Clear (void) {
unsigned char i;
for (i = 0; i < 80; i++) {
_WBYTE(0x10000000 + i, 0x20);
}
Cursor = 0;
}
// LCD Display Signal Function
Signal void LCD_Display (void) {
unsigned char val;
while (1) {
wwatch(PORT1); // Wait for write to PORT1
if ((PORT1 & _RW) == 0) {
// Write to Display
if (((oldPORT1 & _E) != 0) && ((PORT1 & _E) == 0)) {
// E: 1->0
if ((PORT1 & _RS) == 0) {
// Write Command
val = ((PORT1 & _DATA) >> 24);
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(0x10000000 + Cursor);
val &= 0xF0 >> bitpos;
val |= ((PORT1 & _DATA) >> 24) << bitpos;
_WBYTE(0x10000000 + Cursor, val);
if (bitpos == 0) Cursor++;
}
bitpos ^= 4;
}
} else {
// Read from Display
if (((oldPORT1 & _E) == 0) && ((PORT1 & _E) != 0)) {
// E: 0->1
if ((PORT1 & _RS) == 0) {
// Read Status
val = (0x7F >> bitpos) & 0x0F;
} else {
// Read Pointer
val = ((Cursor & 0x7F) >> bitpos) & 0x0F;
}
PORT1 &= ~_DATA;
PORT1 |= val << 24;
bitpos ^= 4;
}
}
oldPORT1 = PORT1;
}
}
LCD_Display()
kill button *
define button "Analog sweep 0 .. 3.3V", "analog0 (3.3)"
define button "Analog sweep STOP", "signal kill analog0"
define button "CAN loopback ON", "CAN_loopback_1_to_2 (); CAN_loopback_2_to_1 ();"
define button "CAN loopback OFF", "signal kill CAN_loopback_1_to_2; signal kill CAN_loopback_2_to_1;"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -