Jay23
Newbie level 6
I have build a 30 min,3 hours and 8 hours timer with PIC16F628A chip.
Mine should work like this:
3 tact switches:
30 min, 3 hr, 8 hr switch.
When I press 30 min : the counter loads this value into the counter and starts counting down when the Start/Stop button is pressed.
Similar function when the 3 hour or the 8 hour switch button is pressed.
A LCD display is connected and the value of the pressed switch is displayed on the display.
The code is added here below:
This is to set a value from 1 -99 minutes with the 2 switches: 0-1 or 10-99.
Then the counter starts counting down.
I want to preset the counter with the value of 30 minutes or 3 hours or 8 hours by pressing the respective tact switch.
Has someone some idea how to fix this?
//regards, Jay
==========================================================================
Mine should work like this:
3 tact switches:
30 min, 3 hr, 8 hr switch.
When I press 30 min : the counter loads this value into the counter and starts counting down when the Start/Stop button is pressed.
Similar function when the 3 hour or the 8 hour switch button is pressed.
A LCD display is connected and the value of the pressed switch is displayed on the display.
The code is added here below:
This is to set a value from 1 -99 minutes with the 2 switches: 0-1 or 10-99.
Then the counter starts counting down.
I want to preset the counter with the value of 30 minutes or 3 hours or 8 hours by pressing the respective tact switch.
Has someone some idea how to fix this?
//regards, Jay
==========================================================================
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 // LCD DISPLAY module connections sbit LCD_RS at RA0_bit; sbit LCD_EN at RA1_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISA0_bit; sbit LCD_EN_Direction at TRISA1_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections // Tact switches sbit SS_Select at RB1_bit; // Start Stop Timer Select sbit Unit_Button at RB2_bit; // Set unit min sbit Ten_Button at RB3_bit; // Set ten min sbit Eighthr_Button at RB0_bit; // Set 8hr //Relays and Buzzer //sbit Relay1 at RB0_bit; //sbit Relay2 at RB0_bit; //sbit Relay3 at RB0_bit; sbit SND at RA7_bit; // LEDs sbit Led_RED at RA6_bit; sbit Led_GREEN at RA3_bit; sbit Led_YELLOW at RA4_bit; // Messages char Message1[]="30min-8hr: Timer"; char Message2[]="Timer ON"; char Message3[]="Timer OFF"; char Message4[]="Set Time: min"; char Message5[]="Time Left: min"; unsigned short i, j, unit=0, ten=0, ON_OFF=0, index=0, clear, time; char *digit = "00"; // 300ms Delay void Delay_300(){ Delay_ms(300); } void Display_Digits(){ digit[1]=unit+48; digit[0]=ten+48; Lcd_Out(2,11,digit); } void play_sound(){ Sound_Play(2500, 500); } void debounce(){ Delay_ms(250); } void start_timer(unsigned short MinVal){ unsigned short temp1, temp2; //Led_RED = 0; //Led_GREEN = 0; //Led_YELLOW = 0; //Relay1 = 1; play_sound(); ON_OFF = 1; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,Message2); Lcd_Out(2,1,Message5); OPTION_REG = 0x80 ; INTCON = 0x90; for (i=0; i<MinVal; i++){ temp1 = (MinVal-i)%10 ; temp2 = (MinVal-i)/10 ; Lcd_Chr(2, 12, temp2+48); Lcd_Chr(2, 13, temp1+48); j=1; do { Delay_ms(1000); j++; } while(((j<=60) && (Clear ==0))); if (Clear) { //Relay1 = 0; Delay_ms(500); Lcd_Out(1,1,Message3); INTCON = 0x00; goto stop; } } stop: //Relay1 = 0; Led_RED = 0; Led_GREEN = 0; Led_YELLOW = 0; ON_OFF = 0; unit = 0; ten = 0; clear = 1; play_sound(); } void interrupt(void){ if (INTCON.INTF == 1) // Check if INTF flag is set { Clear = 1; INTCON.INTF = 0; // Clear interrupt flag before exiting ISR } } void main() { CMCON |= 7; // Disable Comparators //TRISB = 0b00001111; TRISB = 0b01111111; //TRISA = 0b11110000; TRISA = 0b11000000; //Relay1 = 0; Sound_Init(&PORTB,0); // Initialize Buzzer o/p pin Lcd_Init(); // Initialize LCD start: clear = 0; Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,Message1); Lcd_Out(2,1,Message4); Display_Digits() ; do { if(!Unit_Button){ Delay_300(); unit ++; if(unit==10) unit=0; Display_Digits(); } // If !Unit_Button if(!Ten_Button){ Delay_300(); ten ++; if(ten==10) ten=0; Display_Digits(); } // If !Ten_Button if(!SS_Select){ Delay_300(); Led_RED = 1; time = ten*10+unit ; if(time > 0) start_timer(time); } // If !SS_Select if(clear){ goto start; } } while(1); }