
基于stc12c5a60s2和OLED的电子万年历源码.h.docx
44页Main.c :#include "stc12c5a60s2.h" #include "DS1302.h" #include "DS18B20.h" #include "OLED.h" #include "Key.h" #include "EEPROM.h" extern unsigned char Second,Minute,Hour,Date,Month,Year,Week; void T0_init() { TMOD=0x01; TH0=(65535-50000)/256; TL0=(65535-50000)%256; EA=1; ET0=1; TR0=1; Time_Dis(); } void main() { LCD_Init(); DS1302_Init(); LCD_Fill(0xff); //全亮 LCD_CLS(); //lcd复位 Delay(10); DS18B20_Rst(); DS1302_timeread(); Time_Init(); T0_init(); while(1) { Change_Dat(); } }void timer() interrupt 1 { unsigned char i; i++; TR0=0; TH0=(65535-50000)/256; TL0=(65535-50000)%256; DS1302_timeread(); READ_18B20_Temperature(); if(i==15) { i++; Time_Dis(); Temperature(); } if(i==30) { i=0; Compare_colock(); } TR0=1; }Oled.c:#include "stc12c5a60s2.h"#include "OLED.h"#include "code.h"sbit LCD_SCL=P3^4; //时钟 D0(SCLK)sbit LCD_SDA=P3^5; //D1(MOSI) 数据sbit LCD_RST=P3^6; //复位 sbit LCD_DC =P3^7; //数据/命令控制/*********************LCD 延时1ms************************************/void LCD_DLY_ms(unsigned int ms){ unsigned int a;while(ms){a=1800;while(a--);ms--;}return;}/*********************LCD写数据************************************/ void LCD_WrDat(unsigned char dat) {unsigned char i=8;LCD_DC=1; for(i=0;i<8;i++) //发送一个八位数据 {LCD_SCL=0; LCD_SDA=dat&0x80;LCD_SCL=1; dat<<=1; }}/*********************LCD写命令************************************/ void LCD_WrCmd(unsigned char cmd){unsigned char i=8;LCD_DC=0;for(i=0;i<8;i++) //发送一个八位数据 { LCD_SCL=0; LCD_SDA=cmd&0x80;LCD_SCL=1;cmd<<=1;; } }/*********************LCD 设置坐标************************************/void LCD_Set_Pos(unsigned char x, unsigned char y) { LCD_WrCmd(0xb0+y);LCD_WrCmd(((x&0xf0)>>4)|0x10);LCD_WrCmd((x&0x0f)|0x01); } /*********************LCD全屏************************************/void LCD_Fill(unsigned char bmp_dat) {unsigned char y,x;for(y=0;y<8;y++){LCD_WrCmd(0xb0+y);LCD_WrCmd(0x01);LCD_WrCmd(0x10);for(x=0;x












