📄 dk3200 talkingtimerdemo.c
字号:
/* `=========================================================================`
***************************************
**** * * ****
Title: DK3200_TIMER_DEMO
File name: DK3200_Timer_Demo.c
Project name: DK3200_TIMER_DEMO
*** ****
****************** * ******************
**** ****
Author: Petr PFEIFER
MPG Prague, Czech Republic
**** * * ****
***************************************
$Version: 1.030 Build: 2004-04-18,14:42:01
Description:
============
This is a Timer demo,
simple demo program to demonstrate
the I2C IP functionality
using a Real Time Clock(M41ST85).
This version also says what's the time
at begin and every 15 minutes. It uses uPSD Sound Studio
Notes:
======
If timer stops counting when power down
(it shows near the same time or delay when powered up again),
please check quality of your lithium battery in SNAPHAT.
Do not forgot to insert all jumpers JP6 (PB0-PB3).
..........................
. .
. ****************** .
. **PPPPPPPPPPPPPPPP .
. *PPPP*******PP**** .
. **PPP********PP*** .
. ***PPP******PP**** .
. *****PPP****PP**** .
. *****PPP****PP**** .
. PPPPPPPP****PP**** (R) .
. .
..........................
=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Copyright (c) 2004 ST Microelectronics
This code/file 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.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=
For current information on uPSD products,
please consult our pages on the World Wide Web:
www.st.com/psm
- - - - - - - - - - - -
STMicroelectronics GROUP OF COMPANIES
Australia - Brazil - China - Czech Republic - Finland - France - Germany
Hong Kong - India - Italy - Japan - Malaysia - Malta - Morocco - Singapore
Spain - Sweden - Switzerland - United Kingdom - U.S.A.
http://www.st.com
`========================================================================` */
#pragma SYMBOLS
#pragma NOAREGS
#pragma CODE // include assembler listing in .lst file
#include "upsd_hardware.h" // environment hardware specific defines
#include "upsd3200.h" // special function register declarations for UPSD
#include "upsd_st85.h" // M41ST85 Timekeeper routines
#include "upsd_i2c.h" // I2C routines
#include "lcd_3200.h" // Char LCD routines
#include "upsd_timer.h" // Timer routines
#include "uPSD_Sound_Studio.h" // uPSD Sound Studio - declarations
#include "TC_Bx.h" // uPSD Sound Studio - declarations
xdata PSD_REGS PSD8xx_reg _at_ PSD_REG_ADDR;
// Define PSD registers at address "csiop" space
extern bit st85_alarm_flag;
extern xdata unsigned char i2c_xmit_buf[256];// message xmit buffer
extern xdata unsigned char i2c_rcv_buf[256]; // message rcv buffer
void SayNumber59(unsigned char num)
/******************************************************************************
Function : void SayNumber59()
Parameters : (unsigned char num)
Description: Says numbers 0 - 59
******************************************************************************/
{
if (num == 0)
{
uPSDSoundStudio_PlayItem(1);
}
else
if (num < 10)
{
uPSDSoundStudio_PlayItem(25);
uPSDSoundStudio_PlayItem(num+1);
}
else
if (num < 21)
{
uPSDSoundStudio_PlayItem(num+1);
}
else
{
uPSDSoundStudio_PlayItem((num / 10)+19);
if ((num % 10) != 0)
{
uPSDSoundStudio_PlayItem((num % 10)+1);
}
}
}
void main (void) using 0
/******************************************************************************
Function : void main ()
Parameters : (void)
Description: The main routine of the programm.
******************************************************************************/
{
data int TimeQuantumCounter;
data int KeyStatus; // LastKeyStatus
data int KeyOneCnt, KeyTwoCnt; // incremented if pressed
data unsigned char x,SayTime;
WDKEY = 0x55; // disable the watchdog
PSD8xx_reg.VM |= 0x80; // enable peripheral I/O mode for LCD display
PSD8xx_reg.DIRECTION_B |= 0x03; // set PSD-PB0,1 DDR high
PSD8xx_reg.DATAOUT_B |= 0x03; // disable LED2, low level active /01/02
timer0_initialize(); // initialize timer0 interrupt
upsd_i2c_init();
uPSDSoundStudio_Init();
initLCD(); // initialize LCD
printfLCD("*** Talking! ***\n"); // display on LCD
printfLCD("(c)ST Prague2004\n"); // display on LCD
timer0_delay(2000); // delay
PSD8xx_reg.DATAOUT_B = 0x00; // disable LED2, low level active /01/02
printfLCD("RTCi2c-TimerDemo\n"); // display on LCD
printfLCD("(c)ST Prague2004\n"); // display on LCD
timer0_delay(2000); // delay
printfLCD("> To Set Time <\n"); // display on LCD
printfLCD("Press SW1 & SW2 \n"); // display on LCD
timer0_delay(2000); // delay
initLCD(); // initialize LCD
printfLCD("DK3200tTimerDemo\n"); // display on LCD
uPSD_read_clock_init(); // Initialize the clock
TimeQuantumCounter = 0; // initial state
KeyOneCnt = 0; // state of SWITCH ONE
KeyTwoCnt = 0; // state of SWITCH TWO
uPSD_i2c_st85_read_clock(); // Read & Print ST85
SayTime = 1;
while (TRUE)
{
if (TimeQuantumCounter == 0)
{
uPSD_i2c_st85_read_clock(); // Read & Print ST85
if ((i2c_rcv_buf[1]==0)&&(
(i2c_rcv_buf[2]==0)||(i2c_rcv_buf[2]==0x15)||(i2c_rcv_buf[2]==0x30)||(i2c_rcv_buf[2]==0x45) ))
{
SayTime = 1; //Say time
}
if (i2c_rcv_buf[0]<0x50)
{
printfLCD(" Time: %x %x %x \r",i2c_rcv_buf[3]&63,i2c_rcv_buf[2],i2c_rcv_buf[1]);
// Print time, in HEX format
PSD8xx_reg.DATAOUT_B = 0x03; // disable LED2, low level active /01/02
}
else
{
printfLCD(" Time: %x:%x:%x \r",i2c_rcv_buf[3]&63,i2c_rcv_buf[2],i2c_rcv_buf[1]);
// Print time, in HEX format
PSD8xx_reg.DATAOUT_B = 0x00; // disable LED2, low level active /01/02
if (SayTime)
{
uPSDSoundStudio_PlayItem(uPSD_SoundItem_THE_TIME_IS_WAV);
// "the time is"
uPSDSoundStudio_Silence(300);
x = i2c_rcv_buf[3]&63;
x = (x/16)*10 + (x % 16);
SayNumber59(x); //Hour
uPSDSoundStudio_Silence(200);
x = i2c_rcv_buf[2];
x = (x/16)*10 + (x % 16); //Minutes
SayNumber59(x);
SayTime = 0;
}
}
}
TimeQuantumCounter++;
if (TimeQuantumCounter>=9)
{
TimeQuantumCounter = 0;
}
KeyStatus = (PSD8xx_reg.DATAIN_B >> 2) ^ 0xFF;
if (KeyStatus & 1) //scan SWITCH ONE
{
KeyOneCnt++; // (still) pressed
}
else
{
KeyOneCnt = 0; //no press or released
}
if (KeyStatus & 2) //scan SWITCH TWO
{
KeyTwoCnt++; // (still) pressed
}
else
{
KeyTwoCnt = 0; //no press or released
}
timer0_delay(50); // Wait
if ((KeyOneCnt==1) || ((KeyOneCnt>50) && ((KeyOneCnt & 0x03)==0)) || ((KeyOneCnt>75) && ((KeyOneCnt & 0x01)==0)) || ((KeyOneCnt>100)))
{
Increment_hour();
TimeQuantumCounter=0;
SayTime = 0;
}
if ((KeyTwoCnt==1) || ((KeyTwoCnt>50) && ((KeyTwoCnt & 0x03)==0)) || ((KeyTwoCnt>75) && ((KeyTwoCnt & 0x01)==0)) || ((KeyTwoCnt>100)))
{
Increment_minutes();
TimeQuantumCounter=0;
SayTime = 0;
}
}
}
/* *************************************************************************
*** ***
** *** End of File *** **
*** ***
************************************************************************* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -