Code C - [expand] 1 void main() { ... }
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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 int switch_val=0,menu_val=0,enter_noft=0,menu_noft=0,comand=0,comand_noft=0; //int right_noft=0,left_noft=0; int temp,i; int to_main_menu=0,enable_entry=0,disp_refresh=0; int all_menu_val[8]={100,110,111,120,121,200,210,220}; //All possible menu values int date_time[7]={00,00,00,00,00,00,00}; char all_menu_char[6][10]={"Date/Time","Time ","Shedule ","Shedule 1","Shedule 2","N / A "};//,"Date","Time","Shedule","Schedule 1","Schedule 2","N / A"}; //char menu_time[5][10]={"12 Hrs","24 Hrs", "Time:"}; char name; //char menu_root[5][10]={"","Time","Date","Schedules"}; //char menu_date[15]={"Today's Date"}; //char menu_sche[2][15]={"Schedule : 1","Schedule : 2 "}; //......Functions......//// void display(int,int, int ); void display_menu(int); void switch_val_processing(int); void read_ds1307(void); void rd_date_time(void); //for reading the date from the RTC void wr_date_time(void); //for writing the date from the RTC int check_menu_val(int); //void process_keypress(void); //void menu_sel(void); // Lcd pinout settings sbit LCD_D4 at RC0_bit; sbit LCD_D5 at RC5_bit; sbit LCD_D6 at RC4_bit; sbit LCD_D7 at RC3_bit; sbit LCD_RS at RC2_bit; sbit LCD_EN at RC1_bit; // Pin direction sbit LCD_D4_Direction at TRISC0_bit; sbit LCD_D5_Direction at TRISC5_bit; sbit LCD_D6_Direction at TRISC4_bit; sbit LCD_D7_Direction at TRISC3_bit; sbit LCD_RS_Direction at TRISC2_bit; sbit LCD_EN_Direction at TRISC1_bit; //----Buttons configurations----// sbit but_menu at RA3_bit; sbit but_left at RA2_bit; sbit but_right at RA1_bit; sbit but_enter at RA0_bit; //sbit but_intr_flag at intcon.----_bit; //sbit but_intr_clear at ----_bit; //sbit enable at comand.b2; void initialize() { option_reg=0b01001111; intcon=0b11001000; //----disable non used interrupts----// pie1=0x0; pie2=0x0; pie3=0x0; pie4=0x0; //----Enabling negative edge sensing on A0->A3----// IOCAP=0x0; IOCAN=0b00001111; //Positive to negative egde detection on A0 --> A3 IOCAF=0x0; IOCBP=0X0; IOCBN=0X0; IOCBF=0X0; //read date and time to the date_time Variable -------------------- lcd_init(); } void interrupt(void) { delay_ms(10); if(intcon.IOCIF==1) { disp_refresh=1; if(but_menu==1 &&iocan==0b00001000) { switch_val=1; //return(1); } if(menu_val!=0) { if(but_left==1 && iocan==0b00000100) { switch_val=2; //return(2); } if(but_right==1 && iocan==0b00000010) { switch_val=3; //return(3) } if(but_enter==1 && iocan==0b00000001) { switch_val=4; //return(4); } if(but_menu==0 && but_left==0) { switch_val=5; //return(5); } } intcon.iocif=0; } } void main() { initialize(); lcd_out(1,1,"Starting....."); delay_ms(500); lcd_cmd(_lcd_clear); Lcd_cmd(_lcd_cursor_off); while(1) { if(disp_refresh==1) { switch_val_processing(switch_val); display_menu(menu_val); /*lcd_out(2,1,"S_V");*/display(0,0,switch_val); /*lcd_out(2,7,"M_V");*/display(0,0,menu_val); delay_ms(1000); } } } int read_year() { //start_i2c(); //wr_i2c(209); //wr_i2c(0x00); //date= } void read_ds1307(void) { //wr_single_i2c(int 208,int 7,int 16); } void switch_val_processing(int switch_number) { int x,present=0; //----Menu Button Pressed---- if(switch_number==1) { int temp_100=menu_val%100,temp_10=menu_val%10; comand_noft=0; //this will exit the screen even if enter is pressed if(enable_entry==1) { menu_val=100; menu_noft=1; } if(to_main_menu==1) { to_main_menu=0; } if(Enter_noft==1) { menu_val=-temp_100; menu_noft++; enter_noft--; to_main_menu=1; } if(Enter_noft==2) { menu_val=-temp_10; menu_noft++; enter_noft--; } if(to_main_menu==0) { menu_val=0; menu_noft=1; enable_entry=1; } switch_val=0; } //----Left Button pressed---- if(switch_number==2) { int x; if(enter_noft==2) { x=menu_val-1; } if(enter_noft==1) { x=menu_val-10; } for(i=0;i<(sizeof(all_menu_val)/2);i++) { if(x==all_menu_val[i]) { present=1; } } (present==1)? (menu_val=x):(comand=2); switch_val=0; } if(switch_number==3) { int x; if(enter_noft==2) { x=menu_val-1; } if(enter_noft==1) { x=menu_val-10; } for(i=0;i<(sizeof(all_menu_val)/2);i++) { if(x==all_menu_val[i]) { present=1; } } (present==1)? (menu_val=x):(comand=3); switch_val=0; } if(switch_number==4) { int x; enter_noft++; if(enter_noft==2) { x=menu_val-1; } if(enter_noft==1) { x=menu_val-10; } for(i=0;i<(sizeof(all_menu_val)/2);i++) { if(x==all_menu_val[i]) { present=1; } } (present==1)? (menu_val=x):(comand=4); switch_val=0; } } int check_menu_val(int check_num) { int i; for(i=0;i<(sizeof(all_menu_val)/2);i++) { if(check_num==all_menu_val[i]) { return(1);break; } } } //char all_menu_char[6][10]={"Date/Time","Time ","Shedules ","Shedule 1","Shedule 2","N / A "}; void display_menu(int value) { int i; lcd_cmd(_lcd_cursor_off); switch(value) { case(100): { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[0]); break; } case(110): { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[0]); lcd_out(1,5," "); break; } case(111): { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[0]); lcd_out(1,5," "); lcd_out_cp("(Press Enter / Change)"); delay_ms(200); for(i=0;i<11;i++) { lcd_cmd(_lcd_shift_left); delay_ms(200); } lcd_cmd(_lcd_return_home); delay_ms(1000); break; } case(120): { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[1]); break; } case(121): { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[1]); lcd_out(1,5," "); lcd_out_cp("(Press Enter / Change)"); for(i=0;i<11;i++) { lcd_cmd(_lcd_shift_left); delay_ms(200); } lcd_cmd(_lcd_return_home); delay_ms(1000); break; } case(200): { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[2]); Lcd_out_cp(" "); break; } case(210): { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[3]); break; } case(220): { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[4]); break; } default: { lcd_cmd(_lcd_clear); Lcd_out(1,1,all_menu_char[5]); break; } } disp_refresh=0; } void display(int row,int col, int temp_int) { char temp_char[7]; inttostr(temp_int,temp_char); ltrim(temp_char); if(row!=0&&col!=0) { lcd_out(row,col, temp_char); } if(row==0&&col==0) { lcd_out_cp(temp_char); lcd_out_cp(" "); } } /*// returns the value of the switch pressed { disp_refresh=1; if(but_menu==0) { switch_val=1; //return(1); } if(menu_val!=0) { if(but_left==0) { switch_val=2; //return(2); } if(but_right==0) { switch_val=3; //return(3) } if(but_enter==0) { switch_val=4; //return(4); } if(but_menu==0 && but_left==0) { switch_val=5; //return(5); } } }*/
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?