www.pudn.com > hx711_LCD5110.rar > test_eeprom.c, change:2015-07-04,size:3217b


/*--------------------------------------------------------------*/ 
#include <STC12C5A60S2.H> 
#include "hx711.h" 
#include "5110.h" 
#include "HW_EEPROM.h" 
 
//	#include <absacc.h>		//绝对地址访问 
//	#include <string.h>		//字符串处理 
//	#include <intrins.h>	//内部函数,汇编相关	 
//	#include <ctype.h>		//字符分类,字符转换 
//	#include <math.h>		//数学运算 
//	#include <stdio.h>		//标准输入/输出 
//	#include <stdlib.h>		//内存管理 
#define N 23				//定义滤波寄存器个数 
#define  eeprom_address  0x0000    //定义地址寄存器 
/**********************定义共用体***************************/ 
union Uni_4Byte    // 共用体(联合体),存放4Byte数据 
{ 
    unsigned long  all; 
    unsigned char  S[4]; 
} ; 
union Uni_4Byte convert_DATA;   //定义一个数据共用体 
 
union Uni_2Byte    // 共用体(联合体),存放2Byte数据 
{ 
    unsigned int  all; 
    unsigned char  S[2]; 
} ; 
union Uni_2Byte zero_data;   //定义一个数据共用体 
 
sbit zero_key=P3^0; 
unsigned long LCD_count; 
void hex_convert(void) 
{ 
	LCD_write_shu(2,2,0);                             //0 
	LCD_write_shu(3,2,33);                            //x 
	LCD_write_shu(4,2,((convert_DATA.S[1]>>4)&0x0f)); //高4位 
	LCD_write_shu(5,2,(convert_DATA.S[1]&0x0f));           //低4位 
	LCD_write_shu(6,2,((convert_DATA.S[2]>>4)&0x0f)); //高4位 
	LCD_write_shu(7,2,(convert_DATA.S[2]&0x0f));           //低4位 
	LCD_write_shu(8,2,((convert_DATA.S[3]>>4)&0x0f)); //高4位 
	LCD_write_shu(9,2,(convert_DATA.S[3]&0x0f));           //低4位 
 
} 
 
void delay50ms(void) 
{ 
    unsigned char i,j,k; 
    for(i=165;i>0;i--) 
    for(j=60;j>0;j--) 
    for(k=1;k>0;k--); 
} 
 
//排序采用冒泡法 
 
 
long filter() 
{ 
        long value_buf[N],temp,value_temp; 
        char count,i,j; 
        for ( count=0;count<N;count++) 
        { 
                value_buf[count] = ReadAD();  //获取AD转换值 
              delay50ms();delay50ms(); 
        } 
        for (j=0;j<N-1;j++) 
        { 
                for (i=0;i<N-j;i++) 
                { 
                        if ( value_temp>value_buf[i+1] ) 
                        { 
                                temp = value_temp; 
                                value_temp = value_buf[i+1];  
                                value_buf[i+1] = temp; 
                        } 
                } 
        } 
return value_buf[(N-1)/2];				   //返回滤波之后的AD值 
}  
		 
void main(void) 
{	 
	LCD_clear(); 
	LCD_init();														   //LCD初始化 
    zero_data.S[0]=HW_ReadIAPByte(eeprom_address); 
	zero_data.S[1] = HW_ReadIAPByte(eeprom_address+1);		            	    
	LCD_write_shu(5,0,24); 
 
	while(1)				 
	{ 
 
	LCD_count = zero_data.all; 
	LCD_write_shu(1,4,LCD_count/10000); 
	LCD_write_shu(2,4,LCD_count%10000/1000); 
	LCD_write_shu(3,4,LCD_count%1000/100); 
	LCD_write_shu(4,4,45); 
 	LCD_write_shu(5,4,LCD_count%100/10); //行驶时 
   	LCD_write_shu(6,4,LCD_count%10); 
	if(zero_key==0) 
	{ 
		delay50ms(); 
		if(zero_key==0) 
		{ 
 
		zero_data.all=12345; 
		HW_EraseIAPSector(eeprom_address); 
		HW_WriteIAPByte(eeprom_address, zero_data.S[0]); 
		HW_WriteIAPByte(eeprom_address+1, zero_data.S[1]); 
		} 
 
		P0=0X00;  
		while(zero_key==0); 
		P0=0XFF; 
 
	} 

//    delay50ms();	 
							   
 
	} 
 
 
}