📄 f06x_uart1_interrupt.lst
字号:
C51 COMPILER V8.08 F06X_UART1_INTERRUPT 02/02/2008 09:37:19 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE F06X_UART1_INTERRUPT
OBJECT MODULE PLACED IN F06x_UART1_Interrupt.OBJ
COMPILER INVOKED BY: C:\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe F06x_UART1_Interrupt.c DB OE
line level source
1 //-----------------------------------------------------------------------------
2 // F06x_UART1_Interrupt.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2006 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // This program demonstrates how to configure the C8051F060 to write to and read
10 // from the UART interface. The program reads a word using the UART1 interrupts
11 // and outputs that word to the screen, with all characters in uppercase
12 //
13 // How To Test:
14 //
15 // 1) Download code to a 'F060 target board
16 // 2) Connect serial cable from the transceiver to a PC
17 // 3) On the PC, open HyperTerminal (or any other terminal program) and connect
18 // to the COM port at <BAUDRATE> and 8-N-1
19 // 4) Type up to 64 characters into the Terminal and press Enter. The MCU
20 // will then print back the characters that were typed
21 //
22 //
23 // Target: C8051F06x
24 // Tool chain: Keil C51 7.50 / Keil EVAL C51
25 // Command Line: None
26 //
27 // Release 1.0
28 // -Initial Revision (SM)
29 // -6 JUN 2007
30 //
31
32 //-----------------------------------------------------------------------------
33 // Includes
34 //-----------------------------------------------------------------------------
35
36 #include <C8051F060.h> // SFR declarations
37 #include <stdio.h>
38
39 //-----------------------------------------------------------------------------
40 // 16-bit SFR Definitions for 'F06x
41 //-----------------------------------------------------------------------------
42
43 sfr16 RCAP2 = 0xCA; // Timer2 capture/reload
44 sfr16 TMR2 = 0xCC; // Timer2
45
46 //-----------------------------------------------------------------------------
47 // Global Constants
48 //-----------------------------------------------------------------------------
49
50 #define BAUDRATE 115200 // Baud rate of UART in bps
51
52 // SYSTEMCLOCK = System clock frequency in Hz
53 //#define SYSTEMCLOCK 22118400L
54 #define SYSTEMCLOCK 24000000L
55 //-----------------------------------------------------------------------------
C51 COMPILER V8.08 F06X_UART1_INTERRUPT 02/02/2008 09:37:19 PAGE 2
56 // Function Prototypes
57 //-----------------------------------------------------------------------------
58
59 void OSCILLATOR_Init (void);
60 void PORT_Init (void);
61 void UART1_Init (void);
62
63 //-----------------------------------------------------------------------------
64 // Global Variables
65 //-----------------------------------------------------------------------------
66
67 #define UART_BUFFERSIZE 5
68 unsigned char UART_Buffer[UART_BUFFERSIZE];
69 unsigned char UART_Buffer_Size = 0;
70 unsigned char UART_Input_First = 0;
71 unsigned char UART_Output_First = 0;
72 unsigned char TX_Ready =1;
73 static char Byte;
74
75 //-----------------------------------------------------------------------------
76 // main() Routine
77 //-----------------------------------------------------------------------------
78
79 void main (void)
80 {
81 1
82 1 SFRPAGE = CONFIG_PAGE;
83 1
84 1 WDTCN = 0xDE; // Disable watchdog timer
85 1 WDTCN = 0xAD;
86 1
87 1 OSCILLATOR_Init (); // Initialize oscillator
88 1 PORT_Init (); // Initialize crossbar and GPIO
89 1
90 1 UART1_Init (); // Initialize UART1
91 1
92 1 EA = 1;
93 1
94 1 SFRPAGE = UART1_PAGE;
95 1
96 1 while (1)
97 1 { // If the complete word has been entered via the terminal followed
98 2 // by carriage return
99 2 if((TX_Ready == 1) && (UART_Buffer_Size != 0) && (Byte == 67))
100 2 {
101 3 TX_Ready = 0; // Set the flag to zero
102 3
103 3 TI1 = 1; // Set transmit flag to 1
104 3 }
105 2 }
106 1 }
107
108 //-----------------------------------------------------------------------------
109 // Initialization Subroutines
110 //-----------------------------------------------------------------------------
111
112 //-----------------------------------------------------------------------------
113 // OSCILLATOR_Init
114 //-----------------------------------------------------------------------------
115 //
116 // Return Value : None
117 // Parameters : None
C51 COMPILER V8.08 F06X_UART1_INTERRUPT 02/02/2008 09:37:19 PAGE 3
118 //
119 // This function initializes the system clock to use an external 22.1184MHz
120 // crystal.
121 //
122 //-----------------------------------------------------------------------------
123 void OSCILLATOR_Init (void)
124 {
125 1 int i; // Software timer
126 1
127 1 char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
128 1
129 1 SFRPAGE = CONFIG_PAGE; // Set SFR page
130 1
131 1 OSCICN = 0x83; // Set internal oscillator to run
132 1 // at its slowest frequency
133 1
134 1 CLKSEL = 0x00; // Select the internal osc. as
135 1 // the SYSTEMCLOCK source
136 1
137 1 // Initialize external crystal oscillator to use 22.1184 MHz crystal
138 1
139 1 OSCXCN = 0x67; // Enable external crystal osc.
140 1 for (i=0; i < 256; i++); // Wait at least 1ms
141 1
142 1 while (!(OSCXCN & 0x80)); // Wait for crystal osc to settle
143 1
144 1 CLKSEL = 0x01;
145 1 // Select external crystal as SYSTEMCLOCK source
146 1
147 1 SFRPAGE = SFRPAGE_SAVE; // Restore SFRPAGE
148 1 }
149
150 //-----------------------------------------------------------------------------
151 // PORT_Init
152 //-----------------------------------------------------------------------------
153 //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -