📄 mega16._c
字号:
//**************************************************************************/
// 探头控制器第二代mega16L
// mega16L 8M
//*************************************************************************/
//创 建 人:胡勇刚
//创建日期:2005年3月3日
//版 本 号:001
//*************************************************************************/
#define TANTOU_C
#include "config.h"
#define key_in() ((PINB >> 5) & 0x07)
uchar char_count;
uchar set_state;
uchar time_data[16];
uchar i;
//-------------------------------------------------------------------------
#pragma interrupt_handler int0_isr:2
void int0_isr(void);
#pragma interrupt_handler int1_isr:3
void int1_isr(void);
//-------------------------------------------------------------------------
void port_int (void); //端口初始化
void init_devices(void); //单片机初始化
void delay_us (uint time); //延迟time微秒
void delay_ms (uint time); //延迟time毫秒
void count_write(uchar ,uchar ,uchar);
//-------------------------------------------------------------------------
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0xFF;
DDRB = 0x1F;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0xff;
DDRD = 0x00;
}
//-------------------------------------------------------------------------
void delay_us(uint time)
{
uint i;
for(i=0;i<time;i++)
{
delay_1us();
}
}
//-------------------------------------------------------------------------
void delay_ms(uint time)
{
uint i;
for(i=0;i<time;i++)
{
delay_us(1000);
}
}
/******************************************************************************/
void count_write(uchar x,uchar y,uchar count)
{
lcd_print816(x,y,count_array[count >> 4]);
lcd_print816(x,y+8,count_array[count & 0xf]);
}
/******************************************************************************/
void count_reverse(uchar x,uchar y,uchar count)
{
lcd_reverse(x,y,count_array[count>>4]);
lcd_reverse(x,y+8,count_array[count & 0xf]);
}
/******************************************************************************/
//Watchdog initialize
// prescale: 2048K
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget to issue WDRs
}
void watchdog_off(void)
{
WDR();
WDTCR |= BIT(WDTOE);
WDTCR = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
watchdog_init();
MCUCR = 0x00;
GICR = 0xC0;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void time_init(void)
{
/* 初始化pcf8563 */
time_data[0] = 9;
time_data[1] = 0;
time_data[2] = 0; //控制/状态寄存器1
time_data[3] = 0; //控制/状态寄存器2
time_data[4] = 0; //秒
time_data[5] = 0x30; //分
time_data[6] = 0x12; //时
time_data[7] = 0x16; //日
time_data[8] = 0x00; //星期
time_data[9] = 0x03; //月/世
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -