【正文】
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()。 //設定初始時間 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 characteristic distortion, or anomaly to the earth’s magnetic field that is unique to the shape of the object. Magnetic distortions can be categorized as two types—hard iron and soft iron effects. Hard iron distortions arise from permanent magnets and magnetized iron or steel on the pass platform. These distortions will remain constant and in a fixed location relative to the pass for all heading orientations. Hard iron effects add a constant magnitude field ponent along each axes of the sensor output. To pensate for hard iron distortion is usually done by rotating the pass and platform (your car) in a circle and measure enough points on the circle to determine this offset. Once found, the (X,Y) offset can be stored in memory and subtracted from every reading. The net result will be to eliminate the hard iron disturbance from the heading calculation.The soft iron distortion arises from the interaction of the earth’s magnetic field and any magnetically soft material surrounding the pass. Like the hard iron materials, the soft metals also distort the earth’s magnetic field lines. The difference is