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

📄 dk3200_3_demo.c

📁 ST uPSD32XX I2C This example demo code is provided as is and has no warranty, implied or otherwise.
💻 C
字号:
/*---------------------------------------------------------------------------- Title: DK3200_3_demo.cProject Name: keil_8051_test_1.uv2Date: October 8, 2002Author: Alec BathDescription:Simple demo program to demonstrate the I2C IP functionality using a Real Time Clock(M41ST85)10/18/02 PCL  Modified the code to utlize Switches 1 and 2 to set the Real Time Clock Copyright 2002 ST MicroelectronicsThis example demo code is provided as is and has no warranty,implied or otherwise.  You are free to use/modify any of the providedcode at your own risk in your applications with the expressed limitationof liability (see below) so long as your product using the code containsat 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 ORCONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OROTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.----------------------------------------------------------------------------*/ #pragma SYMBOLS					                                           // include#pragma NOAREGS					                                           // include#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_io.h"			                                               // Char LCD routines#include "upsd_timer.h"			                                           // Timer routines#include <stdio.h>				                                           // prototype declarations for standard Keil library functions #include <string.h>#include <intrins.h>xdata PSD_REGS PSD8xx_reg _at_ PSD_REG_ADDR;                               // Define PSD registers at address "csiop" spaceextern bit st85_alarm_flag;extern xdata unsigned char i2c_xmit_buf[256];							   // message xmit bufferextern xdata unsigned char i2c_rcv_buf[256];							   // message rcv buffer// MAIN Demo Programvoid main (void) {	WDKEY = 0x55;									                       // disable the watchdog	PSD8xx_reg.VM |= 0x80;  					                           // enable peripheral I/O mode for LCD display    timer0_initialize();   	 						                       // initialize timer0 interrupt      upsd_i2c_init();   	lcd_init();										                       // initialize LCD. 8 bits, 2 lines, 5x7 font,	printfLCD("DK3200 for uPSD\n");					                       //display on LCD	timer0_delay(1000);								                       // delay	printfLCD("RTC - I2C Demo\n");					                       //display on LCD	timer0_delay(1000);								                       // delay	lcd_clear();	PSD8xx_reg.DIRECTION_B |= 0x03;					                       // set PSD-PB0,1 DDR high	PSD8xx_reg.DATAOUT_B |= 0x02;					                       // disable LED2    printfLCD("To Set Time \n");		                                   //display on LCD    printfLCD("Press sw1 & sw2 \n");	           	                       //display on LCD   	timer0_delay(2000);	    lcd_clear();        uPSD_read_clock_init();   											   // Initialize the clock    while (TRUE){         uPSD_i2c_st85_read_clock();				                       // Read & Print ST85         if ((PSD8xx_reg.DATAIN_B &= 0x0c) == 0){	                       // check if both sw1 and sw2 are pressed           read_switch();												   // if yes, go set the clock	       lcd_clear();		   printfLCD("Updating Clock..\n");				                   // display on LCD	       timer0_delay(1200);			                                   // 1 Sec delay     	   lcd_clear();         }         timer0_delay(100);  					                           // Wait 100 ms	 }}void read_switch (void){	 int j;	 printfLCD("To Change Time: \n");		                               //display on LCD     printfLCD("SW1:Hour SW2:Mins\n");		                               //display on LCD	 timer0_delay(1200);		 	 for (j=0; j<40; j++){	    timer0_delay(400);			    switch (PSD8xx_reg.DATAIN_B | 0xF3) {	   			case 0xFB: 									                   // for DK3200 board (active lo)	   		    {                lcd_clear();				set_hour();												   // Set the hour                 uPSD_i2c_st85_read_clock();				                   // Read & Print ST85                				break;			}            case 0xF7:   			{				 lcd_clear();				 set_minutes();											   // Set the minute                 uPSD_i2c_st85_read_clock();				               // Read & Print ST85		         break;  		 	}		        }     }}

⌨️ 快捷键说明

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