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

📄 banking.c

📁 UPSD单片机驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	
   temp_Dir = 0;
      
   // At this point we have a selected menu item
   // Run the demo code user selected----------------------------------------
   
   switch(Menu_Index)
   {
   case 0: 
   //============================ Demo0: PWM ADC ====================================

   PSD_reg.CONTROL_B&=0xF1;      // MCU IO/Address OUT: mode 
   PSD_reg.DRIVE_B&=0xF1;     // OpenDrain & SlewRate control
   PSD_reg.DIRECTION_B|=0x07;
   PSD_reg.DATAOUT_B&=0xF1;

   lcd_clear();
   if(flag)
  	{
   		printfLCD("PWM/ADC Demo" );
   		ADC_channel=7;
   		init_msgbuff(" ADC=XXX \n", &msg_buff);   // Load msg_buff with Message
	 }
	 else
	 {
		printfLCD("PWM/ADC 演示" );
   		ADC_channel=7;
   		init_msgbuff(" ADC=XXX \n", &msg_buff);   // Load msg_buff with Message
	 }
   ACON |= 0x20;                             // Enable ADC
   k=0;
   while(1){
         if (k == 0) k = 0xff;     // Fix over flow of 0H -> 0FFh
         if (k == 0xf) k = 0;      // Fix over flow from 0FFh -> 0Fh
          PWM_Mode1_Init(0, k);
         delay_1sec();             // wait for voltage to settle
		if(flag)
		{
         	printfLCD("\nPWM=%x",k);  //display adc channel and adc value on LCD
		}
		else
		{
			printfLCD("\nPWM=%x",k);  //display adc channel and adc value on LCD
		}

         ADC_Init(ADC_channel);                 // Init & read ADC channel
         ADC_result = ADC_Read(ADC_channel);
         msg_buff[5] = htoa_lo(ADC_result>>8);  // Convert to ascii hex to display
         msg_buff[6] = htoa_hi(ADC_result);
         msg_buff[7] = htoa_lo(ADC_result);
         printfLCD(msg_buff);             //display adc channel and adc value on LCD
         k = k + 0x10;
   }
   break;
   
   case 1:
   //============================ Demo1: I2C RTC =====================================

      //---------------------- Check RTC tamper function -----------------------------------------
      Turbo_i2c_init();
      ST87_tamper_init();

      //---------------------- Waiting user set time -----------------------------------------
      lcd_clear(); 
      if(flag)
	  {
     	 printfLCD("Use Encoder to" );
      	printfLCD("\nset Date & Time" );
	  }
	  else
	 {
		 printfLCD("转动编码器" );
      	printfLCD("\n设置日期和时间" );
	 }
      delay_1sec();
      delay_1sec();
      Turbo_i2c_init();
      ST87_read();
      st87.second=i2c_rcv_buf[1];
      st87.minute=i2c_rcv_buf[2];
      st87.hour=i2c_rcv_buf[3];
      st87.day=i2c_rcv_buf[5];
      st87.month=i2c_rcv_buf[6];
      st87.year=i2c_rcv_buf[7];

// Set the RTC time...
      
      for (k=0; k<6; k++)              // Six items to adjust DMY & HMS
      {
        Show_time(k);  // Show inital time from RTC and have user adjust
        event = Polling_Encoder();  // get first encoder event
        while (event != 3) {
          Adjust_time(k, event);    // Adjust value and display
          Show_time(k);
          event = Polling_Encoder();  // get next event
        }
      }
      
//----------------------------Save time into ST87-------------------------------------
         i2c_xmit_buf[2]=st87.second;
         i2c_xmit_buf[3]=st87.minute;
         i2c_xmit_buf[4]=st87.hour;
         i2c_xmit_buf[6]=st87.day;
         i2c_xmit_buf[7]=st87.month;
         i2c_xmit_buf[8]=st87.year;
         ST87_write();
         ST87_config();

// -------- Start Display of RTC and Tamper Check ------

      lcd_clear();
      while (TRUE){
         ST87_read();                                   // Read & Display ST87 time

         ulayer = 0;
         ucol = 0;
		 if(flag)
		 {
			 printfLCD("I2C RTC Demo"); 
        	 printfLCD("\nTime: %x",i2c_rcv_buf[3]);
         	printfLCD(":%x",i2c_rcv_buf[2]);
         	printfLCD(":%x\n",i2c_rcv_buf[1]);
		 }
		 else
	 	{
			 printfLCD("I2C RTC 演示"); 
        	 printfLCD("\nTime: %x",i2c_rcv_buf[3]);
         	printfLCD(":%x",i2c_rcv_buf[2]);
         	printfLCD(":%x\n",i2c_rcv_buf[1]);
	 	}
         
         Tamper_check();                     // Check to see if tamper
         
         if(Key_check()==3)                  // Check for tamper clear records
         {
            ST87_tamper_clear();
            lcd_clear();
			if(flag)
			{
           		 printfLCD("Tamper records "); 
            	printfLCD("\nare Cleared!"); 
			}
			else
	 		{
				 printfLCD("触发记录 "); 
            	printfLCD("\n已删!"); 
			 }
            delay_1sec();
            delay_1sec();
            lcd_clear();
         }
      }
   break;

   case 2:
   //============================ Demo2: 8032 Benchmark =================================================
      lcd_init();
	  	if(flag)
		{
      		printfLCD("Simple 8032\n");
      		printfLCD("Mips Benchmark\n");
		}
		else
	 	{
			printfLCD("Simple 8032\n");
      		printfLCD("指令基准\n");
	 	}
      delay_1sec();
      delay_1sec();

      BUSCON = 0xC1;  // set new value to experiment (0x01 - no PFQ/BC or 0xC1 - With PFQ/BC, etc)

      TR0 = 0;  // Stop Timer0
      EA = 0;   // Disable Interrupts - must be done to keep Timer 0 from being reloaded by ISR

      TH0 = 0;  // Set beg_time to 0 on timer0
      TL0 = 0;


    // Keep loop length arround 25K instructions to have large range of mips values
    // this is due to timer0 overflowing more than once when too many instructions executed.

      TR0 = 1;          // Start timer 0

      instructions = benchmark(); // run the benchmark and return # instructions executed

      TR0 = 0;          // Stop timer 0 to read the elapsed time
      end_time = TH0;
      end_time = (end_time<<8) + (unsigned int)TL0;  // Get timer0 value in integer form

      ns_T0 = FREQ_OSC / 1000;  // Get Freq in Mhz
      ns_T0 = 1000 / ns_T0;     // now have ns per OSC clock
      ns_T0 = 12 * ns_T0;    // now have ns per timer 0 count (12 clocks)
      T0_clks = instructions / ns_T0;   // get number of T0 clocks for entire bechmark 


      if (TF0)   // Did Timer0 overflow - then adjust caluclation to add in overflow bit
        {
          delta_time = 0x8000 + (end_time>>1);  // let delta_time = half the number clocks 
          instr = delta_time / T0_clks;  // instr = number ns per instr 
          mips = 10000 / (instr<<1);    // double divisor since total time was cut in half
        }  
      else // no timer0 overflow
        {
          delta_time = end_time;  // delta_time = total number T0 clocks
          instr = delta_time / T0_clks;  // instr = number ns per instr
          mips = 10000 / instr;     // equal number of mips in 10's units and frac in 1's
        }     

      TR0 = 1;
      EA = 1;          // enable ints and timer 0 to run as normal again

      lcd_clear();
      
     // Display Results...

      tmp = BUSCON;  // Store buscon value in char
	  	if(flag)
		{
      		printfLCD("With BUSCON=%x \n", tmp);
      		printfLCD("8032 Mips=");
      		tmp = mips / 10;  // most significant digit of mips
      		printfLCD("%d.", tmp);
      		tmp = (mips-((int)tmp*10));  // get next digit of mips
      		printfLCD("%d ", tmp);
		}
		else
	 	{
			printfLCD("With BUSCON=%x \n", tmp);
      		printfLCD("8032 Mips=");
      		tmp = mips / 10;  // most significant digit of mips
      		printfLCD("%d.", tmp);
      		tmp = (mips-((int)tmp*10));  // get next digit of mips
      		printfLCD("%d ", tmp);
	 	}

      while (1);  // wait for reset

   break;

   case 3:
   //============================ Demo3: Banking ================================================
      {
      void fct_PAGE0();
      void fct_PAGE1();
      void fct_PAGE2();
      void fct_PAGE3();
      void fct_PAGE4();

      lcd_init(); 
		if(flag)
		{
     		printfLCD("Bank switching: ");
     		printfLCD("\nCOMMON BANK...");
		}
		else
	 	{
			printfLCD("存储区组合切换: ");
     		printfLCD("\n公共组...");
	 	}
      fct_PAGE0();
      fct_PAGE1();
      fct_PAGE2();
      fct_PAGE3();
      delay_1sec();
      delay_1sec();
      lcd_clear();
	  	if(flag)
		{
     		 printfLCD("Bank switching: ");
      		printfLCD("\nDEMO is done!   ");
		}
		else
		{
			 printfLCD("存储区组合切换: ");
      		printfLCD("\n演示完毕!   ");
	 	}
      delay_1sec();
      delay_1sec();
      }
   break;
   }
goto RESTART;  //More demonstration
}






⌨️ 快捷键说明

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