📄 test1.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info-------------------------------------------------------------------------------
** File Name: I2C_24C02.c
** Last modified Date: 2008.01.21
** Last Version: v1.0
** Description: Stellaris电子钟实验
**
**------------------------------------------------------------------------------------------------------
** Created By: Kang qinhua
** Created date: 2008.01.21
** Version: v1.0
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Description:
**
********************************************************************************************************/
#include "hw_memmap.h"
#include "hw_types.h"
#include "hw_timer.h"
#include "gpio.h"
#include "sysctl.h"
#include "timer.h"
#include "interrupt.h"
#include "hw_ints.h"
#include "ADC.h"
#include "LCD\TIMER0A_int.h"
#include "LCD\PCF8576.H"
#include "LCD\LCD_TH3144.H"
#include "LCD\i2cint.h"
#include "ADC_ISR.h"
#define LED1 GPIO_PIN_7 // 设置PD7为输出
TIME_FORMAT time;
TIME_FORMAT time_setup; // 设置时间的时间变量
TIME_COUNTER time_second;
static unsigned char Start_Time = 0;
void Timer1A_ISR(void)
{
TimerIntClear(TIMER1_BASE, TIMER_RTC_MATCH);
GPIOPinWrite(GPIO_PORTD_BASE, LED1,GPIOPinRead(GPIO_PORTD_BASE, LED1) ^ LED1);
TimerLoadSet(TIMER1_BASE, TIMER_A, 1);
TimerEnable(TIMER1_BASE, TIMER_A);
time.second++;
if( Start_Time ==1)
{
time_second.second++;
}
}
void delay(unsigned int n)
{
volatile int i;
for(;n>0;n--)
{
for(i=0;i<1000;i++);
}
}
#define ReadKey1() GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_4)
#define ReadKey2() GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_5)
#define ReadKey3() GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5)
#define ReadKey4() GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_4)
unsigned char ReadKey(unsigned char KeyNum)
{
switch (KeyNum)
{
case 1:
if( ReadKey1() == 0 ) // Key1是否有效
{
delay( 100 ); // 延时
if( ReadKey1() == 0 ) // Key1是否有效
{
while( ReadKey1() == 0 ); // 等待按键放开
delay( 100 ); // 延时
return(1); // 返回1
}
}
break;
case 2:
if( ReadKey2() == 0 ) // Key2是否有效
{
delay( 100 ); // 延时
if( ReadKey2() == 0 ) // Key2是否有效
{
while( ReadKey2() == 0 ); // 等待按键放开
delay( 100 ); // 延时
return(1); // 返回1
}
}
break;
case 3:
if( ReadKey3() == 0 ) // Key3是否有效
{
delay( 100 ); // 延时
if( ReadKey3() == 0 ) // Key3是否有效
{
while( ReadKey3() == 0 ); // 等待按键放开
delay( 100 ); // 延时
return(1); // 返回1
}
}
break;
case 4:
if( ReadKey4() == 0 ) // Key4是否有效
{
delay( 100 ); // 延时
if( ReadKey4() == 0 ) // Key4是否有效
{
while( ReadKey4() == 0 ); // 等待按键放开
delay( 100 ); // 延时
return(1); // 返回1
}
}
break;
default:
break;
}
return(0); // 否则返回0
}
static unsigned char leap_month[12]={31,29,31,30,31,30,31,31,30,31,30,31};
static unsigned char non_leap_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void Data_Time(void)
{
if(time.second == 60) // 实现时钟的进制转换
{
time.second = 0;
if(time.minute == 59)
{
time.minute = 0;
if(time.hour == 23)
{
time.hour = 0;
if((time.year%4==0)&&((time.year%100!= 0)||(time.year%400==0))) //闰年
{
if(time.date == leap_month[time.month-1])
{
time.date = 1;
if(time.month == 12)
{
time.month = 1;
time.year++;
}
else
time.month ++;
}
else
time.date++;
}
else //非闰年
{
if(time.date == non_leap_month[time.month-1])
{
time.date = 1;
if(time.month == 12)
{
time.month = 1;
time.year++;
}
else
time.month ++;
}
else
time.date++;
}
}
else
time.hour ++;
}
else
time.minute ++;
}
}
static unsigned char Disp_Status = 1; // LCD显示的状态寄存器
void Manage_Key(void)
{
static unsigned char Status=1;
if( (ReadKey(1) == 1) && (Disp_Status<7) ) // KEY1是否有效,切换LCD的显示状态
{
if( Status == 6 ) // 总共有6个状态
{
Status = 1;
Disp_Status = 1;
}
else
{
Status ++;
Disp_Status ++;
}
//初始化一些值
Start_Time = 0; // 开始计时状态无效
time_setup = time; // 把显示的时间送给设置的时间
if( Status == 5 ) // 如果是第4个状态-计时器
{
time_second.minute = 0; //初始化计时时间
time_second.second = 0;
}
}
if( Status == 5 ) // 如果是第5个状态--秒表
{
if( ReadKey(4) == 1 ) // 检测到KEY4按下时
{
if( Start_Time == 0 ) // 如果状态位为0,开始计时
{
time_second.minute = 0;
time_second.second = 0;
Start_Time = 1;
}
else // 否则停止计时
{
Start_Time = 0;
}
}
Disp_Status = 5;
}
if((Status == 1)&(Disp_Status<7))
{
if( ReadKey(4) == 1 )
{
if( Disp_Status == 1 )
{
time_setup = time;
Disp_Status = 7;
}
}
}
if( Disp_Status == 7 ) // 如果是第7个状态-设置时间的小时
{
if( ReadKey(2) == 1 ) // 检测到KEY2按下时,递增小时值
{
if(time_setup.hour == 23)
{
time_setup.hour = 0;
}
else
time_setup.hour++;
}
else if( ReadKey(3) == 1 ) // 检测到KEY3按下时,递减小时值
{
if(time_setup.hour == 0)
{
time_setup.hour = 23;
}
else
time_setup.hour--;
}
else if( ReadKey(4) == 1 ) // 检测到KEY4按下时,确认设置的小时值
{
Disp_Status = 8;
time = time_setup;
}
}
if( Disp_Status == 8 ) // 如果是第8个状态-设置时间的分
{
if( ReadKey(2) == 1 ) //检测到KEY2按下时,递增分值
{
if(time_setup.minute == 59)
{
time_setup.minute = 0;
}
else
time_setup.minute++;
}
else if( ReadKey(3) == 1 ) //检测到KEY3按下时,递减分值
{
if(time_setup.minute == 0)
{
time_setup.minute = 59;
}
else
time_setup.minute--;
}
else if( ReadKey(4) == 1 ) // 检测到KEY4按下时,确认设置的分值并刷新时间
{
time = time_setup;
Disp_Status = 1;
}
}
if((Status == 3)&&(Disp_Status != 9))
{
if( ReadKey(4) == 1 )
{
Disp_Status = 9;
}
}
if( Disp_Status == 9 ) // 如果是第8个状态-设置年
{
if( ReadKey(2) == 1 ) //检测到KEY2按下时,递增
{
time_setup.year++;
}
else if( ReadKey(3) == 1 ) //检测到KEY3按下时,递减
{
time_setup.year--;
}
else if( ReadKey(4) == 1 ) // 检测到KEY4按下时,确认设置的年并刷新时间
{
time = time_setup;
Disp_Status = 3;
}
}
if((Status == 4) &&( Disp_Status < 10))
{
if( ReadKey(4) == 1 )
{
Disp_Status = 10;
}
}
if( Disp_Status == 10 ) // 如果是第9个状态-设置月
{
if( ReadKey(2) == 1 ) //检测到KEY2按下时,递增
{
if(time_setup.month == 12)
{
time_setup.month = 1;
}
else
time_setup.month++;
}
else if( ReadKey(3) == 1 ) //检测到KEY3按下时,递减
{
if(time_setup.month == 1)
{
time_setup.month = 12;
}
else
time_setup.month--;
}
else if( ReadKey(4) == 1 ) // 检测到KEY4按下时,确认设置的月并刷新时间
{
time = time_setup;
Disp_Status = 11;
}
}
if( Disp_Status == 11 ) // 如果是第10个状态-设置日
{
if( ReadKey(2) == 1 ) //检测到KEY2按下时,递增
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -