24
 /***************************************************** ********* ******* Author : ADI - Apps www.analog.co m/MicroConver ter Date : Sept. 2005 File : 3PWM.c Hardware : Applicable to ADuC702x rev H or I silicon Currently targettin g ADuC7026. Description : 3-phase PWM with dead time PWMTR IP (P3.6) low s tops the P WMs *********************************************************************/  #include<aduc7026.h> int main(void) { GP4DAT = 0x04000000;  // P4.2 configure d as an output. LED is turned on GP3CON = 0x11111111;  // Enable the PWM ou tputs to the GPIO  // Setup the P WM PWMCON = 0x0001;  // 0x01 is enabled PWMDAT0 = 0x00A0;  // Period register PWMDAT1 = 0x00;  // Dead time PWMCFG = 0x00;  // PWMCH0 = 0x00FFE0;  // duty cycle chann el 0 PWMCH1 = 0x0020;  // duty cycle chan nel 1 PWMCH2= 0x0030;  // duty cycle chan nel 2 PWMEN = 0x00;  // Enable (0=ena bled) GP4DAT ^= 0x00040000;  // Complement P4.2 while (1) { } }  /***************************************************** ********* ******* Author : ADI - Apps www.ana log.com/MicroC onverter Date : Feb. 2004 File : UART1.c Hardware : ADuC7024 Description : This code demonstrates basic UART functionality.

702x Example

Embed Size (px)

Citation preview

Page 1: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 1/24

 /*********************************************************************

Author : ADI - Apps www.analog.com/MicroConverter

Date : Sept. 2005

File : 3PWM.c

Hardware : 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;  // P4.2 configured as an output. LED is turned on

GP3CON = 0x11111111;  // Enable the PWM outputs to the GPIO

 // Setup the PWM

PWMCON = 0x0001;  // 0x01 is enabled

PWMDAT0 = 0x00A0;  // Period register

PWMDAT1 = 0x00;  // Dead time

PWMCFG = 0x00;  // 

PWMCH0 = 0x00FFE0;  // duty cycle channel 0PWMCH1 = 0x0020;  // duty cycle channel 1

PWMCH2= 0x0030;  // duty cycle channel 2

PWMEN = 0x00;  // Enable (0=enabled)

GP4DAT ^= 0x00040000;  // Complement P4.2

while (1)

{

}

}

 /*********************************************************************

Author : ADI - Apps www.analog.com/MicroConverter

Date : Feb. 2004

File : UART1.c

Hardware : ADuC7024

Description : This code demonstrates basic UART functionality.

Page 2: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 2/24

  The baudrate is calculated with the following formula:

DL = 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

int main (void) {unsigned char jchar = 0x30;

char output1[13] = "Hello World\n";

 // Setup tx & rx pins on P1.0 and P1.1

GP1CON = 0x011;

 // Start setting up UART at 9600bps

COMCON0 = 0x080;  // Setting DLAB

COMDIV0 = 0x093;  // Setting DIV0 and DIV1 to DL calculatedCOMDIV1 = 0x000;

COMCON0 = 0x007;  // Clearing DLAB

GP4DAT = 0x04000000;  // P4.2 configured as an output. LED is turned on

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

}

}

Page 3: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 3/24

 

 /*********************************************************************

Author : ADI - Apps www.analog.com/MicroConverter

Date : Sept. 2005

File : ADCcont.c

Hardware : Applicable to ADuC702x rev H or I silicon

Currently targetting ADuC7026.

Description : Performs 1024 continuous ADC conversions on ADC0,

store the results in SRAM and send them through UART

at 9600bps when the 1024 conversions are done

*********************************************************************/   

#include <ADuC7026.h>

void senddata(short);

void ADCpoweron(int);

char hex2ascii(char);

int main (void)

