root/Examples_CP-JR_ARM7_LPC2368/ETT_LPC2368_Examples/USB_DEMO/USBCDC/Sim.ini

Revision 8, 4.2 kB (checked in by phil, 16 years ago)

Added Examples etc. from CD

Line 
1 /*----------------------------------------------------------------------------
2  *      Name:    Sim.ini
3  *      Purpose: Functions used for simulating peripherals
4  *      Version: V1.0
5  *----------------------------------------------------------------------------
6  *      This file is part of the uVision/ARM development tools.
7  *      This software may only be used under the terms of a valid, current,
8  *      end user licence from KEIL for a compatible version of KEIL software
9  *      development tools. Nothing else gives you the right to use it.
10  *
11  *      Copyright (c) 2005-2007 Keil Software.
12  *---------------------------------------------------------------------------*/
13
14 /*----------------------------------------------------------------------------
15  * caculate the values for the UART Devisor Latch LSB and MSB register
16  *---------------------------------------------------------------------------*/
17 func void baudrate (void) {
18   printf ("baudrate   9600 dll 0x%X\n", ((14400000UL / 16UL) + ( 9600-1))  /   9600);
19   printf ("baudrate  14400 dll 0x%X\n", ((14400000UL / 16UL) + ( 14400-1)) /  14400);
20   printf ("baudrate  19200 dll 0x%X\n", ((14400000UL / 16UL) + ( 19200-1)) /  19200);
21   printf ("baudrate  38400 dll 0x%X\n", ((14400000UL / 16UL) + ( 38400-1)) /  38400);
22   printf ("baudrate  57600 dll 0x%X\n", ((14400000UL / 16UL) + ( 57600-1)) /  57600);
23   printf ("baudrate 115200 dll 0x%X\n", ((14400000UL / 16UL) + (115200-1)) / 115200);
24 }
25
26
27 /*----------------------------------------------------------------------------
28  *  Simulate LCD Display (2 line 40 character Text LCD with 4-bit Interface)
29  *    Pins:
30  *      - DB4..DB7 = P1.24..P1.27
31  *      - RS       = P1.28
32  *      - RW       = P1.29
33  *      - E        = P1.31
34  *---------------------------------------------------------------------------*/
35
36 define unsigned long oldPORT1;
37 define unsigned char Cursor;
38 define unsigned char bitpos;
39 define unsigned char Cmd;
40
41 define unsigned long _E;
42 define unsigned long _RW;
43 define unsigned long _RS;
44 define unsigned long _CTRL;
45 define unsigned long _DATA;
46
47 define unsigned char DataShift;
48 define unsigned long LCDMem;
49
50 MAP 0x10000000, 0x1000004F READ WRITE   // LCD Memory
51
52 DataShift = 24;         // shift data to 0 position
53 LCDMem    = 0x10000000; // memory to display LCD
54
55 oldPORT1 = PORT1;
56 Cursor   = 0;
57 bitpos   = 0;
58
59 _E    = 0x80000000;
60 _RW   = 0x20000000;
61 _RS   = 0x10000000;
62 _CTRL = 0xB0000000;
63 _DATA = 0x0F000000;
64
65 // Clear Display Function
66 Func void LCD_Clear (void) {
67   unsigned char i;
68
69   for (i = 0; i < 80; i++) {
70 //    _WBYTE(LCDMem + i, 0x20);
71     _WBYTE(LCDMem + i, 0x0);
72   }
73   Cursor = 0;
74 }
75
76 // LCD Display Signal Function
77 Signal void LCD_Display (void) {
78   unsigned char val;
79
80   while (1) {
81     wwatch(PORT1);  // Wait for write to PORT1
82     if ((PORT1 & _RW) == 0) {
83       // Write to Display
84       if (((oldPORT1 & _E) != 0) && ((PORT1 & _E) == 0)) {
85         // E: 1->0
86         if ((PORT1 & _RS) == 0) {
87           // Write Command
88           val  = ((PORT1 & _DATA) >> DataShift);
89           if (val == 3) {
90             bitpos = 4;
91           }
92           Cmd &= 0xF0 >> bitpos;
93           Cmd |= val << bitpos;
94           if (bitpos == 0) {
95             if (Cmd == 0x01) {
96               // Clear Display
97               LCD_Clear();
98             } else if (Cmd & 0x80) {
99               // Set Cursor Position
100               Cursor = Cmd & 0x7F;
101             }
102           }
103         } else {
104           // Write Data
105           val  = _RBYTE(LCDMem + Cursor);
106           val &= 0xF0 >> bitpos;
107           val |= ((PORT1 & _DATA) >> DataShift) << bitpos;
108           _WBYTE(LCDMem + Cursor, val);
109           if (bitpos == 0) Cursor++;
110         }
111         bitpos ^= 4;
112       }
113     } else {
114       // Read from Display
115       if (((oldPORT1 & _E) == 0) && ((PORT1 & _E) != 0)) {
116         // E: 0->1
117         if ((PORT1 & _RS) == 0) {
118           // Read Status
119           val = (0x7F >> bitpos) & 0x0F;
120         } else {
121           // Read Pointer
122           val = ((Cursor & 0x7F) >> bitpos) & 0x0F;
123         }
124         PORT1 &= ~_DATA;
125         PORT1 |=  val << DataShift;
126         bitpos ^= 4;
127       }
128     }
129     oldPORT1 = PORT1;
130   }
131 }
132
133 LCD_Display()
Note: See TracBrowser for help on using the browser.