Professional Documents
Culture Documents
Author
: ADI - Apps
www.analog.com/MicroConverter
Date
File
Hardware
: Sept. 2005
: 3PWM.c
: Applicable to ADuC702x rev H or I silicon Currently targetting ADuC7026.
Description : 3-phase PWM with dead time PWMTRIP (P3.6) low stops the PWMs
*********************************************************************/
#include<aduc7026.h>
int main(void) {
GP4DAT = 0x04000000;
GP3CON = 0x11111111;
// Setup the PWM
PWMCON = 0x0001;
PWMDAT0 = 0x00A0;
PWMDAT1 = 0x00;
PWMCFG = 0x00;
PWMCH0 = 0x00FFE0;
PWMCH1 = 0x0020;
PWMCH2= 0x0030;
PWMEN = 0x00;
GP4DAT ^= 0x00040000;
// 0x01 is enabled
// Period register
// Dead time
//
// duty cycle channel 0
// duty cycle channel 1
// duty cycle channel 2
// Enable (0=enabled)
// Complement P4.2
while (1)
{
}
}
/*********************************************************************
Author
: ADI - Apps
Date
: Feb. 2004
File
Hardware
www.analog.com/MicroConverter
: UART1.c
: ADuC7024
HCLK
_______________
Baudrate * 2 *16
***********************************************************************/
#include <ADuC7024.h>
extern int write (int file, char * ptr, int len); // Functions used to
extern int getchar (void);
// to output data
extern int putchar(int);
// Write character to Serial Port
while(1)
{
GP4DAT ^= 0x00040000;
// Complement P4.2
write(0,output1,13);
// Output Data
jchar = getchar();
// RX Data, Single Byte
write(0,&jchar,1);
// Output Rxed Data
}
}
/*********************************************************************
Author
: ADI - Apps
Date
: Sept. 2005
www.analog.com/MicroConverter
File
: ADCcont.c
Hardware
// power on ADC
// select ADC channel 0
// internal 2.5V reference. 2.5V on Vref pin
// Enable ADCbusy on P0.5
// P4.2 configured as an output. LED is turned on
// Setup tx & rx pins on P1.0 and P1.1
/*********************************************************************
Author
: ADI - Apps
Date
: Sept. 2005
File
: ADCtimer.c
Hardware
www.analog.com/MicroConverter
/********************************************************************/
/*
Interrupt Service Rountine
*/
/*
*/
/********************************************************************/
void IRQ_Handler() __irq
{
GP4DAT ^= 0x00040000;
// Complement P4.2
ADCCP ^= 1;
// change channel
senddata (ADCDAT >> 16);
return ;
}
void senddata(short to_send)
{
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = 0x0A;
// output LF
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = 0x0D;
// output CR
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii ((to_send >> 8) & 0x0F);
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii ((to_send >> 4) & 0x0F);
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii (to_send & 0x0F);
}
char hex2ascii(char toconv)
{
if (toconv<0x0A) toconv += 0x30;
else toconv += 0x37;
return (toconv);
}
void delay (int length)
{
while (length >=0)
length--;
}
void ADCpoweron(int time)
{
ADCCON = 0x20;
// power-on the ADC
while (time >=0)
// wait for ADC to be fully powered on
time--;
}
/*********************************************************************
Author
: ADI - Apps
Date
: Feb. 2004
File
Hardware
www.analog.com/MicroConverter
: ADCcont.c
: ADuC7024
// power on ADC
while (!ADCSTA){}
// wait for end of conversion
ADCDATA[i] = (ADCDAT >> 16);
}
ADCCON = 0x64;
// stops continuous conversion
GP4DAT ^= 0x00040000;
// Complement P4.2
for (i=0; i <1024; i++)
{
senddata (ADCDATA[i]);
}
GP4DAT ^= 0x00040000;
// Complement P4.2
}
}
void senddata(short to_send)
{
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = 0x0A;
// output LF
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = 0x0D;
// output CR
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii ((to_send >> 8) & 0x0F);
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii ((to_send >> 4) & 0x0F);
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii (to_send & 0x0F);
}
char hex2ascii(char toconv)
{
if (toconv<0x0A)
{
toconv += 0x30;
}
else
{
toconv += 0x37;
}
return (toconv);
}
void ADCpoweron(int time)
{
ADCCON = 0x20;
// power-on the ADC
while (time >=0)
// wait for ADC to be fully powered on
time--;
}
/*********************************************************************
Author
: ADI - Apps
Date
File
www.analog.com/MicroConverter
: Feb. 2004
: UART1.c
Hardware
: ADuC7024
while(1)
{
GP4DAT ^= 0x00040000;
// Complement P4.2
write(0,output1,13);
// Output Data
jchar = getchar();
write(0,&jchar,1);
}
}
/***********************************************************************/
/*
*/
/* SERIAL.C: Low Level Serial Routines
*/
/*
*/
/***********************************************************************/
#include <aduc7024.H>
#define CR
/* ADuC7024 definitions
*/
0x0D
if (ch == '\n') {
while(!(0x020==(COMSTA0 & 0x020)))
{}
COMTX = CR;
/* output CR */
}
while(!(0x020==(COMSTA0 & 0x020)))
{}
return (COMTX = ch);
}
/**********************************************************************************************
3510LCD.c file
http://computer00.21ic.org
Copyright(C) Computer-lov 2006-2016
All rights reserved
**********************************************************************************************/
#include <ADuC7027.H>
#include "My_type.h"
#include "3510LCD.h"
/*********************************************************************************************/
void LcdPortInit(void)
{
GP2CON &=~(uint32)(0x0F<<(LCD_RST*4));
GP2DAT |=1<<(LCD_RST+24);
GP2CON &=~(uint32)(0x0F<<(LCD_CS*4));
GP2DAT |=1<<(LCD_CS+24);
GP1CON &=~(uint32)(0x0F<<(LCD_SDATA*4));
GP1DAT &=~(uint32)(1<<(LCD_SDATA+24));
GP1CON &=~(uint32)(0x0F<<(LCD_SCLK*4));
GP1DAT |=1<<(LCD_SCLK+24);
SetLcdRst();
SetLcdCs();
SetLcdSclk();
}
///////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************************************/
void LcdReset(void)
{
ClrLcdRst();
DelayXms(5);
SetLcdRst();
DelayXms(5);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************************************/
void LcdSendCommand(uint8 cmd)
{
uint8 i;
SetSdataOut();
ClrLcdCs();
ClrLcdSclk();
ClrLcdSdata();
SetLcdSclk();
for(i=0;i<8;i++)
{
ClrLcdSclk();
if(cmd & 0x80)
{
SetLcdSdata();
}
else
{
ClrLcdSdata();
}
SetLcdSclk();
cmd<=1;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************************************/
void LcdSendData(uint32 Data)
{
uint32 i;
SetSdataOut();
ClrLcdCs();
ClrLcdSclk();
SetLcdSdata();
SetLcdSclk();
for(i=0;i<8;i++)
{
ClrLcdSclk();
if(Data & 0x80)
{
SetLcdSdata();
}
else
{
ClrLcdSdata();
}
SetLcdSclk();
Data<=1;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************************************/
void LcdReadDummy(void)
{
SetSdataIn();
ClrLcdCs();
ClrLcdSclk();
SetLcdSclk();
}
///////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************************************/
uint16 LcdReadData(void)
{
uint16 r = 0;
uint8 i;
SetSdataIn();
ClrLcdCs();
for(i=0;i<12;i++)
{
ClrLcdSclk();
SetLcdSclk();
r<=1;
if(LCD_SDATA_IN)
{
r++;
}
}
return r;
}
///////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************************************/
void LcdInit(void)
{
uint8 i;
LcdPortInit();
LcdReset();
LcdSendCommand(0x01);
SetLcdCs();
DelayXms(5);
LcdSendCommand(0xc6);
SetLcdCs();
//soft reset
//initial escape
LcdSendCommand(0xb9);
LcdSendData(0x00);
SetLcdCs();
//refresh set
LcdSendCommand(0xb6);
LcdSendData(0x80);
LcdSendData(0x80);
LcdSendData(0x81);
LcdSendData(84);
LcdSendData(69);
LcdSendData(82);
LcdSendData(67);
SetLcdCs();
//display control
LcdSendCommand(0xbd);
LcdSendData(0x00);
SetLcdCs();
LcdSendCommand(0xbe);
LcdSendData(0x04);
SetLcdCs();
//power control
LcdSendCommand(0x11);
SetLcdCs();
//sleep out
LcdSendCommand(0xba);
LcdSendData(127);
LcdSendData(3);
SetLcdCs();
//voltage control
LcdSendCommand(0xb7);
for(i=0; i<14; i++)
{
LcdSendData(0x00);
}
SetLcdCs();
LcdSendCommand(0x29);
SetLcdCs();
//display ON
LcdSendCommand(0x03);
SetLcdCs();
DelayXms(5);
//booster voltage ON
LcdSendCommand(0x20);
SetLcdCs();
LcdSendCommand(0x25);
LcdSendData(62);
SetLcdCs();
}
//write contrast
void LcdClr(void)
{
uint8 x, y;
LcdSendCommand(0x2a);
LcdSendData(0);
LcdSendData(97);
SetLcdCs();
LcdSendCommand(0x2b);
LcdSendData(0);
LcdSendData(66);
SetLcdCs();
LcdSendCommand(0x2c);
//memory write
for(y=0;y<67;y++)
{
for(x=0;x<98;x+=2)
{
LcdSendData(0);
LcdSendData(0);
LcdSendData(0);
}
}
SetLcdCs();
}
///////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************************************/
void LcdBlockWrite(uint8 x1, uint8 y1, uint8 x2, uint8 y2, uint8 *b)
{
uint32 x, y;
LcdSendCommand(0x2a);
//column address set
LcdSendData(x1);
LcdSendData(x2);
SetLcdCs();
LcdSendCommand(0x2b);
LcdSendData(y1);
LcdSendData(y2);
SetLcdCs();
LcdSendCommand(0x2c);
for(y=y1;y=y2;y++)
{
for(x=x1;x=x2;x+=2)
{
LcdSendData(*(b++));
LcdSendData(*(b++));
LcdSendData(*(b++));
}
}
SetLcdCs();
}
//memory write
*********************************************************************
Author
: ADI - Apps
Date
: Sept. 2005
www.analog.com/MicroConverter
File
: Temperature.c
Hardware
GP0CON = 0x010100000;
GP4DAT = 0x04000000;
GP1CON = 0x011;
// power on ADC
// Select Temperature Sensor as an input to the ADC
// connect internal 2.5V reference to Vref pin
ADCCON = 0xE4;
// continuous conversion
while(1)
{
GP4DAT ^= 0x00040000;
// Complement P4.2
while (!ADCSTA){};
// wait for end of conversion
b = (ADCDAT >> 16);
// To calculate temperature in C, use the formula:
a = 0x525 - b;
// ((Temperature = 0x525 - Sensor Voltage) / 1.3)
a /= 1.3;
b = floor(a);
printf("Temperature: %d oC\n",b);
}
return 0;
}
***********************************************************************/
/* This file is part of the uVision/ARM development tools
*/
/* Copyright KEIL ELEKTRONIK GmbH 2002-2004
/***********************************************************************/
*/
/*
*/
/* SYSCALLS.C: System Calls Remapping
*/
/*
*/
/***********************************************************************/
#include <stdlib.h>
extern int putchar (int ch);
extern int getchar (void);
int read (int file, char * ptr, int len) {
char c;
int i;
for (i = 0; i len; i++) {
c = getchar();
if (c == 0x0D) break;
*ptr++ = c;
putchar(c);
}
return len - i;
}
int write (int file, char * ptr, int len) {
int i;
for (i = 0; i len; i++) putchar (*ptr++);
return len;
}
int isatty (int fd) {
return 1;
}
#ifdef ADUC7020
#include <ADUC7020.H>
#endif
#ifdef ADUC7021
#include <ADUC7021.H>
#endif
#ifdef ADUC7024
#include <ADUC7024.H>
#endif
#ifdef ADUC7026
#include <ADUC7026.H>
#endif
#define CLOCK 22544384 // CPU configured for 22.544384 MHz clock
#define T0_Freq 200
// Timer 0 Reload Frequency
#define T0_LD ((unsigned short )(CLOCK / 16 / T0_Freq))
/*----------------------------------------------Sine Wave Table
-----------------------------------------------*/
unsigned char sintab [] = {
0x00, 0x01, 0x03, 0x04, 0x06, 0x07, 0x09, 0x0A,
0x0C, 0x0E, 0x0F, 0x11, 0x12, 0x14, 0x15, 0x17,
0x18, 0x1A, 0x1C, 0x1D, 0x1F, 0x20, 0x22, 0x23,
0x25, 0x26, 0x28, 0x29, 0x2B, 0x2C, 0x2E, 0x2F,
0x30, 0x32, 0x33, 0x35, 0x36, 0x38, 0x39, 0x3A,
0x3C, 0x3D, 0x3F, 0x40, 0x41, 0x43, 0x44, 0x45,
0x47, 0x48, 0x49, 0x4A, 0x4C, 0x4D, 0x4E, 0x4F,
0x51, 0x52, 0x53, 0x54, 0x55, 0x57, 0x58, 0x59,
0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61,
0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
0x6A, 0x6B, 0x6C, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
0x70, 0x71, 0x72, 0x73, 0x73, 0x74, 0x75, 0x75,
0x76, 0x76, 0x77, 0x77, 0x78, 0x79, 0x79, 0x7A,
0x7A, 0x7A, 0x7B, 0x7B, 0x7C, 0x7C, 0x7C, 0x7D,
0x7D, 0x7D, 0x7E, 0x7E, 0x7E, 0x7E, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F };
/* Timer0 Interrupt
*/
*/
*/
-------------------------------------*/
IRQEN = 0x00000004;
/* Configure Timer 0
*/
T0LD = T0_LD;
/* Timer reload value
*/
T0CON = 0xC0;
/* Enable Timer 0, Mode: periodic, prescaler = 1 */
while (1){
}
}
/*
*
* Signal.C: Demonstrates Signal Processing
*
with ARM-powered ADuC7024
* Copyright KEIL ELEKTRONIK GmbH and KEIL SOFTWARE, Inc. 2003 - 2004
*
* This file may be compiled in ARM or Thumb Mode
*/
#include <aduc7024.h>
#include <math.h>
// CPU Clock
#define CLOCK 22544384 // CPU configured for 22.544384 MHz clock
#define T0_CON 0xC0
// ----- Parameters and Variables for Sine Wave Generator ----#define OutFreq 400
// Output Frequency (Range 1Hz - 4000Hz)
short tval;
signed char cval;
struct tone Tone;
/*
* Generate Sine Wave Tone
*/
static void Generate_Sine (struct tone *t) {
int y;
y = (t->cos * (t->y1 >> 14)) - t->y2;
t->y2 = t->y1;
t->y1 = y;
tval = t->y1 >> 16;
cval = tval;
}
extern volatile int T0_ticks;
int T0_last;
/*
* Read Analog Input of Channel 'ch'
*/
unsigned long AdcRead (unsigned int ch) {
REFCON = 0x01;
// Power up internal reference
ADCCP = ch;
// Select Channel defined by ch
ADCCON = 0x0A3;
// Begin Single Conversion in Single Ended Mode
while (ADCSTA == 0x01); // wait for conversation ready
return ADCDAT >> 16; // Return ADC Data resident in bits 27-16
}
int iADCAverage0 = 0;
int main (void) {
int iADC0;
unsigned long analog;
DAC0CON = 0x13;
DAC1CON = 0x13;
// Configure PWM
#define PWM_DEAD
GP3CON = 0x11;
// output PWM on P3.0 & P3.1
PWMDAT0 = CLOCK / (2 * 8000); // 8 KHz PWM Switching Frequency
PWMDAT1 = PWM_DEAD;
// Switching Dead Time
PWM0 = 0;
PWM1 = 0;
PWM2 = 0;
PWMEN = 0x100;
// enable 0L/0H output + crossover
PWMSTA0 = 0x200;
PWMCON = 3;
// enable PWM
IRQEN = 0x00000004;
T0LD = T0_LD;
T0CON = T0_CON;
// Configure Timer 0