|
楼主 |
发表于 2011-8-17 09:27:50
|
显示全部楼层
部分程序
#include <iom169v.h>
#include <MATH.H>
#include <macros.h>
#include <eeprom.h>
#define uchar unsigned char
#define uint unsigned int
uchar half_hour;
//TIMER2 initialize - prescale:1024
// WGM: Normal
// desired value: 500mSec
// actual value: 500.000mSec (0.0%)
void timer2_init(void)
{
TCCR2A = 0x00; //stop
ASSR = 0x08; //set async mode
TCNT2 = 0xF0; //setup
OCR2A = 0x10;
TCCR2A = 0x07; //start
}
void init_devices(void)
{
CLI(); //disable all interrupts
port_init();
timer2_init();
adc_init();
lcd_init();
TIMSK0 = 0x00; //timer interrupt sources
TIMSK1 = 0x00; //timer interrupt sources
TIMSK2 = 0x01; //timer interrupt sources
PCMSK0 = 0x70; //pin change mask
PCMSK1 = 0x00; //pin change mask
EICRA = 0x00; //int0 setup
EIMSK = 0X40; //只使用PCMSK0
SMCR = 0x00;
// SEI(); //re-enable interrupts
}
#pragma interrupt_handler timer2_ovf_isr:6
void timer2_ovf_isr(void)
{
static uchar jjj,SSS;
uchar bbb,i,j,k;
uint xxx;
TCNT2 = 0xF0;//
shanshuo=~shanshuo;
huajianscan();//判断滑键
show_page_all();//显示程序
half_hour++;
if (half_hour>1){
half_hour=0;
if (back_led_time>0)
{
back_led_time--;
}
if (back_led_time==1) close_back_led();
if (now_second>=59){
now_second=0;
if (now_minute>=59){
now_minute=0;
if (now_hour>=23){
now_hour=0;
if (now_week>=6)now_week=0;
else now_week++;
}
else now_hour++;
}
else now_minute++;
}
else now_second++;
}
void main(void)
{
init_devices();
//上电初始化时间
now_hour=8;
now_week=0;
now_minute=0;
now_page=0;
SEI();//开中断
while(1)
{
ADCSRA&=~(1<<ADEN);//禁止ad
SMCR = 0x06;//设置空闲模式
asm("nop");
SMCR |= 0x01;//启动空闲模式
asm("sleep");// 进入休眠
asm("nop");//唤醒后确保4个时钟周期后工作
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
} |
|