This is some code for my old protoboard version .1 i think. Im just posting it here for reference it has some good things like.
Real time clock
RX serial recieve interupt
Menu system via rx
password recogitition
pretty much all it did was keep time and beep, it was all the fluff that was hard. The whole project is attached as a HomeControl.zip
here is the main .c file
////////////////////////////////////////////////////// // Home Control Version 1.0 // A program to control my home via a pic 877 // or at least do the things im to lazy to do ;)~ // // By Mikel, http://www.zonemikel.com ///////////////////////////////////////////////////// #include <16F877.h> #device adc=8 #use delay(clock=4000000) #fuses NOWDT,HS,NOPUT,NOLVP #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) #include <string.h> // string stuff #include <stdlib.h> // for strtol etc #include <INPUT.C> // for get_string() // Defines #define XTal_FQ 4000000 #define T1_FQ (XTal_FQ/4) // 1 clock tick = 1 instr. // cycle = xtal freq / 4 // Global Variables int32 Ticker; // current Date/time will be here int8 Years=0, Months=0, Days=0, Hours=0, Minutes=0, Seconds=0; // is user connected ? int8 UserConnected=0; // how many minutes left to re login for users with wrong pw int8 WrongPassword=0; // hmt users put wrong password // global "status" vairble 0=nothing 1=user connected 2=feeding fish int8 Status=0; ///////////////////////////////////////// // Initilize RTC ///////////////////////////////////////// void Init_RTC(void) // start up the real time clock { Ticker = T1_FQ; // clock counter = #clocks per second setup_timer_1( T1_INTERNAL | T1_DIV_BY_1 ); // int 16 bit timer to interupt // Every 65536 clock cycles enable_interrupts( INT_TIMER1 ); // Start RTC } //////////////////////////////////////// // Process RTC Info //////////////////////////////////////// #int_TIMER1 void TIMER1_isr() { Ticker -= 65536; // Decrament by clocks per interrupt if ( Ticker < 65536 ) // If second has expired { Ticker += T1_FQ; // Incrament ticker by clocks/sec Seconds++; // Incrament Seconds } // turn seconds into everything else if(Seconds == 60) { Minutes++; Seconds=0; if(Minutes == 60) { Hours++; Minutes=0; if(Hours == 24){ Days++; Hours=0; if(Days == 30){ Months++; Days=0; if(Months == 13){ Years++; Months=0; } // years } // months } // days } // hours } // minutes } //////////////////////////////////////// // Beep makes a beep then waits 300 ms //////////////////////////////////////// void Beep() // sends a beep to the piezo on C0 { int k = 0; for(k=0; k<255; k++) // 255 times not very long but a beep { output_high(PIN_C0); delay_us(100); // produces a tone output_low(PIN_C0); delay_us(100); } delay_ms(300); // need to wait a little b4 doing again } //////////////////////////////////////// // Set the time, i hate dialoges //////////////////////////////////////// int SetupTime() { char String[5]; // for user input printf("\n\rPlease Give Me the time"); printf("\n\r Years:"); get_string(String,10); Years = atoi(String); // save year write_eeprom(00, Years); //years stored to eeprom 0 delay_ms(20); // allow time to stick printf("\n\r Months:"); get_string(String,10); Months = atoi(String); write_eeprom(01, Months); //stored to eeprom 01 delay_ms(20); printf("\n\r Days:"); get_string(String,10); Days = atoi(String); write_eeprom(02, Days); //stored to eeprom 02 delay_ms(20); printf("\n\r Hours:"); get_string(String,10); Hours = atoi(String); write_eeprom(03, Hours); //stored to eeprom 03 delay_ms(20); printf("\n\r Minutes:"); get_string(String,10); Minutes = atoi(String); write_eeprom(04, Minutes); //stored to eeprom 04 delay_ms(20); printf("\n\r Seconds:"); get_string(String,10); Seconds = atoi(String); write_eeprom(05, Seconds); //stored to eeprom 04 delay_ms(20); printf("\n\r New Date: %d/%d/%d %d:%d",Months,Days,Years,Hours,Minutes); } //////////////////////////////////////// // Interupt on serial RX //////////////////////////////////////// #int_rda void serial_isr() { disable_interrupts(int_rda); // stop this int UserConnected = 1; // make a user } //////////////////////////////////////// // Prints Menu on rs232 connect //////////////////////////////////////// int PrintMenu(int GetPw) { char Password[15]; // password char Input[15]; // Users Input // if this should get the password if(GetPw) { printf("\n\r Please Enter Password:"); get_string(Input, 15); // get password strcpy(Password, "Password"); // copy the password if(strcmp(Password, Input) == 0) { printf("\n\r Password Accepted");// it was right }else{ WrongPassword++; // track the wrong password printf("\n\r Wrong Password"); // wrong password return(0); } } // end if getpw printf("\n\r ----------------------------------------------------"); printf("\n\r | %d/%d/%d %d:%d\t",Months,Days,Years,Hours,Minutes,Seconds); printf("\n\r | Status: %d",Status); printf("\n\r | valid choices: s,t,m,x,b,f"); // show choices printf("\n\r | s=Set time \t t=View time"); printf("\n\r | m=Menu \t b=beep"); printf("\n\r | f=Feedfish \t x=Dissconnect"); printf("\n\r | r=Show Status"); printf("\n\r ----------------------------------------------------"); return(1); } //////////////////////////////////////// // The Glorious Main //////////////////////////////////////// void main() { //variables char String[10]; // for user input char Input[10]; // int C1On; // to see if C1 is on int C2On; // same for c2 // startup the pic has been restarted all old data is lost printf("\n\rStartup, old settings may be lost"); //SetupTime(); // get time from user // do the rtc stuff Init_RTC(); // startup the rtc // interrupts enable_interrupts( GLOBAL ); // use the ints enable_interrupts(int_rda); // int on serial RX setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(FALSE); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_2(T2_DISABLED,0,1); Beep(); // startup beep printf("\n\rStart"); // print start // from here on its for ev er while(1) { /* if((Prev_Minutes != Minutes) && MinutesLeft !=0) { MinutesLeft--; // decrament timer printf("\r Minutes Left:", MinutesLeft); if(MinutesLeft == 1) { MinutesLeft = 0; // reset timer enable_interrupts(int_rda); // enable interupt } } */ if(UserConnected) { delay_ms(500); // let them open their eyes Beep(); // print the menu if they type right password continue if(PrintMenu(1)==0) { printf("\n\r-Goodbye you have been disconnected");// let them know they diss UserConnected = 0; // set user to 0 enable_interrupts(int_rda); // resetup interrupt } // while the validated user is connected take their commands while(UserConnected) { delay_ms(200); // so they dont flood me printf("\n\rYour Choice:"); // prompt for item get_string(String,10); if(String[0] == 's'){SetupTime();} // setup time (set clock) if(String[0] == 't'){ printf("\n\r Time: %d/%d/%d %d:%d.%d",Months,Days,Years,Hours,Minutes,Seconds); } if(String[0] == 'm'){PrintMenu(0);} // reprint initial menu if(string[0] == 'x'){ // disconnect UserConnected = 0; // set user to 0 enable_interrupts(int_rda); // resetup interrupt printf("\n\r-Goodbye you have been disconnected");// let them know they diss } if(string[0] == 'b'){ Beep(); } if(string[0] == 'r'){ printf("\n\r Status: %d WrongPasswords: %d", Status, WrongPassword); } // turning on c1 and c2 like a toggle if((string[0] == 'c') && (String[1] == '1')) { if(C1On == 1) // if c1 is high { printf("\n\r Pin C1 Low"); output_low(PIN_C1); C1On = 0; }else{ output_high(PIN_C1); printf("\n\r Pin C1 High"); C1On = 1; } } if((string[0] == 'c') && (String[1] == '2')) { if(C2On == 1) // if c2 is high { printf("\n\r Pin C2 Low"); output_low(PIN_C2); C2On = 0; }else{ output_high(PIN_C2); printf("\n\r Pin C2 High"); C2On = 1; } } } // end if userconnected } // end while one /* delay_ms(1000); printf(". Ready:"); // test reciving of rs232 from computer gets(string); printf(". Your string was: %s", string);// print string back to user // figure out what they wanted to do if(string[0] == 'f') { Beep(); printf(". Feeding Fish"); FeedFish(); } */ } }
Just for reference this is what i use to connect to nfs drives on my server
via script, GalacticAC is defined in /etc/hosts with the ip of my server
#! /bin/bash # script to mount my files on webserver sudo mount -t nfs GalacticAC:/mnt/sdb1/ /home/michael/server/sdb1
and via fstab (will mount automatically on boot)
GalacticAC:/mnt/sdb1/ /home/michael/server/sdb1 nfs defaults 0 0

Categories
Tag Cloud
Blog RSS
Comments RSS

Void « Default
Life
Earth
Wind
Water
Fire
Light 