|
附原理图及主函数代码
void main()
{
P_SW2 |= 0x80;
P0M0=0x00; P0M1=0x00; //设置为双向IO
P1M0=0x02; P1M1=0x08; //P13设置为ADC输入,P11设置为推挽输出
P2M0=0x00; P2M1=0x00; //设置为双向IO
P3M0=0x20; P3M1=0xa0; //P35设置为开漏输出,P37设置为高阻输入
P4M0=0x00; P4M1=0x00; //设置为双向IO
P5M0=0x00; P5M1=0x00; //设置为双向IO
P6M0=0x00; P6M1=0x00; //设置为双向IO
P7M0=0x00; P7M1=0x00; //设置为双向IO
P0=1;P12=1;P2=1;P34=1;P36=1;P4=1;P5=1;P6=1;P7=1;
P1IE=0x37; //关闭外部晶振&P13的数字输入
P3PU=0x7f; //打开P30~P36内部上拉电阻
AUXR = 0xc0; //Timer0&Timer1 set as 1T, 16 bits timer auto-reload,
cnt_1ms = 10000 / 1000;
adc_init(); //ADC初始化
tm0_init(); //TIMER0初始化
tm1_init(); //TIMER1初始化
tm3_init();
RTC_config(); //RTC初始化
CMP_config(); //比较器初始化
OLED_Init(); //初始化OLED
OLED_Clear();
DisplayRTC();
while(1)
{
WKTCH=0xff;
WKTCL=0xfe;
Ext_Vcc_Det(); //每15秒钟检测一次外部电源,如果外部电源连接则工作,外部电源断开则进入休眠模式
CaculateWeekDay(YEAR,MONTH,DAY);
if(B_1s)
{
B_1s = 0;
DisplayRTC();
}
if(B_1ms) //1ms到
{
B_1ms = 0;
if(++msecond >= 500) //500ms到
{
msecond = 0;
if(Get_ADC12bitResult(3)<4096)
OLED_ShowNum(96,6,NTC_Lookup(Get_ADC12bitResult(3)),2,16,16);
else OLED_ShowString(96,6,"--",16);
}
}
if(B1_1ms)
{
B1_1ms = 0;
if(B_IR_Press) //检测到收到红外键码
{
B_IR_Press = 0;
LED8[0] = (u8)((UserCode >> 12) & 0x0f); //用户码高字节的高半字节
LED8[1] = (u8)((UserCode >> 8) & 0x0f); //用户码高字节的低半字节
LED8[2] = (u8)((UserCode >> 4) & 0x0f); //用户码低字节的高半字节
LED8[3] = (u8)(UserCode & 0x0f); //用户码低字节的低半字节
LED8[6] = IR_code >> 4;
LED8[7] = IR_code & 0x0f;
}
if(LED8[6]==4&&LED8[7]==5) OLED_Display_Off();
if(LED8[6]==4&&LED8[7]==6) OLED_Display_On();
}
key_scan();
//OLED_Clear();
//delay_ms(500);
//OLED_DrawBMP(0,0,128,8,BMP1); //图片显示(图片显示慎用,生成的字表较大,会占用较多空间,FLASH空间8K以下慎用)
//delay_ms(500);
//OLED_DrawBMP(0,0,128,8,BMP2);
//delay_ms(500);
}
} |
|