📄 dac.lst
字号:
C51 COMPILER V7.05 DAC 08/28/2005 16:58:27 PAGE 1
C51 COMPILER V7.05, COMPILATION OF MODULE DAC
OBJECT MODULE PLACED IN dac.OBJ
COMPILER INVOKED BY: C:\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe dac.c DB OE
stmt level source
1 #include "c8051f020.h"
2 //-----------------------------------------------------------------------------
3 sfr16 DP = 0x82; // data pointer
4 sfr16 TMR3RL = 0x92; // Timer3 reload value
5 sfr16 TMR3 = 0x94; // Timer3 counter
6 sfr16 ADC0 = 0xbe; // ADC0 data
7 sfr16 ADC0GT = 0xc4; // ADC0 greater than window
8 sfr16 ADC0LT = 0xc6; // ADC0 less than window
9 sfr16 RCAP2 = 0xca; // Timer2 capture/reload
10 sfr16 T2 = 0xcc; // Timer2
11 sfr16 RCAP4 = 0xe4; // Timer4 capture/reload
12 sfr16 T4 = 0xf4; // Timer4
13 sfr16 DAC0 = 0xd2; // DAC0 data
14 sfr16 DAC1 = 0xd5; // DAC1 data
15 //-----------------------------------------------------------------------------
16 // Function PROTOTYPES
17 //-----------------------------------------------------------------------------
18 void main (void);
19 void SYSCLK_Init (void);
20 void PORT_Init (void);
21 void UART0_Init (void);
22 void Timer4_Init (int counts);
23 void Timer4_ISR (void);
24 long pow(int x, int y);
25 void Print_Command_List(void);
26 void Sine(void);
27 void Square(void);
28 void Triangle(void);
29 void Saw(void);
30 void Off(void);
31 void Help(void);
32 void Error(void);
33 //-----------------------------------------------------------------------------
34 // Global CONSTANTS
35 //-----------------------------------------------------------------------------
36 #define SYSCLK 22118400 // SYSCLK frequency in Hz
37 #define BAUDRATE 9600 // Baud rate of UART in bps
38 #define SAMPLE_RATE_DAC 80000L // DAC sampling rate in Hz
39 #define PHASE_PRECISION 65536 // range of phase accumulator
40 #define command_length 2 // command length is 2 characters
41 #define command_size 3 // command size is 3 bytes
42 typedef struct Command_Table_Type { // when a command is entered, it is
43 char command[command_size]; // compared to the command field of
44 void (*function_ptr)(void); // of the table. If there is a match
45 }Command_Table_Type; // then the the function located at
46 // function_ptr will be executed
47 typedef enum Waveform { // the different possible output
48 SQUARE, // waveforms
49 SINE,
50 TRIANGLE,
51 SAW,
52 OFF
53 }Waveform;
54 typedef union lng { // access a long variable as two
55 long Long; // 16-bit integer values
C51 COMPILER V7.05 DAC 08/28/2005 16:58:27 PAGE 2
56 int Int[2];
57 } lng;
58 //-----------------------------------------------------------------------------
59 // Global Variables
60 //-----------------------------------------------------------------------------
61 unsigned long frequency = 1000; // frequency of output in Hz,
62 // defaults to 1000 Hz
63 unsigned int phase_add = 1000 * PHASE_PRECISION / SAMPLE_RATE_DAC;
64 unsigned int amplitude = 100 * 655; // 655 is a scaling factor
65 // see the Timer 4 ISR
66 Waveform output_waveform = OFF;
67 char input_str[16]= "";
68 #define num_commands 6
69 Command_Table_Type code function_table[num_commands + 1] = {
70 {"SQ", Square},
71 {"SI", Sine},
72 {"TR", Triangle},
73 {"SA", Saw},
74 {"OF", Off},
75 {"??", Help},
76 {"", Error}
77 };
78 // a full cycle, 16-bit, 2’s complement sine wave lookup table
79 int code SINE_TABLE[256] = {
80 0x0000, 0x0324, 0x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2,
81 0x18f8, 0x1c0b, 0x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11,
82 0x30fb, 0x33de, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a,
83 0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842,
84 0x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6,
85 0x6a6d, 0x6c24, 0x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504,
86 0x7641, 0x776c, 0x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3,
87 0x7d8a, 0x7e1d, 0x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6,
88 0x7fff, 0x7ff6, 0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d,
89 0x7d8a, 0x7ce3, 0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c,
90 0x7641, 0x7504, 0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24,
91 0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4,
92 0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4,
93 0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de,
94 0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b,
95 0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324,
96 0x0000, 0xfcdc, 0xf9b9, 0xf696, 0xf375, 0xf055, 0xed38, 0xea1e,
97 0xe708, 0xe3f5, 0xe0e7, 0xdddd, 0xdad8, 0xd7da, 0xd4e1, 0xd1ef,
98 0xcf05, 0xcc22, 0xc946, 0xc674, 0xc3aa, 0xc0e9, 0xbe32, 0xbb86,
99 0xb8e4, 0xb64c, 0xb3c1, 0xb141, 0xaecd, 0xac65, 0xaa0b, 0xa7be,
100 0xa57e, 0xa34c, 0xa129, 0x9f14, 0x9d0e, 0x9b18, 0x9931, 0x975a,
101 0x9593, 0x93dc, 0x9236, 0x90a1, 0x8f1e, 0x8dab, 0x8c4b, 0x8afc,
102 0x89bf, 0x8894, 0x877c, 0x8676, 0x8583, 0x84a3, 0x83d7, 0x831d,
103 0x8276, 0x81e3, 0x8163, 0x80f7, 0x809e, 0x8059, 0x8028, 0x800a,
104 0x8000, 0x800a, 0x8028, 0x8059, 0x809e, 0x80f7, 0x8163, 0x81e3,
105 0x8276, 0x831d, 0x83d7, 0x84a3, 0x8583, 0x8676, 0x877c, 0x8894,
106 0x89bf, 0x8afc, 0x8c4b, 0x8dab, 0x8f1e, 0x90a1, 0x9236, 0x93dc,
107 0x9593, 0x975a, 0x9931, 0x9b18, 0x9d0e, 0x9f14, 0xa129, 0xa34c,
108 0xa57e, 0xa7be, 0xaa0b, 0xac65, 0xaecd, 0xb141, 0xb3c1, 0xb64c,
109 0xb8e4, 0xbb86, 0xbe32, 0xc0e9, 0xc3aa, 0xc674, 0xc946, 0xcc22,
110 0xcf05, 0xd1ef, 0xd4e1, 0xd7da, 0xdad8, 0xdddd, 0xe0e7, 0xe3f5,
111 0xe708, 0xea1e, 0xed38, 0xf055, 0xf375, 0xf696, 0xf9b9, 0xfcdc,
112 };
113 code char string0[] = "\n\n*** OUTPUT IS NOW A ";
114 code char string1[] = "\n\n----------------------------------\n\n";
115 //-----------------------------------------------------------------------------
116 // MAIN Routine
117 //-----------------------------------------------------------------------------
C51 COMPILER V7.05 DAC 08/28/2005 16:58:27 PAGE 3
118 void main (void) {
119 1 char i; // counting variable
120 1
121 1
122 1 int printed_amplitude = 100; // a separate copy of amplitude because
123 1 // temp_amplitude is written over
124 1 void (*f)(void); // function pointer used to call the proper
125 1 // function from the command table
126 1 WDTCN = 0xde; // Disable watchdog timer
127 1 WDTCN = 0xad;
128 1 SYSCLK_Init ();
129 1 PORT_Init ();
130 1 // initializations for wave generation
131 1 REF0CN = 0x03; // enable internal VREF generator
132 1 DAC1CN = 0x97; // enable DAC1 in left-justified mode
133 1 Timer4_Init(SYSCLK/SAMPLE_RATE_DAC);
134 1 // using Timer4 as update scheduler
135 1 // initialize T4 to update DAC1
136 1 // after (SYSCLK cycles)/sample have
137 1 // passed.
138 1
139 1
140 1 EA = 1; // Enable global interrupts
141 1
142 1
143 1 } // end main
*** WARNING C280 IN LINE 119 OF DAC.C: 'i': unreferenced local variable
*** WARNING C280 IN LINE 124 OF DAC.C: 'f': unreferenced local variable
144 //-----------------------------------------------------------------------------
145 // Init Routines
146 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
148 // SYSCLK_Init
149 //-----------------------------------------------------------------------------
150 //
151 // This routine initializes the system clock to use a 22.1184MHz crystal
152 // as its clock source.
153 //
154 void SYSCLK_Init (void)
155 {
156 1 int i; // delay counter
157 1 OSCXCN = 0x67; // start external oscillator with
158 1 // 22.1184MHz crystal
159 1 for (i=0; i < 256; i++) ; // Wait for osc. to start up
160 1 while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
161 1 OSCICN = 0x88; // select external oscillator as SYSCLK
162 1 // source and enable missing clock
163 1 // detector
164 1 }
165 //-----------------------------------------------------------------------------
166 // PORT_Init
167 //-----------------------------------------------------------------------------
168 //
169 // Configure the Crossbar and GPIO ports
170 //
171 void PORT_Init (void)
172 {
173 1 XBR0 = 0x04; // Enable UART0
174 1 XBR1 = 0x00;
175 1 XBR2 = 0x40; // Enable crossbar and weak pull-up
176 1 P0MDOUT |= 0x01; // Set TX0 pin to push-pull
177 1 }
C51 COMPILER V7.05 DAC 08/28/2005 16:58:27 PAGE 4
178 //-----------------------------------------------------------------------------
179 // Timer4_Init
180 //-----------------------------------------------------------------------------
181 // This routine initializes Timer4 in auto-reload mode to generate interrupts
182 // at intervals specified in <counts>.
183 //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -