【正文】
(value)。}//********讀取當(dāng)前時間********void read_rtc(void) { uchar i。 for(i=0。i7。i++) { time_date[i]=read_ds1302(read_add[i])。 }}2. 指南針模塊子程序:/******//*********************************************//串口初始化//9600 bps @ MHz void init_uart(){ TMOD=0x21。 TH1=0xfd。 TL1=0xfd。 SCON=0x50。 //串口方式為10位異步收發(fā),允許串行接受 PS=1。 //串口中斷設(shè)為高優(yōu)先級別 TR0=1。 //啟動定時器 TR1=1。 ET0=1。 //打開定時器0中斷 ES=1。 //開串口中斷 EA=1。 //開總中斷 } ***串口數(shù)據(jù)發(fā)送******************void SeriPushSend(uchar send_data){ SBUF=send_data。 while(!TI)。 TI=0。 }//*********數(shù)據(jù)校驗****************void Chare(){ delay(5)。 // 傳送延時 if(BUF[0]==0X0Damp。amp。BUF[1]==0X0A) //幀頭判斷{ SUM=BUF[6]+BUF[5]+BUF[4]+BUF[3]+BUF[2]+BUF[1]+BUF[0]。 //校驗和} }3. LCD1602液晶模塊子程序//**********寫命令至LCD***********************void write_(uchar ){ lcdrs=0。 //選擇寫命令模式/* lcden=0。 //液晶使能端賦初值 */ P0=。 //將要寫的命令送到數(shù)據(jù)總線上 delay(5)。 lcden=1。 //給使能端一高電平,將命令送入液晶 delay(5)。 lcden=0。 //將使能端置0以完成高脈沖} //**********寫數(shù)據(jù)至LCD************************void write_date(uchar date){ lcdrs=1。 //選擇寫數(shù)據(jù)模式/* lcden=0。 //液晶使能端賦初值 */ P0=date。 //將要寫的數(shù)據(jù)送到數(shù)據(jù)總線上 delay(5)。 lcden=1。 //給使能端一高電平,將數(shù)據(jù)送入液晶 delay(5)。 lcden=0。 //將使能端置0以完成高脈沖}4. 主程序://************主程序************void main(){ delay(50)。 //延時 lcdrw=0。 init()。 //初始化LCD init_uart()。 //初始化口// set_rtc()。 //設(shè)定初始時間 while(1) //循環(huán) { t=0。 //接收數(shù)據(jù)的累計值 SeriPushSend(0X31)。 //發(fā)送1幀讀取命令 delay(5)。 //延時 read_rtc()。 time_pros()。 ReadKey()。 time_tj()。 //按鍵檢測 display()。 //顯示讀取到的數(shù)值 delay(600)。 //一定時間的延時 } //end while}附錄2英文文獻:How Does a Digital Compass Work? An electronic pass such as the Wayfinder uses a patented magnetic sensor technology that was first developed by PNI, Inc. for the . military. This technology is called magnetoinductive and is the largest advancement in pass technology since the fulxgate was invented 60 years ago. The magnetoinductive technology is able to electronically sense the difference in the earth39。s magnetic field from a disturbance caused by external elements such as ferromagnetic materials and the magnetic field generated by automobile electrical systems. WayFinder digital pass has an embedded micro controller that subtracts the automobile magnetic field (the distortion) from the stronger earth magnetic fields resulting in a highly accurate pass reading. Compass InstallationThe performance of a pass will greatly depend on its installation location. A pass relies on the earth’s magnetic field to provide heading. Any distortions of earth magnetic field by other sources such as a car massive iron ponents should be pensated for in order to determine an accurate heading. Sources of magnetic fields in any automobile include permanent magnets mostly in its audio speakers, motors, electric currents flowing in its wiring—either dc or ac, and ferromagnetic metals such as steel or iron. The influence of these sources of interference on an electronic pass accuracy can be greatly reduced by placing the pass far away from them. Some of the field effects can be pensated by way of calibrating the pass for a defined location in terms of magnetic interference. However, it is not always possible to pensate for time varying magnetic fields。 for example, disturbances generated by the motion of magnetic metals, or unpredictable electrical current in a nearby power lines. Magnetic shielding can be used for large field disturbances from motors or audio speakers. The best way to reduce disturbances is distance. Also, never enclose the pass in a magnetically shielded metallic housing.Compass Tilt ErrorsHeading errors due to a tilt depend somewhat on geographic location. At the equator, tilt errors are less critical since the earth39。s field is strictly in the horizontal plane. This provides larger X and Y readings and little of the Z ponent correction near the magnetic poles, tilt errors are extremely important—since there is less X,Y field and more of the Z ponent. Tilt errors are also dependent on the heading. Magnetic Field DistortionsNearby Ferrous materials is another consideration for heading inaccuracy. Since heading is based on the direction of the earth39。s horizontal field a digital pass must be able to measure this field with lesser influence from other nearby magnetic sources or disturbances.The amount of disturbance depends on the material content of the platform and connectors as well as ferrous objects moving nearby. When a ferrous object is placed in a uniform magnetic field it will exert an influence. This object could be a steel bolt or bracket near the pass or an iron door latch close to the pass. The net result is a charact