AVR单片机实现电子时钟设计.txt
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
#include <avr/wdt.h>
#include <avr/eeprom.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
#define xtal 8
#define CS PA5
#define SID PA6
#define SCLK PA7
#define Set_CS() DDRA |= (1<<CS);PORTA |= (1<<CS)
#define Set_SID() DDRA |= (1<<SID);PORTA |= (1<<SID)
#define Set_SCLK() DDRA |= (1<<SCLK);PORTA |= (1<<SCLK)
#define Clr_CS() DDRA |= (1<<CS);PORTA &=~(1<<CS)
#define Clr_SID() DDRA |= (1<<SID);PORTA &=~(1<<SID)
#define Clr_SCLK() DDRA |= (1<<SCLK);PORTA &=~(1<<SCLK)
#define HH 2 //定义 时 为2
#define MM 1 //定义 分 为1
#define SS 0 //定义 秒 为0
volatile unsigned char Time_h_m_s[3]={0,0,0}; //时间的 时 分 秒 存贮单元
volatile unsigned char flash_sign=0x00;
//====================================================================
//函数声明
void Delay(uint ms); //延时子程序
void Serial_W_1byte_to_LCD(uchar RS, uchar W_data);
void Serial_send_cmd(uchar send_cmd);
void Serial_send_data(uchar send_data);
void Write_8bits(uchar W_bits);
void LCD_Init(void);
void Serial_send_string_to_xy(uchar row, uchar col, uchar *p);
void Display_clock1(uchar row, uchar col, uchar *time);
/*=============================================================
功能: TIMER2溢出中断函数
=================================================================*/
SIGNAL(SIG_OUTPUT_COMPARE2) // _VECTOR(3)
{
static unsigned char half_second;
if((++half_second)>=2)
{
if((++Time_h_m_s[SS])>=60)
{
Time_h_m_s[SS] = 0;
if((++Time_h_m_s[MM])>=60)
{
Time_h_m_s[MM] = 0;
if((++Time_h_m_s[HH])>=24)
Time_h_m_s[HH] = 0;
}
}
half_second = 0x00;
}
flash_sign &= 0x01;
flash_sign ^= 0x01; //置位闪动标志位(该位为0时闪动)
}
/*******************************************************************
函 数 名:Port_init
第 1 页
PDF created with pdfFactory trial version www.pdffactory.com
评论2