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

📄 banking.c

📁 UPSD单片机驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------
banking.c

Version: 
November 23, 2004 Version 2.0 - This is the initial release of the banking demo
for the DK3300-ELCD board.

Description:
This is the banking demo for the uPSD33xx.  This demo is composed of four Demo 
Applications (PWM-ADC, I2C-RTC, Banking and Benchmark) and makes use of the 
Encoder located on the DK boards to select the various menus and control the 
demo.  

This demo is an adaption of the banking demo that runs on the original DK3300 
(that has a 2 line x 16 character dot matrix LCD).  The changes are mainly 
related to the device driver for the enhanced LCD (ELCD) and storage of the 
Tamper Event records in the RTC RAM instead of the SPI EEPROM.  Also added to 
the demo is an option to select whether it runs with English or Chinese 
messages.  


Hardware Platform:
DK3300-ELCD


Copyright (c) 2004 STMicroelectronics Inc.

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 "upsd3300.h"
#include "upsd3300_hardware.h"
#include "upsd3300_adc.h"
#include "upsd3300_timer.h"
#include "upsd3300_lcd.h"
#include "upsd3300_pca-pwm.h"
#include "upsd3300_i2c.h"
#include "st87.h"
#include "encoder.h"

#include "math.h"
#include "key.h"
#include "intrins.h"

unsigned int benchmark(void);   // external proto type definition for assembly benchmark routine

unsigned char idata  msg_buff[20];
xdata PSD_REGS PSD_reg _at_ PSD_REG_ADDR; 
extern xdata unsigned char i2c_xmit_buf[256];
extern xdata unsigned char i2c_rcv_buf[256];
extern Time st87;
unsigned char idata flag = 0;
extern void STname(void);

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

// Display selected item in main menu based on Menu_Index
void Show_Menu(unsigned char m_Menu_Index)
{
   lcd_clear();
   switch(m_Menu_Index)
   {
   case 0:
      printfLCD(">PWM/ADC  I2CRTC" );
      printfLCD("\n Banking  Bench\n" );
   break;
   case 1:
      printfLCD(" PWM/ADC >I2CRTC" );
      printfLCD("\n Banking  Bench\n" );
   break;
   case 2:
      printfLCD(" PWM/ADC  I2CRTC" );
      printfLCD("\n Banking >Bench\n" );
   break;
   case 3:
      printfLCD(" PWM/ADC  I2CRTC" );
      printfLCD("\n>Banking  Bench\n" );
   break;
   }
}

void Show_Menu2(unsigned char m_Menu_Index)
{
	lcd_clear();
	switch(m_Menu_Index)
	{
	case 0:

		printfLCD(">  ENGLISH" );
		printfLCD("\n    中文" );
		flag = 1;
	
	break;
	case 1:
	
		printfLCD("   ENGLISH" );
		ulayer = 3;
		ucol = 0;
	
	printfLCD(">   中文" );
		flag =0;
	break;
	}
}

void Tamper_check()
{
	unsigned char Tamper_sum,Tamper_No;
	signed char Menu_Index;
	unsigned char temp,temp_Dir = 0;

	if((ST87_tamper_check())==1)
	{
        lcd_clear();
		if(flag)
		{
        	printfLCD("New Tamper event" );
    		printfLCD("\n--record saved--" );
		}
		else
	 	{
			printfLCD("新触发事件" );
    		printfLCD("\n--已记录--" );
	 	}
		ST87_tamper_save();
		delay_1sec();
		delay_1sec();

        lcd_clear();
		if(flag)
		{
       		printfLCD("Turn Enc. to see" );
        	printfLCD("\nTamper Records" );
		}
		else
		 {
			printfLCD("转动编码器查看" );
        	printfLCD("\n触发记录" );
	 	}
		delay_1sec();
		delay_1sec();
		delay_1sec();
			
		i2c_xmit_buf[0] = 0x20;		// Setup ST87 start address
		Turbo_i2c_MX (0xD0,1);		// send 1 bytes for st87: addr 0xD0, @ 0x00
	 	Turbo_i2c_MR (0xD0,2);	    // Read address 0x0F for check TB1 and TB2 bits   
		Tamper_sum=i2c_rcv_buf[0];
		Tamper_No=i2c_rcv_buf[1];

		if(Tamper_sum>Tamper_No)temp=Tamper_sum;
		else temp=Tamper_No;
		Menu_Index=0;
		ST87_tamper_Show(Menu_Index);
	
		temp_Dir = 0; 
		while(temp_Dir!=3) 
		{
			temp_Dir=Polling_Encoder();
			if(temp_Dir==2)	
			{
				Menu_Index++;
				if(Menu_Index>=temp)Menu_Index=0;
				ST87_tamper_Show(Menu_Index);
			}
			else if(temp_Dir==1)
			{
				Menu_Index--;
				if(Menu_Index<0)Menu_Index=temp-1;
				ST87_tamper_Show(Menu_Index);
			}
				
			PSD_reg.DIRECTION_B|=0x80;
			PSD_reg.DATAOUT_B|=0x80;
			PSD_reg.DIRECTION_B&=0x7F;	// IN direction
		}
        lcd_clear();
	}
}


