poxkix
Member level 5
I constructed 4 timer circuits which will countdown from 60 minutes to 0.
They are controlled individually by a single PIC18F4620. The timers will time/function at different times depending which timer would I want to start to countdown. The timers default time is 0.
I was thinking, is their another way to make the 4 timers to just 1? Still with the same functionality.
code:
They are controlled individually by a single PIC18F4620. The timers will time/function at different times depending which timer would I want to start to countdown. The timers default time is 0.
I was thinking, is their another way to make the 4 timers to just 1? Still with the same functionality.
code:
Code:
unsigned short cnt = 0;
unsigned short minute = 0;
unsigned short second = 0;
unsigned short count = 0;
unsigned short cnt_pressed = 0;
unsigned short holder = 10;
unsigned short temp = 0;
void increment();
void decrement();
void interrupt () {
if (INTCON.INTF == 1) {
INTCON.INTF = 0;
increment();
INTCON.T0IE = 1;
temp = 1;
}
if (INTCON.T0IF == 1) {
TMR0 = 0;
INTCON.T0IF = 0;
cnt++;
portb.f3 = 1;
temp = 1;
if (cnt == 0x0F) { // 15 time trigger for 1 second
second++;
cnt = 0;
temp = 0;
if (second == 0x3C) { // seconds
decrement();
second = 0;
if (minute == 0x00) { // minutes
INTCON.T0IE = 0;
if(second == 0 && minute == 0) {
portb.f3 = 0;
}
}
}
}
}
}
void initMain() {
TRISA = 0x00;
TRISB = 0x03;
porta = 0;
portb = 0;
}
void initInterrupt() {
TMR0 = 0;
INTCON.GIE = 1;
INTCON.T0IF = 0;
INTCON.INTE = 1;
//INTCON.RBIE = 0;
INTCON.T0IE = 0;
//1 = Interrupt on rising edge of RB0/INT pin
//0 = Interrupt on falling edge of RB0/INT pin
OPTION_REG = 0x47; // option_reg 111 = 1 : 256
}
void subMain() {
while (1) {
if (temp == 0) {
portb.f2 = 0;
} else {
portb.f2 = 1;
}
}
}
void main () {
initMain();
initInterrupt();
subMain();
while(1) {
}
}
void increment() {
short x = 1;
for (;x <= 60; x ++) {
cnt_pressed = cnt_pressed + 1;
if (cnt_pressed == holder) {
minute+= 6;
cnt_pressed = 0;
porta = minute;
portb = minute;
}
portb.f2 = 1;
}
minute = minute + 60;
porta = minute;
portb = minute;
portb.f2 = 1;
}
void decrement() {
switch (minute) {
case 0x00: minute = 0xA0;
case 0x10:
case 0x20:
case 0x30:
case 0x40:
case 0x50:
case 0x60:
case 0x70:
case 0x80:
case 0x90: minute = minute - 7;
cnt_pressed = 9;
porta = minute;
portb = minute;
portb.f2 = 1; break;
default: minute = minute - 1;
cnt_pressed -= 1;
porta = minute;
portb = minute;
portb.f3 = 1;
portb.f2 = 1; break;
}
}