milan.rajik
Banned
- Joined
- Apr 1, 2013
- Messages
- 2,524
- Helped
- 540
- Reputation
- 1,078
- Reaction score
- 524
- Trophy points
- 1,393
- Activity points
- 0
Is it ok if I give you mikroC code. Can you port it to CodeVisionAVR code ?
- - - Updated - - -
I have not tested this code. You have to initially write 0 to eeprom address 0x01 and 0x02. Adjust Trial Limit duration by changing
value.
There should be power for 24 hours and only then the day is counted. Can be modified so that minutes and hours values are written to eeprom and from this day value can be calculated.
This is how I do in my projects.
- - - Updated - - -
I have not tested this code. You have to initially write 0 to eeprom address 0x01 and 0x02. Adjust Trial Limit duration by changing
Code:
#define TRIAL_LIMIT
There should be power for 24 hours and only then the day is counted. Can be modified so that minutes and hours values are written to eeprom and from this day value can be calculated.
This is how I do in my projects.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 char halfSec = 0, sec = 0, minutes = 0, hours = 0; unsigned int days = 0; #define TRIAL_LIMIT 180 //Timer1 Prescaler = 64; Preload = 31249; Actual Interrupt Time = 500 ms //Place/Copy this part in declaration section void InitTimer1() { SREG_I_bit = 1; TCCR1A = 0x80; TCCR1B = 0x0B; OCR1AH = 0x7A; OCR1AL = 0x11; OCIE1A_bit = 1; } void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA { //Enter your code here if(++halfSec == 2) { if(++sec == 60) { if(++minutes == 60) { if(++hours == 24) { ++days; EEPROM_Write(0x01, days); EEPROM_Write(0x02, (days >> 8)); } minutes = 0; } sec = 0; } halfSec = 0; } } void main() { DDRB = 0b00111111; DDRC = 0xFF; DDRD = 0xFF; days = EEPROM_Read(0x02); days <<= 8; Delay_ms(20); days |= EEPROM_Read(0x01); Delay_ms(20); InitTimer1(); while(1) { if(days < TRIAL_LIMIT) { PORTB.B0 = !PORTB.B0; Delay_ms(500); } } }