每个文件分开 可以少点弯路
制作出来的实物图如下:
单片机源程序如下:
- #include "delay.h"
- #include "oled12864.h"
- #include "uart.h"
- #include "esp8266.h"
- #include "ds18b20.h"
- #include "DHT11.h"
- #include "DS3231.h"
- sbit led1=P0^6;
- sbit led2=P0^7;
- uint8 a,wendu;
- uint16 b,c;
- void riqi(void);
- void shijian(void);
- void Uart2_Init(void);
- /*********************定时器函数************************************/
- void Timer0Init() //100微秒@22.1184MHz
- {
- AUXR |= 0x80; //定时器时钟1T模式
- TMOD &= 0xF0; //设置定时器模式
- TL0 = 0x5C; //设置定时初始值
- TH0 = 0xF7; //设置定时初始值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- }
- void Timer1Init() //1000微秒@22.1184MHz
- {
- AUXR |= 0x40; //定时器时钟1T模式
- TMOD &= 0x0F; //设置定时器模式
- TL1 = 0x9A; //设置定时初始值
- TH1 = 0xA9; //设置定时初始值
- TF1 = 0; //清除TF1标志
- TR1 = 1; //定时器1开始计时
- }
- void timer0() interrupt 1
- {
- TL0 = 0x5C; //设置定时初始值
- TH0 = 0xF7; //设置定时初始值
- TF0 = 0;
- b++;
- if(b>1000)
- {
- b=0;
- led1=~led1;
- }
- }
- void timer1() interrupt 3 //定时器1的中断
- {
- TL1 = 0x9A; //设置定时初始值
- TH1 = 0xA9; //设置定时初始值
- c++;
- if(c>1000)
- {
- c=0;
- led2=~led2;
- }
- }
- void duishi()
- {
-
- delayms(1000);
- UART2_SendStr("GET http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json\r\n\r\n");
- nian=(Data[6]-48)*10+(Data[7]-48);
- yue=(Data[9]-48)*10+(Data[10]-48);
- ri=(Data[12]-48)*10+(Data[13]-48);
- zhou=Data2[4]-48;
- shi=(Data[15]-48)*10+(Data[16]-48);
- fen=(Data[18]-48)*10+(Data[19]-48);
- miao=(Data[21]-48)*10+(Data[22]-48)+4;
- if(miao>60) {miao=60;fen+=1;}
- Ds3231Init();
- //SendString("+++");
- }
- void main()
- {
- Timer0Init();//初始化定时器0
- Timer1Init();//初始化定时器1
-
- EA=1;//开启总中断
- ET0=1;//开启定时器0中断
- ET1=1;//开启定时器1中断
-
- Delayus(6000);
- P0M0=0X00;P0M1=0X00;
- P1M0=0X00;P1M1=0X00;
- P2M0=0X00;P2M1=0X00;
- P3M0=0X00;P3M1=0X00;
- P4M0=0X00;P4M1=0X00;
- P5M0=0X00;P5M1=0X00;
- P6M0=0X00;P6M1=0X00;
- OLED_Init();
- OLED_Fill(0xff);
- delayms(200);
- OLED_Fill(0x00);
- delayms(200);
- OLED_CLS();
-
- Uart2_Init();
-
- zhoucqh();
- ESP8266_Init();
- duishi();
-
-
- while(1)
- {
- temget();
- wendu=temget();
-
- DHT11_receive();
-
- Ds3231ReadTime();
- shijian();
- riqi();
- }
- }
- void riqi(void)
- {
- OLED_P8x16Ch(0,0,yue/10);
- OLED_P8x16Ch(8,0,yue%10);
- OLED_P8x16Ch(16,0,13);
- OLED_P8x16Ch(24,0,ri/10);
- OLED_P8x16Ch(32,0,ri%10);
- OLED_P8x16Ch(80,0,12);
- OLED_P8x16Ch(88,0,wendu%100/10);
- OLED_P8x16Ch(96,0,wendu%10);
- OLED_P8x16Ch(104,0,11);
- OLED_P8x16Ch(112,0,RH/10);
- OLED_P8x16Ch(120,0,RH%10);
- }
- void shijian(void)
- {
- OLED_P16x32Ch(0,2,shi/10);
- OLED_P16x32Ch(16,2,shi%10);
- OLED_P16x32Ch(32,2,10);
- OLED_P16x32Ch(48,2,fen/10);
- OLED_P16x32Ch(64,2,fen%10);
- OLED_P16x32Ch(80,2,10);
- OLED_P16x32Ch(96,2,miao/10);
- OLED_P16x32Ch(112,2,miao%10);
-
- OLED_P16x16Ch(0,6,24);
- OLED_P16x16Ch(16,6,25);
- if(zhou==0)OLED_P16x16Ch(32,6,26);
- else OLED_P16x16Ch(32,6,zhou);
- }
复制代码
程序还有待改善,大家一起完善下:
oled学习.rar
(85.02 KB, 下载次数: 518)
|