{

unsigned short ADCDATA[32];int i;

ADCpoweron(20000);  // power on ADC

ADCCP = 0x00;  // select ADC channel 0

REFCON = 0x01;  // internal 2.5V reference. 2.5V on Vref pin

GP0CON = 0x100000;  // Enable ADCbusy on P0.5

GP4DAT = 0x04000000;  // P4.2 configured as an output. LED is turned on

GP1CON = 0x011;  // Setup tx & rx pins on P1.0 and P1.1

 // Setting up UART at 9600 (CD=0)

COMCON0 = 0x80;  // Setting DLAB

COMDIV0 = 0x88;

COMDIV1 = 0x00;

COMCON0 = 0x07;  // Clearing DLAB

ADCCON = 0x4E4;  // ADC Config: fADC/2, acq. time = 2 clocks => ADC Speed =

1MSPS

while(1)

{  // start continuous conversion

Page 4: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 4/24

  for (i=0; i <1024; i++) {

while (!ADCSTA){}  // wait for end of conversion

ADCDATA[i] = (ADCDAT >> 16);

if (ADCCP == 0) ADCCP = 1;  // change channel

else ADCCP = 0;

}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 LFwhile(!(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--;

}

Page 5: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 5/24

 /*********************************************************************

Author : ADI - Apps www.analog.com/MicroConverter

Date : Sept. 2005

File : ADCtimer.c

Hardware : Applicable to ADuC702x rev H or I silicon Currently targetting ADuC7026.

Description : Performs an ADC conversion every 91 us using timer0

overflow alternatively on Channel 0 and 1

sending the results through UART at 9600bps

*********************************************************************/   

#include <ADuC7026.h> // Include ADuC7026 Header File

void IRQ_Handler(void) __irq;  // IRQ Funtion Prototype

void senddata(short to_send);

void ADCpoweron(int);

char hex2ascii(char toconv);

void delay(int);

int main (void)

{

ADCpoweron(20000);  // power on ADC

ADCCP = 0x00;ADCCON = 0x6E2;  // start conversion on timer 0

REFCON = 0x01;  // connect internal 2.5V reference to VREF pin

GP1CON = 0x011;  // Setup tx & rx pins on P1.0 and P1.1

 // Setting up UART at 9600bps (CD=0)

COMCON0 = 0x80;  // Setting DLAB

COMDIV0 = 0x88;

COMDIV1 = 0x00;

COMCON0 = 0x07;  // Clearing DLAB

 // for test purposes only

GP0CON = 0x10100000;  // enable ECLK output on P0.7, and ADCbusy on P0.5

IRQEN = ADC_BIT;  // Enable ADC IRQ ( 0x80 )

 // timer0 configuration

T0LD = 1000;  // 23.4us

T0CON = 0xC0;  // count down // periodic mode 

GP4DAT = 0x04000000;  // Configure P4.2 as output

while(1)

{

}

return 0 ;

}

Page 6: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 6/24

 

 /********************************************************************/  

 /* 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--;

}

Page 7: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 7/24

 /*********************************************************************

Author : ADI - Apps www.analog.com/MicroConverter

Date : Feb. 2004

File : ADCcont.c

Hardware : ADuC7024

Description : Performs 1024 continuous ADC conversions on ADC0,

store the results in SRAM and send them through UART

at 9600bps when the 1024 conversions are done

*********************************************************************/   

#include <ADuC7024.h>

void senddata(short);

void ADCpoweron(int);

char hex2ascii(char);

int main (void) {

unsigned short ADCDATA[1024];

int i;

ADCpoweron(20000);  // power on ADC

ADCCP = 0x00;  // select ADC channel 0

REFCON = 0x01;  // internal 2.5V reference. 2.5V on Vref pin

GP0CON = 0x100000;  // Enable ADCbusy on P0.5

 // configures GPIO to flash LED P4.2

GP4DAT = 0x04000000;  // P4.2 configured as an output. LED is turned on

 // Setup tx & rx pins on P1.0 and P1.1

GP1CON = 0x011;

 // Start setting up UART at 9600bps

COMCON0 = 0x80;  // Setting DLAB

COMDIV0 = 0x93;

COMDIV1 = 0x00;

COMCON0 = 0x07;  // Clearing DLAB

while(1)

{

ADCCON = 0x0E4;  // start continuous conversion

for (i=0; i <1024; i++)

{

Page 8: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 8/24

  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--;

}

Page 9: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 9/24

 

 /*********************************************************************

Author : ADI - Apps www.analog.com/MicroConverter

Date : Feb. 2004

File : UART1.c

Hardware : ADuC7024

Description : This code demonstrates basic UART functionality.

The baudrate is calculated with the following formula:

DL = 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

int main (void) {

unsigned char jchar = 0x30;

char output1[13] = "Hello World\n";

 // Setup tx & rx pins on P1.0 and P1.1

GP1CON = 0x011;

 // Start setting up UART at 9600bps

COMCON0 = 0x080;  // Setting DLABCOMDIV0 = 0x093;  // Setting DIV0 and DIV1 to DL calculated

COMDIV1 = 0x000;

COMCON0 = 0x007;  // Clearing DLAB

GP4DAT = 0x04000000;  // P4.2 configured as an output. LED is turned on

while(1)

{

GP4DAT ̂ = 0x00040000;  // Complement P4.2write(0,output1,13);  // Output Data

Page 10: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 10/24

   jchar = getchar();  // RX Data, Single Byte

write(0,&jchar,1);  // Output Rxed Data

}

}

 /***********************************************************************/  

 /* */  

 /* SERIAL.C: Low Level Serial Routines */  

 /* */  

 /***********************************************************************/  

#include <aduc7024.H> /* ADuC7024 definitions */ 

#define CR 0x0D

int putchar(int ch) {  /* Write character to Serial Port */  

if (ch == '\n') {

while(!(0x020==(COMSTA0 & 0x020)))

{}

COMTX = CR;  /* output CR */  

}

while(!(0x020==(COMSTA0 & 0x020)))

{}

return (COMTX = ch);

}

int getchar (void) {  /* Read character from Serial Port */  

while(!(0x01==(COMSTA0 & 0x01)))

{}

return (COMRX);

}

 /**********************************************************************************************

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"

Page 11: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 11/24

 

 /*********************************************************************************************/  

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 

{

Page 12: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 12/24

  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)

{

Page 13: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 13/24

  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);  //soft reset

SetLcdCs();

DelayXms(5);

LcdSendCommand(0xc6);  //initial escape

SetLcdCs();

LcdSendCommand(0xb9);  //refresh set

LcdSendData(0x00);

SetLcdCs();

LcdSendCommand(0xb6);  //display control

LcdSendData(0x80);

LcdSendData(0x80);

LcdSendData(0x81);

LcdSendData(84);

LcdSendData(69);

LcdSendData(82);

LcdSendData(67);

SetLcdCs();

Page 14: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 14/24

 

LcdSendCommand(0xb3);  //gray scale position set

LcdSendData(1);

LcdSendData(2);

LcdSendData(4);

LcdSendData(8);LcdSendData(16);

LcdSendData(30);

LcdSendData(40);

LcdSendData(50);

LcdSendData(60);

LcdSendData(70);

LcdSendData(80);

LcdSendData(90);

LcdSendData(100);

LcdSendData(110);LcdSendData(127);

SetLcdCs();

LcdSendCommand(0xb5);  //gamma curve set

LcdSendData(0x01);

SetLcdCs();

LcdSendCommand(0xbd);  //common driver output select

LcdSendData(0x00);

SetLcdCs();

LcdSendCommand(0xbe);  //power control

LcdSendData(0x04);

SetLcdCs();

LcdSendCommand(0x11);  //sleep out

SetLcdCs();

LcdSendCommand(0xba);  //voltage control

LcdSendData(127);

LcdSendData(3);

SetLcdCs();

LcdSendCommand(0xb7);  //temperature gradient set

for(i=0; i<14; i++)

{

LcdSendData(0x00);

}

SetLcdCs();

LcdSendCommand(0x29);  //display ON

SetLcdCs();

Page 15: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 15/24

 

LcdSendCommand(0x03);  //booster voltage ON

SetLcdCs();

DelayXms(5);

LcdSendCommand(0x20);  //display inversion OFFSetLcdCs();

LcdSendCommand(0x25);  //write contrast

LcdSendData(62);

SetLcdCs();

}

void LcdClr(void)

{

uint8 x, y;LcdSendCommand(0x2a);  //column address set

LcdSendData(0);

LcdSendData(97);

SetLcdCs();

LcdSendCommand(0x2b);  //page address set

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);

Page 16: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 16/24

  SetLcdCs();

LcdSendCommand(0x2b);  //page address set

LcdSendData(y1);

LcdSendData(y2);

SetLcdCs();

LcdSendCommand(0x2c);  //memory write

for(y=y1;y=y2;y++)

{

for(x=x1;x=x2;x+=2)

{

LcdSendData(*(b++));

LcdSendData(*(b++));

LcdSendData(*(b++));

}}

SetLcdCs();

}

*********************************************************************

Author : ADI - Apps www.analog.com/MicroConverter

Date : Sept. 2005

File : Temperature.c

Hardware : Applicable to ADuC702x rev H or I silicon

Currently targetting ADuC7026.

Description : Measures and outputs internal temperature via UART at

9600bps.

*********************************************************************/   

#include <ADuC7026.h>

#include <stdio.h>

#include <math.h>

void ADCpoweron(int);

int main(void)

{

float a = 0;

short b;

Page 17: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 17/24

  GP0CON = 0x010100000;  // enable ECLK output on P0.7, and ADCbusy on P0.5

GP4DAT = 0x04000000;  // P4.2 configured as an output. LED is turned on

GP1CON = 0x011;  // Setup tx & rx pins on P1.0 and P1.1

 // Setting up UART at 9600 bps for CD = 0

COMCON0 = 0x80;  // Setting DLAB

COMDIV0 = 0x88;  // 

COMDIV1 = 0x00;

COMCON0 = 0x07;  // Clearing DLAB

ADCpoweron(2000);  // power on ADC

ADCCP = 0x10;  // Select Temperature Sensor as an input to the ADC

REFCON = 0x01;  // 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;

}

void ADCpoweron(int time)

{

ADCCON = 0x20;  // power-on the ADC

while (time >=0)  // wait for ADC to be fully powered on

time--;

}

***********************************************************************/   

 /* This file is part of the uVision/ARM development tools */  

 /* Copyright KEIL ELEKTRONIK GmbH 2002-2004 */   /***********************************************************************/  

Page 18: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 18/24

  /* */  

 /* 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;

}

void _exit (int n) {

label: goto label; /* endless loop */  

}

#ifdef ADUC7020

#include <ADUC7020.H>

#endif

#ifdef ADUC7021

#include <ADUC7021.H>

#endif

#ifdef ADUC7024#include <ADUC7024.H>

Page 19: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 19/24

#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 };

static unsigned char DAC0_next_out;

static unsigned char DAC1_next_out;

static unsigned char DAC2_next_out;

static unsigned char DAC3_next_out;

static unsigned int i = 0x00;

void IRQ_Handler (void) __irq {

if (IRQSIG & 0x00000004) {  /* Timer0 Interrupt */  

 /*-----------------------------------------------

Output D/A Value

-----------------------------------------------*/  

DAC0DAT = DAC0_next_out < 20;  /* Convert last D/A value */  

DAC1DAT = DAC1_next_out < 20;

DAC2DAT = DAC2_next_out < 20;

DAC3DAT = DAC3_next_out < 20;

 /*-----------------------------------------------

Page 20: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 20/24

  Calculate next D/A Value

-----------------------------------------------*/  

if (i++ >= 511) i = 0;

if (i >= 384){

DAC0_next_out = 127 - sintab[127 - (i % 128)];  /* 180 - 270 quadrant */  

DAC1_next_out = 1023 - 2*i;

DAC2_next_out = 0;

DAC3_next_out = i - 255;

}

else if (i >= 256){

DAC0_next_out = 127 - sintab[i % 128];  /* 90 - 180 quadrant */  

DAC1_next_out = (i - 256) * 2;

DAC2_next_out = 255;DAC3_next_out = i - 255;

}

else if (i >= 128) {

DAC0_next_out = 128 + sintab[127 - (i % 128)];  /* 0 - 90 quadrant */  

DAC1_next_out = 511 - i * 2;

DAC2_next_out = 255;

DAC3_next_out = i;

}

else{

DAC0_next_out = 128 + sintab[i];  /* 270 - 0 quadrant */  DAC1_next_out = i * 2;

DAC2_next_out = 0;

DAC3_next_out = i;

}

T0CLRI = 1;  /* Clear Timer 0 interrupt */  

}

}

void main (void)

{

 /*-------------------------------------

Configure the D/A converter:

normal mode, 0-VDD range,

-------------------------------------*/  

DAC0CON = 0x13;

DAC1CON = 0x13;

DAC2CON = 0x13;

DAC3CON = 0x13;

 /*-------------------------------------

Initialize Timer 0 Interrupt

Page 21: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 21/24

  -------------------------------------*/  

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 // Enable Timer 0, Mode: periodic

 // <o> Reload Frequency (Hz) for Mode periodic <1-1000000>

#define T0_RlFreq 8000 // Timer 0 Reload Frequency

#if ((T0_CON & 3) == 0)

#define T0_Pres 1

#elif ((T0_CON & 3) == 1)

#define T0_Pres 16#elif ((T0_CON & 3) == 2)

#define T0_Pres 256

#else

#error "Illegal Prescale Value for Timer 0"

#endif

#define T0_LD ((unsigned int )(CLOCK / (T0_Pres*T0_RlFreq)))

 // ----- Parameters and Variables for Sine Wave Generator -----#define OutFreq 400 // Output Frequency (Range 1Hz - 4000Hz)

Page 22: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 22/24

  #define OutAmpl 200 // Output Amplitute (Range 0 - 0.99)

#define PI 3.1415926

struct tone {  // struct for Sine Wave Generator Signal

int cos;  // cosine factor

long y1;  // y[-1] valueint y2;  // y[-2] value

};

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;

Page 23: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 23/24

  DAC0CON = 0x13;  // Configure DACs Range as AVdd

DAC1CON = 0x13;

 // Configure PWM

#define PWM_DEAD (0.000005 * (CLOCK/2)) // PWM Dead Time: 5 uSec

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;  // Configure Timer 0

T0LD = T0_LD;

T0CON = T0_CON;

 // Initialize Sine Generator

Tone.cos = (cos (2*PI*((float)OutFreq/T0_RlFreq))) * 32768;

Tone.y1 = 0;

Tone.y2 = (sin (2*PI*((float)OutFreq/T0_RlFreq)) * OutAmpl) * 32768;

while (1) {

while (T0_ticks == T0_last);  // Synchronize to Timer Interrupt

T0_last = T0_ticks;

Generate_Sine (&Tone);  // Generate Sine Wave Output

 // Output PWM Signal

PWM0 = ((Tone.y1 >> 8) & 0xFF) + PWM_DEAD;

analog = ((unsigned long) ((Tone.y1 < 7) + 0x80000000)) >> 4;

DAC0DAT = analog & 0x0FFF0000;  // Output Sine Wave Output

iADC0 = AdcRead(0);  // Read ADC0 Value

 // Average is the current average, minus 10th of the current average

 // plus 10th of the new ADC value

iADCAverage0 = iADCAverage0 - iADCAverage0 / 10 + iADC0 / 10;

DAC1DAT = (iADCAverage0 < 16) & 0x0FFF0000;

}

}

Page 24: 702x Example

8/3/2019 702x Example

http://slidepdf.com/reader/full/702x-example 24/24

ADuC702x temperature sensor

The ADuC702x has an on-chip temperature sensor. This sensor can be used to indicate the

die temperature of the part. Its accuracy is typically +/-3 degree C. its reading at 25degree C

is 780mV typical with a temperature coefficient of -1.3mV/degree C.

Therefore temperature can be calculated using the formula:

Temperature = (812.5-ADC reading in mV)/1.3 

The LSB weight of the ADC is 2.5V/2^12 or 610uV. 780mV at 25deg C correspond to

812.5mV at 0deg C.

V = -1.3 x Temp /1000 + 812.5 mV

812.5mV is 0x533 hex

An equivalent formula is:

Temperature = 0x533  – Sensor Voltage / 1.3