here's my program
Quote:
|
#include <p18f4520.h> #include <delays.h> void Init_LCD(void); //initialize the lcd void W_ctr_8bit(char); //8 bit control word for lcd void W_data_8bit(char); //8 bit text data for lcd void time(void); //time display format void switchprogram(void); //program for switches void 7segment(void); int h = 0; //initialize hour int m = 0; //initialize minute int s = 0; //initialize seconds int loop = 1; //for counting through looping int 7segnumber = 0; //initialize 7seg number int fifteen = 0; //individual loops for timing int five = 0; int ten = 0; int twenty = 0; char counting[9] = "COUNTING"; char count; void main() { ADCON1 = 0x0F; //set to digital TRISC = 0; //set PORTD as output TRISB = 0b00111000; //set PORTB as output TRISD = 0; //set PORTC as output TRISA = 0b11100000; TRISE=0b11111111; PORTC = 0b11111111;//turn off 7 segment, use 1 to off (com anode) PORTAbits.RA0 = 0; //turn off LED's initially PORTAbits.RA1 = 0; PORTAbits.RA2 = 0; PORTAbits.RA3 = 0; for(loop!=0;loop++) { time(); W_ctr_8bit(0b00000111); W_data_8bit(count); s++; if(s==60) { m++; s = 0; } switchprogram(); 7segment(); Delay10KTCYx(50); //1 second count } } //main program ends here void time() { for(h>=10) //displays a 0 in front when the hour number is single { count = "0"+h+":"+m; } for(m>=10) //displays a 0 in front when the minute number is single { count = +h+":0"+m; } for(h>=10&&m>=10) //displays a 0 in front of both when both numbers are single { count = "0"+h+":0"+m; } for(m>=60) //changes 60minutes into 1 hour { h++; m = 0; } } void Init_LCD() { W_ctr_8bit(0b00111100); //function set 8 bit 2 lines W_ctr_8bit(0b00001100); //display on cursor on W_ctr_8bit(0b00000110); //entry mode - inc addr, no shift W_ctr_8bit(0b00000001); //clear display and home position W_ctr_8bit(0x02); } void W_ctr_8bit(char x) { LCD_RS = 0; LCD_E = 1; LCD_DATA = x; LCD_E = 0; Delay_1kcyc(); } void W_data_8bit(char x) { LCD_RS = 1; LCD_E = 1; LCD_DATA = x; LCD_E = 0; Delay_1kcyc(); } void switchprogram() { if(PORTAbits.RA5==0) //sw1 for 15min count { 7segnumber++; for(fifteen==0;fifteen<900;fifteen++) //looping for 15mins { if(fifteen==900) { 7segnumber--; PORTAbits.RA4=1; //sounds buzzer PORTAbits.RA0=1; //activates led PORTAbits.RA1=1; PORTAbits.RA2=1; PORTAbits.RA3=1; fifteen = 0; Delay100TCYx(5); break; } } } if(PORTEbits.RE0==0) //sw3 for 5min count { 7segnumber++; for(five==0;five<300;five++) //looping for 5mins { if(five==300) { 7segnumber--; PORTAbits.RA4=1; //sounds buzzer PORTAbits.RA0=1; //activates led PORTAbits.RA1=1; PORTAbits.RA2=1; PORTAbits.RA3=1; five = 0; Delay100TCYx(5); break; } } } if(PORTEbits.RE1==0) //sw2 for 10min count { 7segnumber++; for(ten==0;ten<600;ten++) //looping for 10mins { if(ten==600) { 7segnumber--; PORTAbits.RA4=1; //sounds buzzer PORTAbits.RA0=1; //activates led PORTAbits.RA1=1; PORTAbits.RA2=1; PORTAbits.RA3=1; ten = 0; Delay100TCYx(5); break; } } } if(PORTEbits.RE2==0) //sw4 for 20min count { 7segnumber++; for(twenty==0;twenty<1200;twenty++) //looping for 20mins { if(twenty==1200) { 7segnumber--; PORTAbits.RA4=1; //sounds buzzer PORTAbits.RA0=1; //activates led PORTAbits.RA1=1; PORTAbits.RA2=1; PORTAbits.RA3=1; twenty = 0; Delay100TCYx(5); break; } } } } void 7segment(); { switch(7segnumber) { case 0 : PORTC = 0b01111111; break; // logic '0' to turn on the 7 segment. a is at the right, g is at the left starting from the second one. PORTC = 0b0gfedcba; case 1 : PORTC = 0b01111001; break; case 2 : PORTC = 0b00100100; break; case 3 : PORTC = 0b00110000; break; case 4 : PORTC = 0b00011001; break; } } |





Linear Mode
21 OCZ Fans!