// Main Program

main()
{  
   unsigned char temp_Dir =0;
   unsigned char event, k, ADC_channel;
   signed char Menu_Index;
   unsigned int ADC_result;
   unsigned char tmp;
   unsigned int end_time, delta_time, mips, instr, ns_T0, T0_clks, instructions; 

   PSD_reg.VM |= 0x80;                       //Enable peripheral I/O
   timer0_init(); 
   ADC_Init(7);
   lcd_init();  
   lcd_clear();    
   printfLCD("DK3300-ELCD Demo");      
   printfLCD("\nV2.0 Turbo uPSD");
   delay_1sec();
   delay_1sec();
   delay_1sec();
   lcd_clear();               
   printfLCD("Turn Encoder R/L");                     
   printfLCD("\nPress to Select");
   delay_1sec();
   delay_1sec();
   delay_1sec();
   
//------------------------------------------------------------------------------
Menu_Index=0;
	PSD_reg.OMC_AB&=0xF8;
	PSD_reg.OMC_AB|=0x04;
	Show_Menu2 (Menu_Index);
temp_Dir = 0;
	while(temp_Dir!=3)
	{
		temp_Dir=Polling_Encoder();
		if(temp_Dir==2)
		{
				Menu_Index++;
				if(Menu_Index==2)Menu_Index=0;
				Show_Menu2 (Menu_Index);
		}
		else if(temp_Dir==1)
		{
				Menu_Index--;
				if(Menu_Index==-1)Menu_Index=1;
				Show_Menu2 (Menu_Index);
		}
		
		PSD_reg.DIRECTION_B|=0x80;
		PSD_reg.DATAOUT_B|=0x80;
		PSD_reg.DIRECTION_B&=0x7F;	// IN direction
		
	}
//----------------------------------------------------------------------------------------

RESTART:
	//-----Waiting user select a demo to run-----------------------------------------
	//	use OMC_AB[0,1] as a 2-bit counter to identify running of Encoder
	//	use OMC_AB[2] as a running direction indication of Encoder
	//-------------------------------------------------------------------------------
	Menu_Index=0;
	PSD_reg.OMC_AB&=0xF8;
	PSD_reg.OMC_AB|=0x04;
	Show_Menu (Menu_Index);

	temp_Dir = 0;
	while(temp_Dir!=3)
	{
		temp_Dir=Polling_Encoder();
		if(temp_Dir==2)
		{
				Menu_Index++;
				if(Menu_Index==4)Menu_Index=0;
				Show_Menu (Menu_Index);
		}
		else if(temp_Dir==1)
		{
				Menu_Index--;
				if(Menu_Index==-1)Menu_Index=3;
				Show_Menu (Menu_Index);
		}
		
		PSD_reg.DIRECTION_B|=0x80;
		PSD_reg.DATAOUT_B|=0x80;
		PSD_reg.DIRECTION_B&=0x7F;	// IN direction
		
	}

⌨️ 快捷键说明

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