หัวข้อ: ช่วยหน่อยครับ ดูโค้ดให้หน่อยว่าทำไมมัน Error ตรงไหน เริ่มหัวข้อโดย: 04_EnE ที่ มกราคม 02, 2013, 07:34:27 am [Main]
#include<htc.h> #include "jpv.c" #include "lcd.c" #include "set1.c" extern void ic(); extern void lcd(); extern void md11(); void main() { RBPU=1; TRISB=0xff; TRISC=0x58; GIE=1; PEIE=1; RBIE=1; lcd(); ic(); while(1); } ***************************************************************************** #include<htc.h> #define ON 1; #define OFF 0; unsigned char k; unsigned char strALM[]={"ALM-HRALM-MN"}; unsigned char str456[]={"MNTH[0-12]TMRSTRHRSTRMINSTPHR STPMIN"}; unsigned char stap[]={"AMPM"}; unsigned char almFLG=OFF; unsigned char tmF=OFF; unsigned char s32=0x00; unsigned int alhr=0x00,thr1=0x00,thr2=0x00; unsigned int almn=0x00,tmn1=0x00,tmn2=0x00; void start(); void ack(); void write(unsigned char); void stop(); void restart(); void noack(); void masterack(); void bcd2ascii(unsigned char); void read(); extern void data(unsigned char); extern void init(); extern void buttons(); extern void comm(unsigned char); //extern void setting(); unsigned char second=0x00; unsigned char minute; unsigned char hour=0x00; unsigned char day; unsigned char date; unsigned char month; unsigned char year; unsigned char recv_data; unsigned int count,count1; unsigned int d1,d2; unsigned int thour; unsigned char tminute; unsigned char tsecond=0; unsigned char tdate; unsigned char tmonth; unsigned char tyear; unsigned char tday; unsigned char dayy[7][3]={'S','U','N', 'M','O','N', 'T','U','E', 'W','E','D', 'T','H','U', 'F','R','I', 'S','A','T'}; unsigned char monnt[12][3]={'J','A','N', 'F','E','B', 'M','A','R', 'A','P','R', 'M','A','Y', 'J','U','N', 'J','U','L', 'A','U','G', 'S','E','P', 'O','C','T', 'N','O','V', 'D','E','C'}; void led(); //unsigned char globwhlcntl=0; void ic() { SSPCON=0x28; SSPADD=0x09; TRISC=0x58; /////////////////////////////////reading from device ///////////////////////////////////////////////////////////////////////////////////// while(1) { comm(0xc6);data(':'); comm(0xc6);data(':'); comm(0xc6);data(':'); comm(0xc6);data(':'); comm(0xc6);data(':'); comm(0xc6);data(':'); start(); write(0xd0); ack(); write(0x00); ack(); restart(); write(0xd1); ack(); read(); second=recv_data; masterack(); read(); minute=recv_data; masterack(); read(); hour=recv_data; masterack(); read(); day=recv_data; masterack(); read(); date=recv_data; masterack(); read(); month=recv_data; masterack(); read(); year=recv_data; noack(); stop(); thour=hour; if(thour<0x13) { comm(0xce); for(k=0;k<=1;k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// data(stap[k]); } } else { comm(0xce); for(k=2;stap[k]!='\0';k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// data(stap[k]); } } comm(0xc3); if(hour==0x13) { hour=0x01; } if(hour==0x14) { hour=0x02; } if(hour==0x15) { hour=0x03; } if(hour==0x16) { hour=0x04; } if(hour==0x17) { hour=0x05; } if(hour==0x18) { hour=0x06; } if(hour==0x19) { hour=0x07; } if(hour==0x20) { hour=0x08; } if(hour==0x21) { hour=0x09; } if(hour==0x22) { hour=0x10; } if(hour==0x23) { hour=0x11; } if(hour==0x00) { hour=0x12; } bcd2ascii(hour); comm(0xc7); bcd2ascii(minute); data(' '); data(' '); bcd2ascii(second); if(almFLG==1) ///// alarm indication......... ...... {comm(0x8e); data(''); // <-----------@jpv[jijesh.p.v] ----------> } if(tmF==1) {comm(0x8f); /// timer indication ................... .............. data('*'); } comm(0x8a); //////////////day -> displaying sun=1,mon=2... if(day==0) d2=0; if(day==1) d2=1; if(day==2) d2=2; if(day==3) d2=3; if(day==4) d2=4; if(day==5) d2=5; if(day==6) d2=6; for(d1=0;d1<=2;d1++) { data(dayy[d2][d1]); }///////////////////////////////////////////////////////////// comm(0x80); bcd2ascii(date); data(' '); ////////////////////////////////// if(month==1) d2=0; if(month==2) d2=1; if(month==3) d2=2; if(month==4) d2=3; if(month==5) d2=4; if(month==6) d2=5; if(month==7) d2=6; if(month==8) d2=7; if(month==9) d2=8; if(month==10) d2=9; if(month==11) d2=10; if(month==12) d2=11; for(d1=0;d1<=2;d1++) { //bcd2ascii(month);////////////////month ->0-jan.. data(monnt[d2][d1]); } ////////////////////////////////////////////// data(' '); bcd2ascii(year); RBIE=1; // -> EN/REN PB INTERRUPT //buttons(); for(count=0;count<=200;count++) for(count1=1;count1<=1;count1++); tminute=minute; tdate=date; tmonth=month; tyear=year; tday=day; if(almFLG==0x01) ///if aLARM IS on then,...... @jpv {if(thour==alhr) {if(tminute==almn) { RC7=1; for(count=0;count<=2000;count++) for(count1=1;count1<=1;count1++); init(); for(k=0;k<=2;k++) ///////////////////************************************* { data(strALM[k]); } if(RB6==1) { almFLG=0x00; almFLG=0x00; while(RB6==1); RC7=0; } init(); }}} if(tmF==0x01) { if(tmn1==tminute) {if(thr1==thour) {RC7=1; ///RELAY CONNECTED ENABLED........ }} if(thr2==thour) {if(tmn2==tminute) {RC7=0;} ///RELAY CONNECTED }} comm(0xc6);data(' '); comm(0xc6);data(' '); comm(0xc6);data(' '); comm(0xc6);data(' '); } } void start() { SEN=1; while(SEN); } void masterack() { ACKDT=0; ACKEN=1; } void ack() { while(ACKSTAT==1); //ack receiving.......... ................... ................... ................... .. } void write(unsigned char recv) { SSPBUF=recv; while(RW==1); } void noack() { ACKDT=1; ACKEN=1; } void restart() { RSEN=1; while(RSEN==1); } void stop() { PEN=1; while(PEN); } void read() { RCEN=1; if(SSPOV==0)/////////////////IF NO ERROR { while(RCEN==1); recv_data=SSPBUF; } } void bcd2ascii(unsigned char recv) { unsigned char temp=recv; temp=temp&0xf0; temp=temp>>4; temp=temp+0x30; data(temp); temp=recv; temp=temp&0x0f; temp=temp+0x30; data(temp); } void led() { /////////////////////////////////led blink writing to rtc///////////////////////////////////////////////// SSPCON=0x28; SSPADD=0x09; start(); write(0xd0); // device initialize ack(); write(0x07); //starting addr regr ack(); write(0x10); ack(); stop(); } #include<htc.h> unsigned int thour; unsigned int cthour; unsigned int mdd=0,k1; unsigned char tminute; unsigned char ctminute; unsigned int tpoint; unsigned char tdate; unsigned char ctdate; unsigned char tmonth; unsigned char ctmonth; unsigned char tyear; unsigned char ctyear,ctday; unsigned char sss=0; //////locking variables.......... ................... .. unsigned int temp; unsigned int max,min; unsigned char stry[]={"SET HOUR[0-23]"}; // info data of hr set unsigned char strz[]={"MIN[0-59]"}; // ,, ,, mnt set unsigned char str123[]={"DATE"}; // ,, ,, date set // ,, ,,year set //unsigned char str4[]={"TMRSTARTSTOP"}; unsigned char str789[]={"YEAR-2000-99"}; // ,, ,,day set unsigned char str1011[]={"DAY 0-SUN"}; //unsigned char strALM[]={"ALM-HR ALM-MN"}; //unsigned char sta1[]={"SET ALM-HOUR"}; //unsigned char sta2[]={"SET ALM-MIN"}; unsigned char stt1[]={"OFFON "}; void b2a(unsigned char); #define md RB4 #define lt RB5 #define pt RB6 #define in RB7 unsigned int incr1(unsigned int); unsigned int decr1(unsigned int); void md11(); void lt11(); void pntr11(); void stop123(); void start123(); void ack123(); void write123(unsigned char recv); void noack123(); void restart123(); //extern void init(); void intcame(); unsigned int count=0; unsigned int count1=0; void hrset(); unsigned char llock=0; unsigned int sw; void alarm2(); void tmdtst(); //unsigned char mdswtch=0; void interrupt ooo(void)///////////////////////////////ISR OF PORTB INTERRUPT { sw=PORTB; //read PORTB NOW OTHERWISE VALUE WILL CHANGE if(RBIF==1) // chkng whether interrupt occurd/not-------------------------------------->@jpv { for(count=0;count<=2000;count++) // A small Delay for(count1=1;count1<=100;count1++); // ,, ,, intcame(); RC7=1; for(count=0;count<=2000;count++) // ,, ,, for(count1=1;count1<=100;count1++); RC7=0; RBIF=0; // clearing PORTB interrupt flag......... } RBIE=0; // Enabling PORTB interrupt......... }///////////////////////////////////////////////////////////////////////////////////////////////// void intcame() { switch(sw) { case 0x10: //CHKNG WHETEHER THE MODE SWITCH BUTTON IS PRESSED ..................I F YES JUMP TO func:md11(); md11(); break; default: break; }; } void md11() ///mode settingssss { //////////////////////// mdd=0; cthour=thour; //thour,tmin.,tdate.,tmon.,tyear is used in jpv.c and loads a copy of the rtc time ctminute=tminute; // ,, ctdate=tdate; //,, ctmonth=tmonth; //,, ctyear=tyear; // ,, ctday=tday; // ,, sss=0; //,sss1=0,sss2=0,sss3=0,sss4=0; ////////////locking variables for lcd clear ////////////////////////////lcd clear.............. ............. lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////////////////////// /*////////////////lcd starting C0 loc///2ND LINE SEL lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay11(2000);RC2=0;///////////////////////////////////////////////////////////// */ while(sw==0x10) /////////////////MODE SWITCH PRESSED............ .. { ////////////////lcd starting C0 loc///2ND LINE SEL ///////////////////////////////////////////////////////////// if(mdd==0) /////////////////////////////////////////setting hour mdd will increment when pntr pin is pressed { if(sss==0) { //////////////lcd clear lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////// ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=0;stry[k]!='\0';k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=stry[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////// max=0x24;// max hour .this is used in incr1 func: min=0x00; b2a(cthour); cthour=incr1(cthour);////////////////////////pass to func:incr1 for incrm. values cthour=decr1(cthour); } if(mdd==1)/////////////////////////////////////setting minute {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=0;strz[k]!='\0';k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=strz[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// max=0x60; /////max minute this is used in incr1 func min=0x00; b2a(ctminute); ctminute=incr1(ctminute);////////////////////////pass to func:incr1 for incrm. values ctminute=decr1(ctminute); } //////////////////////////////////////////////////////// 3RD MODE SETTING DATE........ if(mdd==2)/////////////////////////////////////setting date {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=0;str123[k]!='\0';k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str123[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; // lcd should be clear only once,......... } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// max=0x32; /////max day in a month .this is used in incr1 func min=0x01; b2a(ctdate); ctdate=incr1(ctdate);////////////////////////pass to func:incr1 for incrm. values ctdate=decr1(ctdate); } if(mdd==3)/////////////////////////////////////setting month {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=0;k<=9;k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str456[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; // lcd should be clear only once,......... } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// max=0x13; /////max day in a month .this is used in incr1 func min=0x01; b2a(ctmonth); ctmonth=incr1(ctmonth);////////////////////////pass to func:incr1 for incrm. values ctmonth=decr1(ctmonth); } ////// if(mdd==4)/////////////////////////////////////setting year {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=0;str789[k]!='\0';k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str789[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; // lcd should be clear only once,......... } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// max=0x99; /////max day in a month .this is used in incr1 func min=0x00; b2a(ctyear); ctyear=incr1(ctyear);////////////////////////pass to func:incr1 for incrm. values ctyear=decr1(ctyear); } if(mdd==5)/////////////////////////////////////setting day.....0-sun 1-mon 2-tues.............7-sat {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=0;str1011[k]!='\0';k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str1011[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; // lcd should be clear only once,......... } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// min=0x00; max=0x08; /////max day in a month .this is used in incr1 func b2a(ctday); ctday=incr1(ctday);////////////////////////pass to func:incr1 for incrm. values[inc. day ] ctday=decr1(ctday); } ////////////////////////////////////////////////////////TMRRRRRRRRRRRRRRRRRR START ///////// if(mdd==6)/////////////////////////////////////settingTIMER ON AND OFF {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=10;k<=12;k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str456[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; // lcd should be clear only once,......... } lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// if(RB7==1) { while(RB7==1); if(tmF==0x00) { tmF=0x01; } else tmF=0x00; } if(tmF==0) { //unsigned char k; for(k=0;k<=2;k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=stt1[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } //while(RB6==0); } else { for(k=3;stt1[k]!='\0';k++) ///////////////////************************************* { RC7=1; for(count=0;count<=200;count++); RC7=0; /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=stt1[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } } }////////end of this TIMER on/off mode............... .. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(mdd==7) /////////////////////////////////////////setting TIMER START hour { if(sss==0) {//////////////lcd clear lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////// ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=13;k<=17;k++) ///////////////////************************************* {/////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str456[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0;} sss++;} ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////// max=0x24;// max hour .this is used in incr1 func: min=0x00; b2a(thr1); thr1=incr1(thr1);////////////////////////pass to func:incr1 for incrm. values thr1=decr1(thr1); } if(mdd==8)/////////////////////////////////////setting TIMER START minute {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=18;k<=23;k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str456[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// max=0x60; /////max minute this is used in incr1 func min=0x00; b2a(tmn1); tmn1=incr1(tmn1);////////////////////////pass to func:incr1 for incrm. values tmn1=decr1(tmn1); } //////////////////////////////////////////////////////////////////TIMER STOPPPPPPPPPPPPPP if(mdd==9) /////////////////////////////////////////setting TIMER STOP hour {if(sss==0) {//////////////lcd clear lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////// ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=24;k<=28;k++) ///////////////////************************************* {/////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str456[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0;} sss++;} ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////// max=0x24;// max hour .this is used in incr1 func: min=0x00; b2a(thr2); thr2=incr1(thr2);////////////////////////pass to func:incr1 for incrm. values thr2=decr1(thr2); } if(mdd==10)/////////////////////////////////////setting TIMER STOP minute {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=29;k<=34;k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=str456[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// max=0x60; /////max minute this is used in incr1 func min=0x00; b2a(tmn2); tmn2=incr1(tmn2);////////////////////////pass to func:incr1 for incrm. values tmn2=decr1(tmn2); } //////////////////////////////////////////////////////////TMRRRRRRRRRRRRRRRRRRRR END ////////////////////////////ALARM SARIKAL if(mdd==11)/////////////////////////////////////ALM ON/OFF {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=0;k<=2;k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=strALM[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; // lcd should be clear only once,......... } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// min=0x00; max=0x08; /////max day in a month .this is used in incr1 func //b2a(ctday); if(RB7==1) { while(RB7==1); //almFLG=~almFLG; if(almFLG==0x00) { almFLG=0x01; } else almFLG=0x00; } if(almFLG==0) { //unsigned char k; for(k=0;k<=2;k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=stt1[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } tpoint=0x0c; } else { //unsigned char k; for(k=3;stt1[k]!='\0';k++) ///////////////////************************************* { RC7=1; for(count=0;count<=200;count++); RC7=0; /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=stt1[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } tpoint=0x0e; } }////////end of this alarm on/off mode............... .. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if(mdd==12) /////////////////////////////////////////setting alarm hour {if(sss==0) {//////////////lcd clear lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////// ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=0;k<=5;k++) ///////////////////************************************* {/////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=strALM[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0;} sss++;} ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////// max=0x24;// max hour .this is used in incr1 func: min=0x00; b2a(alhr); alhr=incr1(alhr);////////////////////////pass to func:incr1 for incrm. values alhr=decr1(alhr); } if(mdd==13)/////////////////////////////////////setting ALARM minute {/////////////// ////////////////////////lcd clear.............. ............. if(sss==0) {lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ////////////////lcd starting 80 loc///1ST LINE SEL lcd_data=0x80;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; ///////////////////////////////////////////////////////////// //unsigned char k; for(k=6;strALM[k]!='\0';k++) ///////////////////************************************* { /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=strALM[k];RC0=1;RC1=0;RC2=1;delay1(2000);RC2=0; } sss++; } ///////// lcd_data=0xC4;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; /////////////// max=0x60; /////max minute this is used in incr1 func min=0x00; b2a(almn); almn=incr1(almn);////////////////////////pass to func:incr1 for incrm. values almn=decr1(almn); } ///////////////////////////////////////////ADTH BLOCK.............. ................... ................... ................... .............. pntr11() ; //chk whether the pointer is pressed, if yes do that spfc func: for(count=0;count<=2000;count++) //////////////////////some delay.............. .......... for(count1=1;count1<=5;count1++); /////////////////////// ,, ,, ///////////////////// ////////////unlocking while loop if(RB4==1) { while(RB4==1); sw=0x00; lcd_data=0x01;RC0=0;RC1=0;RC2=1;delay1(2000);RC2=0; //clear the lcd screen /////////// /////////////////////////writing back the changed settings..... above in while loop............. noack123(); stop123(); start123(); write123(0xd0); // device initialize ack123();//@#$#@$@#^$%^#$%&$%^&*$^&*%^&*$%^&$@#$!@!#!@$#!@$@!#$@#$@#%@#%@#%#@%; write123(0x00); //starting addr regr@!#!@##%$#$%#$$%^%^&*%$^&*(%^&*%^&*%^& ack123(); write123(0x00); ack123(); write123(ctminute); ack123(); write123(cthour); ack123(); write123(ctday); ack123(); write123(ctdate); ack123(); write123(ctmonth); ack123(); write123(ctyear); ack123(); stop123(); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } unsigned int incr1(unsigned int pnn)// for incrementing current pointing values..........@jpv[] { if(RB7==1) {for( count=0;count<=200;count++) for( count1=0;count1<=1;count1++); while(RB7==1); pnn=pnn++; temp=pnn&0x0f; if(temp==0X0A)//////////////if hr >19 it will go to 0x1a so chk this. {pnn=pnn&0xf0;pnn=pnn+0x10;} if(pnn==max)//////////////////////// if hr>23 we hove to reset to 00; {pnn=0x00;}} return pnn; } ///////////////////////////////////////////////////KURAKAN........ unsigned int decr1(unsigned int pnn)// for ,, current pointing values..........@jpv[] { if(RB5==1) {for( count=0;count<=200;count++) for( count1=0;count1<=1;count1++); while(RB5==1); if(pnn==min)//////////////////////// if hr>23 we hove to reset to 00; {pnn=max;} pnn=pnn--; temp=pnn&0x0f; if(temp==0X0f)////////////// {pnn=pnn&0xf0;pnn=pnn+0x09;} } return pnn; } ///////////// void alarm2() { } void tmdtst() { } void pntr11()//incrementing corresponding pointer pointing value { if(RB6==1) {while(RB6==1); sss=0; mdd=mdd+1;//////////////////////incrementing modes ........... if(mdd==tpoint)//////MAX MODES THAT WILL BE SHIFTED [-IF max. mode then we have to repeat from first mode] { sss=0; mdd=0;} if(mdd==7) { if(tmF==0x00) { mdd=11; } } }} /* /while(llock==0) { hrset(); if(li==1) {llock=1;; } } } void hrset() { // if(RA0=1) { for( count=0;count<=20;count++) for( count1=0;count1<=1;count1++); //if(ptr==0) { init(); thour=thour+1; comm(0xc0); data(0x30+thour); } } } */ void b2a(unsigned char recv) //bcd 2 ascii { temp=recv; temp=temp&0xf0; temp=temp>>4; temp=temp+0x30; /////////////////////////////////////data(temp); /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=temp; RC0=1; RC1=0; RC2=1; int i; for(i=0;i<2000;i++) for(i=0;i<2000;i++); RC2=0; //////////////////////////////////////////////////////////////////////////////////// temp=recv; temp=temp&0x0f; temp=temp+0x30; ///////////////////////////////////data(temp);/ /////////////////////////data displaying ///////////////////////////////////////////////// lcd_data=temp; RC2=1; int i; for(i=0;i<2000;i++) for(i=0;i<2000;i++); RC2=0; } //////////////rtc write elements////////////////////////////////////////////// void start123() { SEN=1; while(SEN); } void ack123() { while(ACKSTAT==1); //ack receiving.......... ................... ................... ................... .. } void write123(unsigned char recv) { SSPBUF=recv; while(RW==1); } void noack123() { ACKDT=1; ACKEN=1; } void restart123() { RSEN=1; while(RSEN==1); } void stop123() { PEN=1; while(PEN); } #include<htc.h> void init(); void comm(unsigned char); /////*********************************************************************************************** void data(unsigned char); void delay1(int ); void init1(); #define lcd_data PORTD unsigned char str[]={"Made by Jijesh.p.v "}; //(22/08/2011)-10:42-"};//******************************************************* void lcd() { int k; init(); ////////////////******************************************** for(k=0;str[k]!='\0';k++) ///////////////////************************************* { data(str[k]); } ///////////////////////////***************************** comm(0x1c); comm(0x1c); comm(0x1c); for(count=0;count<=2000;count++) for(count1=1;count1<=100;count1++);///^$%^$%^$^#$%^@$%@!#$!@#$%$%^$%^&$^&*%^&(%&*)^&*%^#$%@#$!@#$!@#$@#%@#$%@#$%@$%/////////// init(); ////************************************************************************************ } //********************************************************************************************************************************* void init() { TRISD=0x00; comm(0x38); delay1(2000); comm(0x0c); //nocursor delay1(2000); comm(0x01); delay1(2000); comm(0x06); delay1(2000); comm(0x80); delay1(2000); } void comm(unsigned char co) { lcd_data=co; RC0=0; RC1=0; RC2=1; delay1(2000); RC2=0; } void data(unsigned char da) { lcd_data=da; RC0=1; RC1=0; RC2=1; delay1(2000); RC2=0; } void delay1(int del) { int i; for(i=0;i<del;i++) for(i=0;i<del;i++); } |