📄 pwm_adc.lst
字号:
C51 COMPILER V7.50 PWM_ADC 07/11/2005 15:30:31 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE PWM_ADC
OBJECT MODULE PLACED IN pwm_adc.OBJ
COMPILER INVOKED BY: C:\keil\C51\BIN\C51.EXE pwm_adc.c OPTIMIZE(9,SIZE) BROWSE DEBUG OBJECTEXTEND
line level source
1 /*------------------------------------------------------------------------------
2 pwm_adc.c
3
4 Version:
5 August 2004 Version 2.0 - Updated include file names, modified comments.
6
7 Description:
8 This code demonstrates use of the PWM and ADC function blocks within the
9 uPSD3300 device. A pulse width modulated signal output from the PWM circuit is
10 tied to an RC circuit resulting in a DC voltage that is proportional to the
11 pulse width. This DC voltage is input to an ADC channel and is read after each
12 time the pulse width out of the PWM is changed. The PWM setting and the ADC
13 value read is displayed on the LCD.
14
15
16 Copyright (c) 2004 STMicroelectronics Inc.
17
18 This example demo code is provided as is and has no warranty,
19 implied or otherwise. You are free to use/modify any of the provided
20 code at your own risk in your applications with the expressed limitation
21 of liability (see below) so long as your product using the code contains
22 at least one uPSD product (device).
23
24 LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
25 AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
26 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
27 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
28 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
29 ------------------------------------------------------------------------------*/
30
31 #include "upsd3300.h"
32 #include "upsd3300_hardware.h"
33 #include "upsd3300_adc.h"
34 #include "upsd3300_timer.h"
35 #include "upsd3300_lcd.h"
36 #include "upsd3300_pca-pwm.h"
37
38
39 unsigned char idata msg_buff[20]; // Buffer for LCD message
40 xdata PSD_REGS PSD_reg _at_ PSD_REG_ADDR; // Access PSD regs at CSIOP addr
41
42 // Copy character string in code space to data space
43 void init_msgbuff(unsigned char *dataptr, unsigned char *buffptr)
44 {
45 1 unsigned char i;
46 1 unsigned char code * temp_addr;
47 1 unsigned char * dest_addr;
48 1
49 1 temp_addr = (unsigned char code *) (dataptr); // get text message addr from code space
50 1 dest_addr = (unsigned char *) (buffptr); // get data space buffer address
51 1
52 1 for (i=0; i<20; i++)
53 1 {
54 2 * dest_addr++ = * temp_addr++; // copy the byte from code space to data space
55 2 }
C51 COMPILER V7.50 PWM_ADC 07/11/2005 15:30:31 PAGE 2
56 1 }
57
58
59
60 main()
61 {
62 1 unsigned char k, ADC_channel;
63 1 unsigned int ADC_result;
64 1
65 1 //-----Enable peripheral I/O function-------------
66 1 PSD_reg.VM |= 0x80; //Enable peripheral I/O for DK3300 board
67 1
68 1 //-----Initialize Timer 0-------------
69 1 timer0_init();
70 1
71 1 //-----Show demo information on LCD-------------
72 1 lcd_init();
73 1
74 1 PSD_reg.OMCMASK_AB = 0xF0; // Mask off upper nibble of Output MacroCell register.
75 1 // This allows writing a byte to OMC register to load
76 1 // 4-bit initial count to down-counter in PLD without
77 1 // disturbing the upper 4-bits of OMC register
78 1
79 1 PSD_reg.OMC_AB = 0x08; // Load initial count of eight into down-counter in PLD.
80 1 // This 4-bit counter will pulse pin PB4 each time 8 counts of
81 1 // 8032 ALE pulses occur per logic equations.
82 1 printfLCD("PWM to ADC DEMO");//PWM to ADC DEMO
83 1 delay_1sec();
84 1 init_msgbuff("\nPWM=XX ADC=XXX\n", &msg_buff); // Load msg_buff with text message
85 1
86 1 k=0xf; // Init k to initial value
87 1 ADC_channel=7; // Select ADC channel 7
88 1
89 1
90 1 ADC_Init(ADC_channel); // Init ADC channel
91 1
92 1 delay_10ms(); // Wait for ADC Auto Calibration
93 1 delay_10ms();
94 1
95 1
96 1 // Main loop to output PWM value and read/display ADC value
97 1
98 1 while(1)
99 1 {
100 2 if (k == 0) k = 0xff; // Fix overflow to 0 -> 0xFF
101 2 if (k == 0xf) k = 0; // Fix overflow to 0xF -> 0
102 2
103 2 PWM_Mode1_Init(0, k); //Set to PWM channel 0 output with k pulse width
104 2
105 2 delay_1sec(); // wait for voltage to settle and user to read display
106 2
107 2 ADC_result = ADC_Read(ADC_channel);
108 2
109 2 msg_buff[5] = htoa_hi(k); // Display PWM pulse width value
110 2 msg_buff[6] = htoa_lo(k);
111 2
112 2 msg_buff[12] = htoa_lo(ADC_result>>8); // Convert to ASCII hex to display
113 2 msg_buff[13] = htoa_hi(ADC_result);
114 2 msg_buff[14] = htoa_lo(ADC_result);
115 2
116 2 printfLCD(msg_buff); //Display ADC channel and value on LCD
117 2 k = k + 0x10;
C51 COMPILER V7.50 PWM_ADC 07/11/2005 15:30:31 PAGE 3
118 2 }
119 1 }
120
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 224 ----
CONSTANT SIZE = 33 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 15
IDATA SIZE = 20 ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -