⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dk3200_1_demo.c

📁 DK3200开发板上的ADC开发出的AD和PWM应用程序
💻 C
字号:
/*------------------------------------------------------------------------------
DK3200_1_demo.c

Version:
September 13, 2004 Version 2.0 -
Initial release of a PWM-ADC demo that compiles and runs using the Raisonance
tool chain.
          
Description:
Simple Demo code for uPSD3200.
PWM channel PWM0 outputs pulse train that is integrated by RC circuit on DK3200 board
to produce a DC voltage which is read by ADC channel ADC0. The PW duty cycle varies to 
produce a slow DC voltage swing between 0 and 5VDC. The ADC conversion value is 
displayed in HEX format on the LCD, showing values between 0x00 and 0xFF as the voltage 
swings. Jumpers must be installed on DK3200 JP1 pins 23 to 24, and on pins 15 to 16, 
which wraps PWM0 output into ADC0 input.

This program also demonstrates using a 4-bit auto-reloading down-counter in the PLD 
of the uPSD. The 8032 can set the initial down-count value by writing to 4 macrocells. 
The down-counter is clocked by the 8032 ALE signal. When the count reaches zero terminal
count, uPSD pin PB4 is pulsed. The 8032 may change the initial counter load value at any 
time, which chages the divisor of ALE signal as it appears on pin PB4.

Compiler:
Raisonance

Copyright (c) 2004 STMicroelectronics
This example demo code is provided as is and has no warranty,
implied or otherwise.  You are free to use/modify any of the provided
code at your own risk in your applications with the expressed limitation
of liability (see below) so long as your product using the code contains
at least one uPSD products (device).

LIMITATION OF LIABILITY:   NEITHER STMicroelectronics NOR ITS VENDORS OR 
AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
------------------------------------------------------------------------------*/

#include "upsd3200_hardware.h"		// environment hardware specific defines
#include "upsd3200.h"			      // special function register declarations for UPSD
#include "upsd3200_lcd.h"				// prototype declarations and defines for uPSD IP drivers
#include "upsd3200_timer.h"
#include "upsd_pwm.h"
#include "upsd_adc.h"


xdata volatile PSD_REGS PSD_reg _at_ PSD_REG_ADDR;      // Establish the CSIOP register

unsigned char idata  msg_buff[20];

// Routine to copy string in Code space to idata space
void init_msgbuff(unsigned char *dataptr, unsigned char *buffptr)
{
	unsigned char i;
	unsigned char code * temp_add;
	unsigned char src_code;
	unsigned char * dest_add;
	
	for (i=0; i<20; i++)
		{
		temp_add =  (unsigned char code *) (dataptr + i);     // get message byte
		src_code =  *  temp_add;
		dest_add = (unsigned char *) (buffptr + i);   // put message byte
		* dest_add = src_code;
		}	
}


main()
{	
	unsigned char k, ADC_channel;
	unsigned char ADC_result;

	//-----Enable peripheral I/O function-------------
	PSD_reg.VM |= 0x80;           //Enable peripheral I/O for DK3300 board

	//-----Initialize Timer 0-------------
	timer0_init(); 

	//-----Show demo information on LCD-------------
	lcd_init();					

	PSD_reg.OMCMASK_AB = 0xF0;    // Mask off upper nibble of Output MacroCell register.
                                 // This allows writing a byte to OMC register to load 
                                 // 4-bit initial count to down-counter in PLD without
                                 // disturbing the upper 4-bits of OMC register

	PSD_reg.OMC_AB = 0x08;        // Load initial count of eight into down-counter in PLD.
                                 // This 4-bit counter will pulse pin PB4 each time 8 counts of
                                 // 8032 ALE pulses occur per logic equations. 

	printfLCD("PWM to ADC DEMO");
	delay_1sec();
	init_msgbuff("\nPWM=XX ADC=XX\n", &msg_buff); 	// Load msg_buff with text message

   uPSD_PWM_Init_8bit(0, 6000, 0x8f);	// init PWM - Channel 0 on, Freq 6 MHz into PWM 

	ADC_channel=0;                // Select ADC channel 0
   uPSD_ADC_Init(ADC_channel);   // Init ADC channel	

	k=0xf;                        // Init k to initial value

// Main loop to output PWM value and read/display ADC value

	while(1)                 
   {
         if (k == 0) k = 0xff;   // Fix overflow to 0 -> 0xFF
         if (k == 0xf) k = 0;    // Fix overflow to 0xF -> 0

         uPSD_PWM_Channel_8bit(0,k);	   // PWMCON = 0x8F, PWM0, and duty varies  
         delay_1sec();                    // wait for voltage to settle and user to read display

         ADC_result = uPSD_ADC_Read(ADC_channel);	// Read ADC Value

         msg_buff[5] = htoa_hi(k);                 // Display PWM pulse width value
         msg_buff[6] = htoa_lo(k);

         msg_buff[12] = htoa_hi(ADC_result);       // Convert to ASCII hex to display
		   msg_buff[13] = htoa_lo(ADC_result);

         printfLCD(msg_buff);                      //Display ADC channel and value on LCD
         k = k + 0x10;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -