#define Highest(param) ((char *)¶m)[3]
#define Higher(param) ((char *)¶m)[2]
#define Hi(param) ((char *)¶m)[1]
#define Lo(param) ((char *)¶m)[0]
unsigned short lowByte, highByte, higherByte, highestByte, p_address;
unsigned long pulses;
unsigned short lowByte, highByte, higherByte, highestByte, p_address;
unsigned char txt[14],txt6[14];
unsigned long count;
unsigned long pulses;
unsigned long total_consumption;
unsigned long current_consumption;
unsigned long monthly_consumption;
double Meter_reading;
double Meter_Constant = 0.001;
void EEPROMWriteInt(unsigned short p_address, unsigned long int p_value) {
lowByte = Lo(p_value); //((p_value >> 0) & 0xFF);
highByte = Hi(p_value); //((p_value >> 8) & 0xFF);
higherByte = Higher(p_value);
highestByte = Highest(p_value);
EEPROM_write(p_address, lowByte);
delay_ms(20);
EEPROM_write(p_address + 1, highByte);
delay_ms(20);
EEPROM_write(p_address + 2, higherByte);
delay_ms(20);
EEPROM_write(p_address + 3, highestByte);
delay_ms(20);
lowByte = 0x00;
highByte = 0x00;
higherByte = 0x00;
highestByte = 0x00;
}
unsigned long int EEPROMReadInt(unsigned short p_address)
{
Lo(pulses) = EEPROM_read(p_address);
delay_ms(20);
Hi(pulses) = EEPROM_read(p_address + 1);
delay_ms(20);
Higher(pulses) = EEPROM_read(p_address + 2);
delay_ms(20);
Highest(pulses) = EEPROM_read(p_address + 3);
delay_ms(20);
return pulses;
}
void main()
{
ANSEL = 0;
ANSELH = 0;
TRISA = 0;
PORTA.RA0 = 1;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0;
PORTB = 0;
PORTC = 0;
TRISC = 0x99;
INTCON = 0xC0;
PIE1.TMR1IE = 1;
PIR1.TMR1IF = 0;
T1CON = 0x03;
TMR1L = 0;
TMR1H = 0;
Lcd_Init();
Delay_ms(100); // Delay 100ms
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
pulses = (count*65536)+ (TMR1H<<8 | TMR1L);
pulses += EEPROMReadInt(0);
while(1){
pulses = (count*65536)+ (TMR1H<<8 | TMR1L);
Delay_ms(20);
EEPROMWriteInt(0x00, pulses);
LongToStr(pulses,txt);
Lcd_out(1,9,txt);
}
}