📄 wakeuptimer.c
字号:
/*********************************************************************
Author : ADI - Apps www.analog.com/MicroConverter
Date : Sept. 2005
File : WakeUpTimer.c
Hardware : Applicable to ADuC702x rev H or I silicon
Currently targetting ADuC7026.
Description : Wake-up Timer causes part to power-up, perform an Analog
to Digital Conversion, output conversion via UART at 9600bps
and power-down again, once every minute.
the debugger cannot be used when the part is placed in power down mode.
*********************************************************************/
#include <ADuC7026.h>
void My_IRQ_Function(void);
void senddata(short);
void ADCpoweron(int);
char hex2ascii(char);
int main(void)
{
GP4DAT = 0x04000000; // Configure P4.2 as output
GP4DAT ^= 0x00040000; // Complement P4.2
GP1CON = 0x011; // Setup tx & rx pins on P1.0 and P1.1
// Start setting up UART at 9600bps (CD = 0 in startup.s)
COMCON0 = 0x80; // Setting DLAB
COMDIV0 = 0x88; //
COMDIV1 = 0x00;
COMCON0 = 0x07; // Clearing DLAB
T2CON = 0xE8; // Configures Timer2 to count down, with
// "Hr:Min:Sec:Hundredths" format and prescalar of 256
T2LD = 0x00010000; // Sets the counter register to 5 minutes. Format: HH:MM:SS:hh
IRQ = My_IRQ_Function; // Specify Interrupt Service Rountine
IRQEN = WAKEUP_TIMER_BIT; // Enable wake up timer IRQ
/* POWKEY1 = 0x01;
POWCON = 0x30; // Device in sleep mode
POWKEY2 = 0xF4;
*/ GP4DAT ^= 0x00040000; // Complement P4.2
while (1){
}
return 0;
}
/********************************************************************/
/* */
/* Interrupt Service Rountine */
/* */
/********************************************************************/
void My_IRQ_Function()
{
GP4DAT ^= 0x00040000; // Complement P4.2 each time an interrupt
// occurs (light on during conversion)
//ADC configuration
ADCpoweron(20000); // power on ADC
REFCON = 0x01; // connect internal 2.5V reference to VREF pin
ADCCP = 0x00; // Selecting ADC Channel 0
ADCCON = 0x4E3; // Perform single software conversion (ADC Speed = 1 MSPS)
while (!ADCSTA){} // wait for end of conversion
senddata(ADCDAT >> 16); // Output Conversion
ADCCON = 0x00; // Powers Down ADC
int t = 5000; // Delay required to send data via UART
while(t>0)
{
t--;
}
GP4DAT ^= 0x00040000; // Complement P4.2 at end of conversion (switches off)
T2CLRI = 0xFF; // Clearing Timer2 Interrupt
/* POWKEY1 = 0x01;
POWCON = 0x30; // Device in sleep mode
POWKEY2 = 0xF4;
*/
return;
}
void ADCpoweron(int time)
{
ADCCON = 0x20; // power-on the ADC
while (time >=0) // wait for ADC to be fully powered on
time--;
}
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -