?? main.c
字號:
#include "C8051F020.h"
#include "CM240128.H"
#include "menu.h"
#include "引導菜單.h"
#include "輸入狀態欄.h"
#include "fm24c256.h"
#include "gprs.h"
#include "數據存儲.h"
#include "m41t0drv.h"
#include <string.h>
#include "comm.h"
#include "unic.h"
#include "數據發送.h"
#include <intrins.h>
//--------------------------------------------------------------------------------------------------------------
# define uchar unsigned char
# define uint unsigned int
#define BAUDRATE 115200 // Baud rate of UART in bps
#define SYSCLK 11059200 // SYSCLK frequency in Hz
#define dq P7_0
unsigned char debug =1;
unsigned char MainMenu;
extern xdata DataType InputData;
extern unsigned int gb ;
bit flag;
uint Temperature;
uchar temp_buff[9];//存取讀取得字節,READ SCRATCHPAD為9字節,READ為8字節
uchar id_buff[8];
uchar *p;
uchar code Crctable[256]={
0,94,188,226,97,63,221,131,194,156,126,32,163,253,31,65,
157,195,33,127,252,162,64,30,95,1,227,189,62,96,130,220,
35,125,159,193,66,28,254,160,225,191,93,3,128,222,60,98,
190,224,2,92,223,129,99,61,124,34,192,158,29,67,161,255,
70,24,250,164,39,121,155,197,132,218,56,102,229,187,89,7,
219,133,103,57,186,228,6,88,25,71,165,251,120,38,196,154,
101,59,217,135,4,90,184,230,167,249,27,69,198,152,122,36,
248,166,68,26,153,199,37,123,58,100,134,216,91,5,231,185,
140,210,48,110,237,179,81,15,78,16,242,172,47,113,147,205,
17,79,173,243,112,46,204,146,211,141,111,49,178,236,14,80,
175,241,19,77,206,144,114,44,109,51,209,143,12,82,176,238,
50,108,142,208,83,13,239,177,240,174,76,18,145,207,45,115,
202,148,118,40,171,245,23,73,8,86,180,234,105,55,213,139,
87,9,235,181,54,104,138,212,149,203,41,119,244,170,72,22,
233,183,85,11,136,214,52,106,43,117,151,201,74,20,246,168,
116,42,200,150,21,75,169,247,182,232,10,84,215,137,107,53};
void tempDelay(uchar us)
{
while(us--);
}
void init18b20(void)
{
dq=1;
_nop_();
dq=0;
tempDelay(86); tempDelay(86); tempDelay(86); tempDelay(86);
tempDelay(86); tempDelay(86); tempDelay(86); tempDelay(86);
tempDelay(86); tempDelay(86); tempDelay(86); tempDelay(86);
_nop_();
dq=1;
tempDelay(14); tempDelay(14); tempDelay(14); tempDelay(14);
tempDelay(14); tempDelay(14); tempDelay(14); tempDelay(14);
tempDelay(14); tempDelay(14); tempDelay(14); tempDelay(14);
_nop_(); _nop_(); _nop_();
if(dq==0)
flag=1;//成功
else
flag=0;
tempDelay(20); tempDelay(20); tempDelay(20); tempDelay(20);
tempDelay(20); tempDelay(20); tempDelay(20); tempDelay(20);
tempDelay(20); tempDelay(20); tempDelay(20); tempDelay(20);
_nop_(); _nop_();
dq=1;
}
void GoMainMenu(void)
{
MainMenu=1;
}
void delay(void)
{
unsigned char i,j;
for(i=0;i<250;i++)
{
for(j=0;j<250;j++);
}
}
void fs(unsigned char z)
{
bit ReceiveBit;
SBUF1=z;//temp1;
ReceiveBit= 0;
while( ReceiveBit== 0)
{ReceiveBit=SCON1&0X2;}
SCON1 &=0XFD;
ReceiveBit= 0;
}
unsigned char js(void)
{
bit ReceiveBit;
unsigned char temp1;
aaa:
ReceiveBit=SCON1&0X1;
if(ReceiveBit== 0)goto aaa;
while( ReceiveBit== 1){
SCON1 &=0XFE;
temp1 = SBUF1;
return temp1;
}
}
void main (void)
{
xdata unsigned char disbuf[20];
xdata DateTimeTYP datetime;
static idata unsigned char oldmin,i;
unsigned int timeval;
xdata unsigned char jsbuf[256];
Oscillator_Init();
WatchDog(0);
Port_IO_Init();
P74OUT = 0x3f;
P0MDOUT = 0xff;
P1MDOUT = 0x0f; // 1對應的引腳是推挽輸出 0對應的引腳是漏極開路輸出 開機默認:0x00
P2MDOUT = 0; // 1對應的引腳是推挽輸出 0對應的引腳是漏極開路輸出 開機默認:0x00
P3MDOUT = 0;
P7 = 0xff;//gprs控制
P2=0xff;
P3=0xff;
T3Stup(1000);
EA=1;
TickCount=6000;//下次心跳延時時間 (TickCount/1000)秒
Lcd_Init();
ClrDisplay();
CommInit();
OSCXCN = 0x67; // start external oscillator with
while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
OSCICN = 0x88; // select external oscillator as SYSCLK
SCON1 = 0x50; // SCON0: mode 1, 8-bit UART, enable RX
SCON0 = 0x50; // SCON0: mode 1, 8-bit UART, enable RX
TMOD = 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TH1 = -(SYSCLK/BAUDRATE/16); // set Timer1 reload value for baudrate
TR1 = 1; // start Timer1
CKCON |= 0x10; // Timer1 uses SYSCLK as time base
PCON |= 0x90; // SMOD00 = 1
TI0 = 1; // Indicate TX0 ready
SCON1 |= 0x12; // Indicate TX1 ready
for(i=0;i<200;i++){jsbuf[i]=0;}
UART1SETUP(115200,8);
UART1DISABLE();
//SBUF1 =0x00;//串口輸出
//UART0SETUP(57600,8);//設置串口
//UART0DISABLE();//關串口中斷
GetM41T0Time(&datetime);
InputData.datetime[0] = (datetime.year>>4)+'0';
InputData.datetime[1] = (datetime.year&0x0f)+'0';
InputData.datetime[2] = (datetime.month>>4)+'0';
InputData.datetime[3] = (datetime.month&0x0f)+'0';
InputData.datetime[4] = (datetime.date>>4)+'0';
InputData.datetime[5] = (datetime.date&0x0f)+'0';
InputData.datetime[6] = (datetime.hour>>4)+'0';
InputData.datetime[7] = (datetime.hour&0x0f)+'0';
InputData.datetime[8] = (datetime.min>>4)+'0';
InputData.datetime[9] = (datetime.min&0x0f)+'0';
InputData.datetime[10] = 0;
InputData.datetime[11] = 0;
AppendData(&InputData);
/*
UART0SETUP(57600,8);//設置串口
UART0DISABLE();//關串口中斷
if(DataInit()!=0)
{
//-------------------------------------------
//歡迎界面及啟動GPRS
SetCurrLoc(0,0);
DisplayStr("系統初始化請等待...",30);
for(i=0;i<60000;i++);
LoadServerIP();
if(strlen(ServerIp)>7)GPRSInit();
//-------------------------------------------
}
UART0ENABLE();//開串口中斷
*/
GoMainMenu();
while (1)
{
if(MainMenu==1){MainMenu=0;MENU_Boot(0);}
CommInceptProc();
MenuScan();
MenuIncept(InputStateInput());
/*
if(TickCount==0)
{
TickCount=60000;//下次心跳延時時間 (TickCount/1000)秒
UART0Write(" ",3);
}
*/
GetM41T0Time(&datetime);
if(oldmin!=datetime.min)
{
oldmin=datetime.min;
disbuf[0] = '2';
disbuf[1] = '0';
disbuf[2] = (datetime.year>>4)+'0';
disbuf[3] = (datetime.year&0x0f)+'0';
disbuf[4] = '-';
disbuf[5] = (datetime.month>>4)+'0';
disbuf[6] = (datetime.month&0x0f)+'0';
disbuf[7] = '-';
disbuf[8] = (datetime.date>>4)+'0';
disbuf[9] = (datetime.date&0x0f)+'0';
disbuf[10] = '|';
disbuf[11] = (datetime.hour>>4)+'0';
disbuf[12] = (datetime.hour&0x0f)+'0';
disbuf[13] = ':';
disbuf[14] = (datetime.min>>4)+'0';
disbuf[15] = (datetime.min&0x0f)+'0';
disbuf[16] = 0;
disbuf[17] = 0;
disbuf[18] = 0;
disbuf[19] = 0;
SetCurrLoc(10,0);
DisplayFill(' ',20);
SetCurrLoc(14,0);
DisplayStr(disbuf,20);
timeval = (disbuf[11]-0x30);
timeval*=10;
timeval += (disbuf[12]-0x30);
timeval*=10;
timeval += (disbuf[14]-0x30);
timeval*=10;
timeval += (disbuf[15]-0x30);
if(timeval == GetAutoSendTime())
{
MENU_DataSend(0);//時間到數據發送
}
}
}
}
//-----------------------------------------------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -